From 888f866dae243dcc205e31b6b1d8716bd00af4dc Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Mon, 5 Feb 2024 20:25:08 +0000 Subject: [PATCH] Fix issue with coredns node hosts controller The nodes controller was reading from the configmaps cache, but doesn't add any handlers, so if no other controller added configmap handlers, the cache would remain empty. Signed-off-by: Brad Davidson --- pkg/node/controller.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/node/controller.go b/pkg/node/controller.go index ef111541c9..c522032798 100644 --- a/pkg/node/controller.go +++ b/pkg/node/controller.go @@ -9,6 +9,7 @@ import ( coreclient "github.com/rancher/wrangler/pkg/generated/controllers/core/v1" "github.com/sirupsen/logrus" core "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func Register(ctx context.Context, @@ -76,13 +77,12 @@ func (h *handler) updateCoreDNSConfigMap(nodeName, nodeAddress string, removed b return nil } - configMapCache, err := h.configMaps.Cache().Get("kube-system", "coredns") - if err != nil || configMapCache == nil { + configMap, err := h.configMaps.Get("kube-system", "coredns", metav1.GetOptions{}) + if err != nil || configMap == nil { logrus.Warn(errors.Wrap(err, "Unable to fetch coredns config map")) return nil } - configMap := configMapCache.DeepCopy() hosts := configMap.Data["NodeHosts"] hostsMap := map[string]string{} @@ -116,6 +116,10 @@ func (h *handler) updateCoreDNSConfigMap(nodeName, nodeAddress string, removed b for host, ip := range hostsMap { newHosts += ip + " " + host + "\n" } + + if configMap.Data == nil { + configMap.Data = map[string]string{} + } configMap.Data["NodeHosts"] = newHosts if _, err := h.configMaps.Update(configMap); err != nil {