From dc1b768e73001f9a6670f80bca2036a81748c081 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 19 Feb 2018 17:31:02 +0000 Subject: [PATCH 1/2] Allow Kubernetes node-name to be set from env var If we have the node-name then we can save work requesting the list of local pods from kubelet. And the best way to get the node name is via the "downwards api", i.e. put this in the Daemonset Yaml: - name: KUBERNETES_NODENAME valueFrom: fieldRef: apiVersion: v1 fieldPath: spec.nodeName --- prog/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prog/main.go b/prog/main.go index 7d72262b1..11686ae16 100644 --- a/prog/main.go +++ b/prog/main.go @@ -428,6 +428,11 @@ func main() { } } + // Node name may be set by environment variable, e.g. from the Kubernetes downward API + if flags.probe.kubernetesNodeName == "" { + flags.probe.kubernetesNodeName = os.Getenv("KUBERNETES_NODENAME") + } + if flags.dryRun { return } From 04002f32873bf451c60dc07cd5097f704d1c6ad3 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 19 Feb 2018 17:41:32 +0000 Subject: [PATCH 2/2] Fix doc string for -probe.kubernetes --- prog/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prog/main.go b/prog/main.go index 11686ae16..61ede6ab2 100644 --- a/prog/main.go +++ b/prog/main.go @@ -302,7 +302,7 @@ func setupFlags(flags *flags) { flag.StringVar(&flags.probe.dockerBridge, "probe.docker.bridge", "docker0", "the docker bridge name") // K8s - flag.BoolVar(&flags.probe.kubernetesEnabled, "probe.kubernetes", false, "collect kubernetes-related attributes for containers, should only be enabled on the master node") + flag.BoolVar(&flags.probe.kubernetesEnabled, "probe.kubernetes", false, "collect kubernetes-related attributes for containers") flag.DurationVar(&flags.probe.kubernetesClientConfig.Interval, "probe.kubernetes.interval", 10*time.Second, "how often to do a full resync of the kubernetes data") flag.StringVar(&flags.probe.kubernetesClientConfig.Server, "probe.kubernetes.api", "", "The address and port of the Kubernetes API server (deprecated in favor of equivalent probe.kubernetes.server)") flag.StringVar(&flags.probe.kubernetesClientConfig.CertificateAuthority, "probe.kubernetes.certificate-authority", "", "Path to a cert. file for the certificate authority")