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

Merge pull request #1491 from marquiz/devel/nf-owner-ref

nfd-worker: set owner reference in NodeFeature objects
This commit is contained in:
Kubernetes Prow Robot 2023-12-08 14:51:47 +01:00 committed by GitHub
commit 04c4725dd1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 3 deletions

View file

@ -5,3 +5,11 @@
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid

View file

@ -45,6 +45,14 @@ spec:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
resources:
{{- toYaml .Values.worker.resources | nindent 12 }}
command:

View file

@ -33,6 +33,7 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/klog/v2"
klogutils "sigs.k8s.io/node-feature-discovery/pkg/utils/klog"
@ -679,15 +680,35 @@ func (m *nfdWorker) updateNodeFeatureObject(labels Labels) error {
features := source.GetAllFeatures()
// Create owner ref
ownerRefs := []metav1.OwnerReference{}
podName := os.Getenv("POD_NAME")
podUID := os.Getenv("POD_UID")
if podName != "" && podUID != "" {
isTrue := true
ownerRefs = []metav1.OwnerReference{
{
APIVersion: "v1",
Kind: "Pod",
Name: podName,
UID: types.UID(podUID),
Controller: &isTrue,
},
}
} else {
klog.InfoS("Cannot set NodeFeature owner reference, POD_NAME and/or POD_UID not specified")
}
// TODO: we could implement some simple caching of the object, only get it
// every 10 minutes or so because nobody else should really be modifying it
if nfr, err := cli.NfdV1alpha1().NodeFeatures(namespace).Get(context.TODO(), nodename, metav1.GetOptions{}); errors.IsNotFound(err) {
klog.InfoS("creating NodeFeature object", "nodefeature", klog.KObj(nfr))
nfr = &nfdv1alpha1.NodeFeature{
ObjectMeta: metav1.ObjectMeta{
Name: nodename,
Annotations: map[string]string{nfdv1alpha1.WorkerVersionAnnotation: version.Get()},
Labels: map[string]string{nfdv1alpha1.NodeFeatureObjNodeNameLabel: nodename},
Name: nodename,
Annotations: map[string]string{nfdv1alpha1.WorkerVersionAnnotation: version.Get()},
Labels: map[string]string{nfdv1alpha1.NodeFeatureObjNodeNameLabel: nodename},
OwnerReferences: ownerRefs,
},
Spec: nfdv1alpha1.NodeFeatureSpec{
Features: *features,
@ -707,6 +728,7 @@ func (m *nfdWorker) updateNodeFeatureObject(labels Labels) error {
nfrUpdated := nfr.DeepCopy()
nfrUpdated.Annotations = map[string]string{nfdv1alpha1.WorkerVersionAnnotation: version.Get()}
nfrUpdated.Labels = map[string]string{nfdv1alpha1.NodeFeatureObjNodeNameLabel: nodename}
nfrUpdated.OwnerReferences = ownerRefs
nfrUpdated.Spec = nfdv1alpha1.NodeFeatureSpec{
Features: *features,
Labels: labels,