From 9e437e41e7b3da68b8dd3663d6a18f48f6e28c9d Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Fri, 5 May 2023 12:35:44 +0300 Subject: [PATCH] topology-updater: use node IP in the default configz URI Use node IP (instead of node name) in the default value of -kubelet-config-uri. Should make the default deployment more robust, making it work in scenarios where node name does not resolve to the node ip, e.g. nodename != hostname. --- cmd/nfd-topology-updater/main.go | 9 +++++---- deployment/components/topology-updater/env.yaml | 7 +++++++ .../components/topology-updater/kustomization.yaml | 4 ++++ .../templates/topologyupdater.yaml | 4 ++++ docs/reference/topology-updater-commandline-reference.md | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 deployment/components/topology-updater/env.yaml diff --git a/cmd/nfd-topology-updater/main.go b/cmd/nfd-topology-updater/main.go index 88012e2aaa..6fb96a979b 100644 --- a/cmd/nfd-topology-updater/main.go +++ b/cmd/nfd-topology-updater/main.go @@ -112,12 +112,13 @@ func parseArgs(flags *flag.FlagSet, osArgs ...string) (*topology.Args, *resource } if len(resourcemonitorArgs.KubeletConfigURI) == 0 { - if len(utils.NodeName()) == 0 { - fmt.Fprintf(flags.Output(), "unable to determine the default kubelet config endpoint 'https://${NODE_NAME}:%d/configz' due to empty NODE_NAME environment, "+ - "please either define the NODE_NAME environment variable or specify endpoint with the -kubelet-config-uri flag\n", kubeletSecurePort) + nodeIP := os.Getenv("NODE_IP") + if len(nodeIP) == 0 { + fmt.Fprintf(flags.Output(), "unable to determine the default kubelet config endpoint 'https://${NODE_IP}:%d/configz' due to empty NODE_IP environment, "+ + "please either define the NODE_IP environment variable or specify endpoint with the -kubelet-config-uri flag\n", kubeletSecurePort) os.Exit(1) } - resourcemonitorArgs.KubeletConfigURI = fmt.Sprintf("https://%s:%d/configz", utils.NodeName(), kubeletSecurePort) + resourcemonitorArgs.KubeletConfigURI = fmt.Sprintf("https://%s:%d/configz", nodeIP, kubeletSecurePort) } return args, resourcemonitorArgs diff --git a/deployment/components/topology-updater/env.yaml b/deployment/components/topology-updater/env.yaml new file mode 100644 index 0000000000..fbcc231776 --- /dev/null +++ b/deployment/components/topology-updater/env.yaml @@ -0,0 +1,7 @@ +- op: add + path: "/spec/template/spec/containers/0/env/-" + value: + name: NODE_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP diff --git a/deployment/components/topology-updater/kustomization.yaml b/deployment/components/topology-updater/kustomization.yaml index b951ec605d..f025a7330f 100644 --- a/deployment/components/topology-updater/kustomization.yaml +++ b/deployment/components/topology-updater/kustomization.yaml @@ -14,3 +14,7 @@ patches: target: labelSelector: app=nfd name: nfd-topology-updater +- path: env.yaml + target: + labelSelector: app=nfd + name: nfd-topology-updater diff --git a/deployment/helm/node-feature-discovery/templates/topologyupdater.yaml b/deployment/helm/node-feature-discovery/templates/topologyupdater.yaml index cd3fca051e..51285341eb 100644 --- a/deployment/helm/node-feature-discovery/templates/topologyupdater.yaml +++ b/deployment/helm/node-feature-discovery/templates/topologyupdater.yaml @@ -37,6 +37,10 @@ spec: valueFrom: fieldRef: fieldPath: spec.nodeName + - name: NODE_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP command: - "nfd-topology-updater" args: diff --git a/docs/reference/topology-updater-commandline-reference.md b/docs/reference/topology-updater-commandline-reference.md index 4d35f917f3..47437ae33f 100644 --- a/docs/reference/topology-updater-commandline-reference.md +++ b/docs/reference/topology-updater-commandline-reference.md @@ -109,7 +109,7 @@ nfd-topology-updater -watch-namespace=rte The `-kubelet-config-uri` specifies the path to the Kubelet's configuration. Note that the URi could either be a local host file or an HTTP endpoint. -Default: `https://${NODE_NAME}:10250/configz` +Default: `https://${NODE_IP}:10250/configz` Example: