Skip to content

Commit

Permalink
nfd-master: update node if no NodeFeature objects are present
Browse files Browse the repository at this point in the history
Correctly handle the case where no NodeFeature objects exist for certain
node (and NodeFeature API has been enabled with
-enable-nodefeature-api). In this case all the labels should be removed.
  • Loading branch information
marquiz committed Dec 19, 2022
1 parent d1b3148 commit 8e87645
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions pkg/nfd-master/nfd-master.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,7 @@ func (m *nfdMaster) nfdAPIUpdateAllNodes() error {
func (m *nfdMaster) nfdAPIUpdateOneNode(nodeName string) error {
sel := labels.SelectorFromSet(labels.Set{nfdv1alpha1.NodeFeatureObjNodeNameLabel: nodeName})
objs, err := m.nfdController.featureLister.List(sel)
if len(objs) == 0 {
klog.Infof("no NodeFeature object exists for node %q, skipping...", nodeName)
return nil
} else if err != nil {
if err != nil {
return fmt.Errorf("failed to get NodeFeature resources for node %q: %w", nodeName, err)
}

Expand All @@ -532,22 +529,26 @@ func (m *nfdMaster) nfdAPIUpdateOneNode(nodeName string) error {

klog.V(1).Infof("processing node %q, initiated by NodeFeature API", nodeName)

// Merge in features
//
// NOTE: changing the rule api to support handle multiple objects instead
// of merging would probably perform better with lot less data to copy.
features := objs[0].Spec.DeepCopy()
for _, o := range objs[1:] {
o.Spec.MergeInto(features)
}
features := &nfdv1alpha1.NodeFeatureSpec{}
annotations := Annotations{}

utils.KlogDump(4, "Composite NodeFeatureSpec after merge:", " ", features)
if len(objs) > 0 {
// Merge in features
//
// NOTE: changing the rule api to support handle multiple objects instead
// of merging would probably perform better with lot less data to copy.
features = objs[0].Spec.DeepCopy()
for _, o := range objs[1:] {
o.Spec.MergeInto(features)
}

annotations := Annotations{}
if objs[0].Namespace == m.namespace && objs[0].Name == nodeName {
// This is the one created by nfd-worker
if v := objs[0].Annotations[nfdv1alpha1.WorkerVersionAnnotation]; v != "" {
annotations[nfdv1alpha1.WorkerVersionAnnotation] = v
utils.KlogDump(4, "Composite NodeFeatureSpec after merge:", " ", features)

if objs[0].Namespace == m.namespace && objs[0].Name == nodeName {
// This is the one created by nfd-worker
if v := objs[0].Annotations[nfdv1alpha1.WorkerVersionAnnotation]; v != "" {
annotations[nfdv1alpha1.WorkerVersionAnnotation] = v
}
}
}

Expand Down

0 comments on commit 8e87645

Please sign in to comment.