1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

Only read NodeName from env once, at startup

Simplifies the code a bit. Also, log NodeName at startup.
This commit is contained in:
Markus Lehtonen 2019-02-25 10:01:27 +02:00
parent 6f73106d01
commit c54551f599
3 changed files with 7 additions and 11 deletions

View file

@ -43,9 +43,6 @@ const (
// ProgramName is the canonical name of this program
ProgramName = "nfd-master"
// NodeNameEnv is the environment variable that contains this node's name.
NodeNameEnv = "NODE_NAME"
// Namespace for feature labels
labelNs = "feature.node.kubernetes.io/"
@ -57,6 +54,7 @@ const (
var (
stdoutLogger = log.New(os.Stdout, "", log.LstdFlags)
stderrLogger = log.New(os.Stderr, "", log.LstdFlags)
nodeName = os.Getenv("NODE_NAME")
)
// Labels are a Kubernetes representation of discovered features.
@ -82,6 +80,7 @@ func main() {
stderrLogger.Fatalf("version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run.")
}
stdoutLogger.Printf("Node Feature Discovery Master %s", version.Get())
stdoutLogger.Printf("NodeName: '%s'", nodeName)
// Parse command-line arguments.
args, err := argsParse(nil)
@ -213,7 +212,7 @@ func updateMasterNode(helper apihelper.APIHelpers) error {
if err != nil {
return err
}
node, err := helper.GetNode(cli, os.Getenv(NodeNameEnv))
node, err := helper.GetNode(cli, nodeName)
if err != nil {
return err
}

View file

@ -17,7 +17,6 @@ limitations under the License.
package main
import (
"os"
"strings"
"testing"
@ -37,7 +36,7 @@ const (
)
func init() {
os.Setenv(NodeNameEnv, mockNodeName)
nodeName = mockNodeName
}
func TestUpdateNodeFeatures(t *testing.T) {

View file

@ -55,15 +55,13 @@ import (
const (
// ProgramName is the canonical name of this program
ProgramName = "nfd-worker"
// NodeNameEnv is the environment variable that contains this node's name.
NodeNameEnv = "NODE_NAME"
)
// package loggers
var (
stdoutLogger = log.New(os.Stdout, "", log.LstdFlags)
stderrLogger = log.New(os.Stderr, "", log.LstdFlags)
nodeName = os.Getenv("NODE_NAME")
)
// Global config
@ -104,6 +102,7 @@ func main() {
stderrLogger.Fatalf("version not set! Set -ldflags \"-X sigs.k8s.io/node-feature-discovery/pkg/version.version=`git describe --tags --dirty --always`\" during build or run.")
}
stdoutLogger.Printf("Node Feature Discovery Worker %s", version.Get())
stdoutLogger.Printf("NodeName: '%s'", nodeName)
// Parse command-line arguments.
args, err := argsParse(nil)
@ -427,8 +426,7 @@ func advertiseFeatureLabels(client pb.LabelerClient, labels Labels) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
nodeName := os.Getenv(NodeNameEnv)
stdoutLogger.Printf("%s: %s", NodeNameEnv, nodeName)
stdoutLogger.Printf("Sendng labeling request nfd-master")
labelReq := pb.SetLabelsRequest{Labels: labels,
NfdVersion: version.Get(),