From e23388d7c67a16cea143bd19a52967ab9c80c3cc Mon Sep 17 00:00:00 2001 From: Casey Davenport Date: Wed, 21 Apr 2021 11:06:47 -0700 Subject: [PATCH] Handle mismatched nodenames when setting NetworkUnavailable (#946) --- pkg/startup/startup.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/startup/startup.go b/pkg/startup/startup.go index 3784ef9c8..8a35ef9e3 100644 --- a/pkg/startup/startup.go +++ b/pkg/startup/startup.go @@ -185,8 +185,15 @@ func Run() { configureASNumber(node) if clientset != nil { + // Determine the Kubernetes node name. Default to the Calico node name unless an explicit + // value is provided. + k8sNodeName := nodeName + if nodeRef := os.Getenv("CALICO_K8S_NODE_REF"); nodeRef != "" { + k8sNodeName = nodeRef + } + log.Info("Setting NetworkUnavailable to False") - err := setNodeNetworkUnavailableFalse(*clientset, nodeName) + err := setNodeNetworkUnavailableFalse(*clientset, k8sNodeName) if err != nil { log.WithError(err).Error("Unable to set NetworkUnavailable to False") } @@ -483,7 +490,6 @@ func writeNodeConfig(nodeName string) { // been created, it returns a blank node resource. func getNode(ctx context.Context, client client.Interface, nodeName string) *api.Node { node, err := client.Nodes().Get(ctx, nodeName, options.GetOptions{}) - if err != nil { if _, ok := err.(cerrors.ErrorResourceDoesNotExist); !ok { log.WithError(err).WithField("Name", nodeName).Info("Unable to query node configuration")