Skip to content

Commit

Permalink
Merge pull request #227 from yevgeny-shnaidman/yevgeny/fix-topology-d…
Browse files Browse the repository at this point in the history
…aemonset

Adding NODE_ADDRESS env variable to topology DS to support default
  • Loading branch information
k8s-ci-robot authored May 8, 2024
2 parents 6dc725d + bbe69fb commit 0fd049a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 15 additions & 3 deletions internal/daemonset/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (d *daemonset) SetTopologyDaemonsetAsDesired(ctx context.Context, nfdInstan
"nfd-topology-updater",
},
Args: getArgs(nfdInstance),
Env: getEnvs(),
Env: getTopologyEnvs(),
SecurityContext: getSecurityContext(),
VolumeMounts: getVolumeMounts(),
},
Expand Down Expand Up @@ -115,7 +115,7 @@ func getArgs(nfdInstance *nfdv1.NodeFeatureDiscovery) []string {
}
}

func getEnvs() []corev1.EnvVar {
func getWorkerEnvs() []corev1.EnvVar {
return []corev1.EnvVar{
{
Name: "NODE_NAME",
Expand All @@ -128,6 +128,18 @@ func getEnvs() []corev1.EnvVar {
}
}

func getTopologyEnvs() []corev1.EnvVar {
nodeAddressEnv := corev1.EnvVar{
Name: "NODE_ADDRESS",
ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.hostIP",
},
},
}
return append(getWorkerEnvs(), nodeAddressEnv)
}

func getSecurityContext() *corev1.SecurityContext {
return &corev1.SecurityContext{
RunAsUser: ptr.To[int64](0),
Expand Down Expand Up @@ -216,7 +228,7 @@ func (d *daemonset) SetWorkerDaemonsetAsDesired(ctx context.Context, nfdInstance
DNSPolicy: corev1.DNSClusterFirstWithHostNet,
Containers: []corev1.Container{
{
Env: getEnvs(),
Env: getWorkerEnvs(),
Image: nfdInstance.Spec.Operand.ImagePath(),
Name: "nfd-worker",
Command: []string{"nfd-worker"},
Expand Down
6 changes: 5 additions & 1 deletion internal/daemonset/testdata/test_topology_daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ spec:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
fieldPath: spec.nodeName
- name: NODE_ADDRESS
valueFrom:
fieldRef:
fieldPath: status.hostIP
image: test-image
imagePullPolicy: Always
command:
Expand Down

0 comments on commit 0fd049a

Please sign in to comment.