Skip to content

Commit

Permalink
pkg/node: give priority to nodeName from K8S_NODE_NAME env variable
Browse files Browse the repository at this point in the history
If Cilium is running in k8s mode, K8S_NODE_NAME is available so we
can set the node name directly upon node initialization. This prevents
Cilium from setting the node name with a different name at a later
stage as the os.Hostname() can be return a different value than
K8S_NODE_NAME.

Fixes: dbfc2c3 ("k8s: remove waiting for node spec on k8s client init")
Signed-off-by: André Martins <andre@cilium.io>
  • Loading branch information
aanm committed May 29, 2020
1 parent 93ab013 commit 3533fd3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/node/types/nodename.go
@@ -1,4 +1,4 @@
// Copyright 2016-2017 Authors of Cilium
// Copyright 2016-2020 Authors of Cilium
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@ package types
import (
"os"

k8sConsts "github.com/cilium/cilium/pkg/k8s/constants"
"github.com/cilium/cilium/pkg/logging/logfields"
)

Expand All @@ -42,6 +43,11 @@ func GetName() string {
}

func init() {
// Give priority to the environment variable available in the Cilium agent
if name := os.Getenv(k8sConsts.EnvNodeNameSpec); name != "" {
nodeName = name
return
}
if h, err := os.Hostname(); err != nil {
log.WithError(err).Warn("Unable to retrieve local hostname")
} else {
Expand Down

0 comments on commit 3533fd3

Please sign in to comment.