@@ -503,7 +503,7 @@ func (m *nfdMaster) prune() error {
503
503
klog .InfoS ("pruning node..." , "nodeName" , node .Name )
504
504
505
505
// Prune labels and extended resources
506
- err := m .updateNodeObject (node . Name , Labels {}, Annotations {}, ExtendedResources {}, []corev1.Taint {})
506
+ err := m .updateNodeObject (& node , Labels {}, Annotations {}, ExtendedResources {}, []corev1.Taint {})
507
507
if err != nil {
508
508
nodeUpdateFailures .Inc ()
509
509
return fmt .Errorf ("failed to prune node %q: %v" , node .Name , err )
@@ -692,8 +692,13 @@ func (m *nfdMaster) SetLabels(c context.Context, r *pb.SetLabelsRequest) (*pb.Se
692
692
klog .InfoS ("gRPC SetLabels request received" , "nodeName" , r .NodeName )
693
693
}
694
694
if ! m .config .NoPublish {
695
+ // Fetch the node object.
696
+ node , err := m .getNode (r .NodeName )
697
+ if err != nil {
698
+ return & pb.SetLabelsReply {}, err
699
+ }
695
700
// Create labels et al
696
- if err := m .refreshNodeFeatures (r . NodeName , r .GetLabels (), r .GetFeatures ()); err != nil {
701
+ if err := m .refreshNodeFeatures (node , r .GetLabels (), r .GetFeatures ()); err != nil {
697
702
nodeUpdateFailures .Inc ()
698
703
return & pb.SetLabelsReply {}, err
699
704
}
@@ -716,15 +721,15 @@ func (m *nfdMaster) nfdAPIUpdateAllNodes() error {
716
721
return nil
717
722
}
718
723
719
- func (m * nfdMaster ) nfdAPIUpdateOneNode (nodeName string ) error {
724
+ func (m * nfdMaster ) nfdAPIUpdateOneNode (node * corev1. Node ) error {
720
725
if m .nfdController == nil || m .nfdController .featureLister == nil {
721
726
return nil
722
727
}
723
728
724
- sel := k8sLabels .SelectorFromSet (k8sLabels.Set {nfdv1alpha1 .NodeFeatureObjNodeNameLabel : nodeName })
729
+ sel := k8sLabels .SelectorFromSet (k8sLabels.Set {nfdv1alpha1 .NodeFeatureObjNodeNameLabel : node . Name })
725
730
objs , err := m .nfdController .featureLister .List (sel )
726
731
if err != nil {
727
- return fmt .Errorf ("failed to get NodeFeature resources for node %q: %w" , nodeName , err )
732
+ return fmt .Errorf ("failed to get NodeFeature resources for node %q: %w" , node . Name , err )
728
733
}
729
734
730
735
// Sort our objects
@@ -748,7 +753,7 @@ func (m *nfdMaster) nfdAPIUpdateOneNode(nodeName string) error {
748
753
return nil
749
754
}
750
755
751
- klog .V (1 ).InfoS ("processing of node initiated by NodeFeature API" , "nodeName" , nodeName )
756
+ klog .V (1 ).InfoS ("processing of node initiated by NodeFeature API" , "nodeName" , node . Name )
752
757
753
758
features := nfdv1alpha1 .NewNodeFeatureSpec ()
754
759
@@ -775,7 +780,7 @@ func (m *nfdMaster) nfdAPIUpdateOneNode(nodeName string) error {
775
780
// Update node labels et al. This may also mean removing all NFD-owned
776
781
// labels (et al.), for example in the case no NodeFeature objects are
777
782
// present.
778
- if err := m .refreshNodeFeatures (nodeName , features .Labels , & features .Features ); err != nil {
783
+ if err := m .refreshNodeFeatures (node , features .Labels , & features .Features ); err != nil {
779
784
return err
780
785
}
781
786
@@ -820,14 +825,14 @@ func filterExtendedResource(name, value string, features *nfdv1alpha1.Features)
820
825
return filteredValue , nil
821
826
}
822
827
823
- func (m * nfdMaster ) refreshNodeFeatures (nodeName string , labels map [string ]string , features * nfdv1alpha1.Features ) error {
828
+ func (m * nfdMaster ) refreshNodeFeatures (node * corev1. Node , labels map [string ]string , features * nfdv1alpha1.Features ) error {
824
829
if m .config .AutoDefaultNs {
825
830
labels = addNsToMapKeys (labels , nfdv1alpha1 .FeatureLabelNs )
826
831
} else if labels == nil {
827
832
labels = make (map [string ]string )
828
833
}
829
834
830
- crLabels , crAnnotations , crExtendedResources , crTaints := m .processNodeFeatureRule (nodeName , features )
835
+ crLabels , crAnnotations , crExtendedResources , crTaints := m .processNodeFeatureRule (node . Name , features )
831
836
832
837
// Mix in CR-originated labels
833
838
maps .Copy (labels , crLabels )
@@ -849,9 +854,9 @@ func (m *nfdMaster) refreshNodeFeatures(nodeName string, labels map[string]strin
849
854
taints = filterTaints (crTaints )
850
855
}
851
856
852
- err := m .updateNodeObject (nodeName , labels , annotations , extendedResources , taints )
857
+ err := m .updateNodeObject (node , labels , annotations , extendedResources , taints )
853
858
if err != nil {
854
- klog .ErrorS (err , "failed to update node" , "nodeName" , nodeName )
859
+ klog .ErrorS (err , "failed to update node" , "nodeName" , node . Name )
855
860
return err
856
861
}
857
862
@@ -861,14 +866,9 @@ func (m *nfdMaster) refreshNodeFeatures(nodeName string, labels map[string]strin
861
866
// setTaints sets node taints and annotations based on the taints passed via
862
867
// nodeFeatureRule custom resorce. If empty list of taints is passed, currently
863
868
// NFD owned taints and annotations are removed from the node.
864
- func (m * nfdMaster ) setTaints (taints []corev1.Taint , nodeName string ) error {
865
- // Fetch the node object.
866
- node , err := m .getNode (nodeName )
867
- if err != nil {
868
- return err
869
- }
870
-
869
+ func (m * nfdMaster ) setTaints (taints []corev1.Taint , node * corev1.Node ) error {
871
870
// De-serialize the taints annotation into corev1.Taint type for comparision below.
871
+ var err error
872
872
oldTaints := []corev1.Taint {}
873
873
if val , ok := node .Annotations [nfdv1alpha1 .NodeTaintsAnnotation ]; ok {
874
874
sts := strings .Split (val , "," )
@@ -905,11 +905,10 @@ func (m *nfdMaster) setTaints(taints []corev1.Taint, nodeName string) error {
905
905
}
906
906
907
907
if taintsUpdated {
908
- err = controller .PatchNodeTaints (context .TODO (), m .k8sClient , nodeName , node , newNode )
909
- if err != nil {
908
+ if err := controller .PatchNodeTaints (context .TODO (), m .k8sClient , node .Name , node , newNode ); err != nil {
910
909
return fmt .Errorf ("failed to patch the node %v" , node .Name )
911
910
}
912
- klog .InfoS ("updated node taints" , "nodeName" , nodeName )
911
+ klog .InfoS ("updated node taints" , "nodeName" , node . Name )
913
912
}
914
913
915
914
// Update node annotation that holds the taints managed by us
@@ -926,11 +925,10 @@ func (m *nfdMaster) setTaints(taints []corev1.Taint, nodeName string) error {
926
925
927
926
patches := createPatches ([]string {nfdv1alpha1 .NodeTaintsAnnotation }, node .Annotations , newAnnotations , "/metadata/annotations" )
928
927
if len (patches ) > 0 {
929
- err = m .patchNode (node .Name , patches )
930
- if err != nil {
928
+ if err := m .patchNode (node .Name , patches ); err != nil {
931
929
return fmt .Errorf ("error while patching node object: %w" , err )
932
930
}
933
- klog .V (1 ).InfoS ("patched node annotations for taints" , "nodeName" , nodeName )
931
+ klog .V (1 ).InfoS ("patched node annotations for taints" , "nodeName" , node . Name )
934
932
}
935
933
return nil
936
934
}
@@ -1024,13 +1022,7 @@ func (m *nfdMaster) processNodeFeatureRule(nodeName string, features *nfdv1alpha
1024
1022
// updateNodeObject ensures the Kubernetes node object is up to date,
1025
1023
// creating new labels and extended resources where necessary and removing
1026
1024
// outdated ones. Also updates the corresponding annotations.
1027
- func (m * nfdMaster ) updateNodeObject (nodeName string , labels Labels , featureAnnotations Annotations , extendedResources ExtendedResources , taints []corev1.Taint ) error {
1028
- // Get the worker node object
1029
- node , err := m .getNode (nodeName )
1030
- if err != nil {
1031
- return err
1032
- }
1033
-
1025
+ func (m * nfdMaster ) updateNodeObject (node * corev1.Node , labels Labels , featureAnnotations Annotations , extendedResources ExtendedResources , taints []corev1.Taint ) error {
1034
1026
annotations := make (Annotations )
1035
1027
1036
1028
// Store names of labels in an annotation
@@ -1083,7 +1075,7 @@ func (m *nfdMaster) updateNodeObject(nodeName string, labels Labels, featureAnno
1083
1075
1084
1076
// patch node status with extended resource changes
1085
1077
statusPatches := m .createExtendedResourcePatches (node , extendedResources )
1086
- err = m .patchNodeStatus (node .Name , statusPatches )
1078
+ err : = m .patchNodeStatus (node .Name , statusPatches )
1087
1079
if err != nil {
1088
1080
return fmt .Errorf ("error while patching extended resources: %w" , err )
1089
1081
}
@@ -1096,13 +1088,13 @@ func (m *nfdMaster) updateNodeObject(nodeName string, labels Labels, featureAnno
1096
1088
1097
1089
if len (patches ) > 0 || len (statusPatches ) > 0 {
1098
1090
nodeUpdates .Inc ()
1099
- klog .InfoS ("node updated" , "nodeName" , nodeName )
1091
+ klog .InfoS ("node updated" , "nodeName" , node . Name )
1100
1092
} else {
1101
- klog .V (1 ).InfoS ("no updates to node" , "nodeName" , nodeName )
1093
+ klog .V (1 ).InfoS ("no updates to node" , "nodeName" , node . Name )
1102
1094
}
1103
1095
1104
1096
// Set taints
1105
- err = m .setTaints (taints , node . Name )
1097
+ err = m .setTaints (taints , node )
1106
1098
if err != nil {
1107
1099
return err
1108
1100
}
0 commit comments