-
Notifications
You must be signed in to change notification settings - Fork 309
nfd-worker: Add support to configure the ownerReference to Node #2041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,7 @@ type coreConfig struct { | |
| LabelWhiteList utils.RegexpVal | ||
| NoPublish bool | ||
| NoOwnerRefs bool | ||
| OwnerRefPod bool | ||
| FeatureSources []string | ||
| Sources *[]string | ||
| LabelSources []string | ||
|
|
@@ -101,6 +102,7 @@ type Args struct { | |
| Options string | ||
| Port int | ||
| NoOwnerRefs bool | ||
| OwnerRefPod bool | ||
|
|
||
| Overrides ConfigOverrideArgs | ||
| } | ||
|
|
@@ -109,6 +111,7 @@ type Args struct { | |
| type ConfigOverrideArgs struct { | ||
| NoPublish *bool | ||
| NoOwnerRefs *bool | ||
| OwnerRefPod *bool | ||
| FeatureSources *utils.StringSliceVal | ||
| LabelSources *utils.StringSliceVal | ||
| } | ||
|
|
@@ -253,33 +256,53 @@ func (w *nfdWorker) setOwnerReference() error { | |
| ownerReference := []metav1.OwnerReference{} | ||
|
|
||
| if !w.config.Core.NoOwnerRefs { | ||
| // Get pod owner reference | ||
| podName := os.Getenv("POD_NAME") | ||
| // Add pod owner reference if it exists | ||
| if podName != "" { | ||
| if selfPod, err := w.k8sClient.CoreV1().Pods(w.kubernetesNamespace).Get(context.TODO(), podName, metav1.GetOptions{}); err != nil { | ||
| klog.ErrorS(err, "failed to get self pod, cannot inherit ownerReference for NodeFeature") | ||
| return err | ||
| } else { | ||
| for _, owner := range selfPod.OwnerReferences { | ||
| owner.BlockOwnerDeletion = ptr.To(false) | ||
| ownerReference = append(ownerReference, owner) | ||
| if w.config.Core.OwnerRefPod { | ||
| // Get pod owner reference | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Main concern with the current shape: wrapping the pre-existing Pod path in Could we keep Pod as the default and make Node the opt-in? And, larger question: would you be open to a single enum flag |
||
| podName := os.Getenv("POD_NAME") | ||
| // Add pod owner reference if it exists | ||
| if podName != "" { | ||
| if selfPod, err := w.k8sClient.CoreV1().Pods(w.kubernetesNamespace).Get(context.TODO(), podName, metav1.GetOptions{}); err != nil { | ||
| klog.ErrorS(err, "failed to get self pod, cannot inherit ownerReference for NodeFeature") | ||
| return err | ||
| } else { | ||
| for _, owner := range selfPod.OwnerReferences { | ||
| owner.BlockOwnerDeletion = ptr.To(false) | ||
| ownerReference = append(ownerReference, owner) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| podUID := os.Getenv("POD_UID") | ||
| if podUID != "" { | ||
| ownerReference = append(ownerReference, metav1.OwnerReference{ | ||
| APIVersion: "v1", | ||
| Kind: "Pod", | ||
| Name: podName, | ||
| UID: types.UID(podUID), | ||
| }) | ||
| podUID := os.Getenv("POD_UID") | ||
| if podUID != "" { | ||
| ownerReference = append(ownerReference, metav1.OwnerReference{ | ||
| APIVersion: "v1", | ||
| Kind: "Pod", | ||
| Name: podName, | ||
| UID: types.UID(podUID), | ||
| }) | ||
| } else { | ||
| klog.InfoS("Cannot append POD ownerReference to NodeFeature, POD_UID not specified") | ||
| } | ||
| } else { | ||
| klog.InfoS("Cannot append POD ownerReference to NodeFeature, POD_UID not specified") | ||
| klog.InfoS("Cannot set NodeFeature owner references, POD_NAME not specified") | ||
| } | ||
| } else { | ||
| klog.InfoS("Cannot set NodeFeature owner references, POD_NAME not specified") | ||
| // Get node owner reference | ||
| nodeName := os.Getenv("NODE_NAME") | ||
| if nodeName != "" { | ||
| if selfNode, err := w.k8sClient.CoreV1().Nodes().Get(context.TODO(), nodeName, metav1.GetOptions{}); err != nil { | ||
| klog.ErrorS(err, "failed to get self node, cannot inherit ownerReference for NodeFeature") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small thing while we're here: could we thread a |
||
| return err | ||
| } else { | ||
| ownerReference = append(ownerReference, metav1.OwnerReference{ | ||
| APIVersion: "v1", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the Node case, worth setting |
||
| Kind: "Node", | ||
| Name: nodeName, | ||
| UID: selfNode.UID, | ||
| }) | ||
| } | ||
| } else { | ||
| klog.InfoS("Cannot set NodeFeature owner reference to Node, NODE_NAME not specified") | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -505,6 +528,9 @@ func (w *nfdWorker) configure(filepath string, overrides string) error { | |
| if w.args.Overrides.NoOwnerRefs != nil { | ||
| c.Core.NoOwnerRefs = *w.args.Overrides.NoOwnerRefs | ||
| } | ||
| if w.args.Overrides.OwnerRefPod != nil { | ||
| c.Core.OwnerRefPod = *w.args.Overrides.OwnerRefPod | ||
| } | ||
| if w.args.Overrides.FeatureSources != nil { | ||
| c.Core.FeatureSources = *w.args.Overrides.FeatureSources | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,9 +48,12 @@ func TestRun(t *testing.T) { | |
| Convey("When publishing features from fake source", func() { | ||
| os.Setenv("NODE_NAME", "fake-node") | ||
| os.Setenv("KUBERNETES_NAMESPACE", "fake-ns") | ||
| b := true | ||
| args := &worker.Args{ | ||
| Oneshot: true, | ||
| Oneshot: true, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting |
||
| NoOwnerRefs: true, | ||
| Overrides: worker.ConfigOverrideArgs{ | ||
| NoOwnerRefs: &b, | ||
| FeatureSources: &utils.StringSliceVal{"fake"}, | ||
| LabelSources: &utils.StringSliceVal{"fake"}, | ||
| }, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small fix:
jq ".items[].metadata.name"emits quoted strings, whichkubectl deletewill reject. Two options — add-rto jq, or simpler:kubectl delete -n node-feature-discovery nodefeatures.nfd.k8s-sigs.io --all.