Commit c58ee730 authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

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: 's avatarBrad Davidson <brad.davidson@rancher.com> (cherry picked from commit 888f866d) Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com>
parent 7d9b5cc2
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
coreclient "github.com/rancher/wrangler/pkg/generated/controllers/core/v1" coreclient "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
core "k8s.io/api/core/v1" core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
func Register(ctx context.Context, func Register(ctx context.Context,
...@@ -76,13 +77,12 @@ func (h *handler) updateCoreDNSConfigMap(nodeName, nodeAddress string, removed b ...@@ -76,13 +77,12 @@ func (h *handler) updateCoreDNSConfigMap(nodeName, nodeAddress string, removed b
return nil return nil
} }
configMapCache, err := h.configMaps.Cache().Get("kube-system", "coredns") configMap, err := h.configMaps.Get("kube-system", "coredns", metav1.GetOptions{})
if err != nil || configMapCache == nil { if err != nil || configMap == nil {
logrus.Warn(errors.Wrap(err, "Unable to fetch coredns config map")) logrus.Warn(errors.Wrap(err, "Unable to fetch coredns config map"))
return nil return nil
} }
configMap := configMapCache.DeepCopy()
hosts := configMap.Data["NodeHosts"] hosts := configMap.Data["NodeHosts"]
hostsMap := map[string]string{} hostsMap := map[string]string{}
...@@ -116,6 +116,10 @@ func (h *handler) updateCoreDNSConfigMap(nodeName, nodeAddress string, removed b ...@@ -116,6 +116,10 @@ func (h *handler) updateCoreDNSConfigMap(nodeName, nodeAddress string, removed b
for host, ip := range hostsMap { for host, ip := range hostsMap {
newHosts += ip + " " + host + "\n" newHosts += ip + " " + host + "\n"
} }
if configMap.Data == nil {
configMap.Data = map[string]string{}
}
configMap.Data["NodeHosts"] = newHosts configMap.Data["NodeHosts"] = newHosts
if _, err := h.configMaps.Update(configMap); err != nil { if _, err := h.configMaps.Update(configMap); err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment