mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
nfd-master: drop stale variables
Remove some stale variables that were leftover from the recent removal of nfd version annotations.
This commit is contained in:
parent
38ed148352
commit
678d7e89cb
2 changed files with 17 additions and 26 deletions
|
@ -183,7 +183,7 @@ func TestUpdateNodeObject(t *testing.T) {
|
||||||
mockAPIHelper.On("GetNode", mockClient, mockNodeName).Return(mockNode, nil).Twice()
|
mockAPIHelper.On("GetNode", mockClient, mockNodeName).Return(mockNode, nil).Twice()
|
||||||
mockAPIHelper.On("PatchNodeStatus", mockClient, mockNodeName, mock.MatchedBy(jsonPatchMatcher(statusPatches))).Return(nil)
|
mockAPIHelper.On("PatchNodeStatus", mockClient, mockNodeName, mock.MatchedBy(jsonPatchMatcher(statusPatches))).Return(nil)
|
||||||
mockAPIHelper.On("PatchNode", mockClient, mockNodeName, mock.MatchedBy(jsonPatchMatcher(metadataPatches))).Return(nil)
|
mockAPIHelper.On("PatchNode", mockClient, mockNodeName, mock.MatchedBy(jsonPatchMatcher(metadataPatches))).Return(nil)
|
||||||
err := mockMaster.updateNodeObject(mockClient, mockNodeName, fakeFeatureLabels, Annotations{}, fakeAnnotations, fakeExtResources, nil)
|
err := mockMaster.updateNodeObject(mockClient, mockNodeName, fakeFeatureLabels, fakeAnnotations, fakeExtResources, nil)
|
||||||
|
|
||||||
Convey("Error is nil", func() {
|
Convey("Error is nil", func() {
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
@ -193,7 +193,7 @@ func TestUpdateNodeObject(t *testing.T) {
|
||||||
Convey("When I fail to update the node with feature labels", func() {
|
Convey("When I fail to update the node with feature labels", func() {
|
||||||
expectedError := fmt.Errorf("no client is passed, client: <nil>")
|
expectedError := fmt.Errorf("no client is passed, client: <nil>")
|
||||||
mockAPIHelper.On("GetClient").Return(nil, expectedError)
|
mockAPIHelper.On("GetClient").Return(nil, expectedError)
|
||||||
err := mockMaster.updateNodeObject(nil, mockNodeName, fakeFeatureLabels, Annotations{}, fakeAnnotations, fakeExtResources, nil)
|
err := mockMaster.updateNodeObject(nil, mockNodeName, fakeFeatureLabels, fakeAnnotations, fakeExtResources, nil)
|
||||||
|
|
||||||
Convey("Error is produced", func() {
|
Convey("Error is produced", func() {
|
||||||
So(err, ShouldResemble, expectedError)
|
So(err, ShouldResemble, expectedError)
|
||||||
|
@ -203,7 +203,7 @@ func TestUpdateNodeObject(t *testing.T) {
|
||||||
Convey("When I fail to get a mock client while updating feature labels", func() {
|
Convey("When I fail to get a mock client while updating feature labels", func() {
|
||||||
expectedError := fmt.Errorf("no client is passed, client: <nil>")
|
expectedError := fmt.Errorf("no client is passed, client: <nil>")
|
||||||
mockAPIHelper.On("GetClient").Return(nil, expectedError)
|
mockAPIHelper.On("GetClient").Return(nil, expectedError)
|
||||||
err := mockMaster.updateNodeObject(nil, mockNodeName, fakeFeatureLabels, Annotations{}, fakeAnnotations, fakeExtResources, nil)
|
err := mockMaster.updateNodeObject(nil, mockNodeName, fakeFeatureLabels, fakeAnnotations, fakeExtResources, nil)
|
||||||
|
|
||||||
Convey("Error is produced", func() {
|
Convey("Error is produced", func() {
|
||||||
So(err, ShouldResemble, expectedError)
|
So(err, ShouldResemble, expectedError)
|
||||||
|
@ -214,7 +214,7 @@ func TestUpdateNodeObject(t *testing.T) {
|
||||||
expectedError := errors.New("fake error")
|
expectedError := errors.New("fake error")
|
||||||
mockAPIHelper.On("GetClient").Return(mockClient, nil)
|
mockAPIHelper.On("GetClient").Return(mockClient, nil)
|
||||||
mockAPIHelper.On("GetNode", mockClient, mockNodeName).Return(nil, expectedError).Twice()
|
mockAPIHelper.On("GetNode", mockClient, mockNodeName).Return(nil, expectedError).Twice()
|
||||||
err := mockMaster.updateNodeObject(mockClient, mockNodeName, fakeFeatureLabels, Annotations{}, fakeAnnotations, fakeExtResources, nil)
|
err := mockMaster.updateNodeObject(mockClient, mockNodeName, fakeFeatureLabels, fakeAnnotations, fakeExtResources, nil)
|
||||||
|
|
||||||
Convey("Error is produced", func() {
|
Convey("Error is produced", func() {
|
||||||
So(err, ShouldEqual, expectedError)
|
So(err, ShouldEqual, expectedError)
|
||||||
|
@ -227,7 +227,7 @@ func TestUpdateNodeObject(t *testing.T) {
|
||||||
mockAPIHelper.On("GetNode", mockClient, mockNodeName).Return(mockNode, nil).Twice()
|
mockAPIHelper.On("GetNode", mockClient, mockNodeName).Return(mockNode, nil).Twice()
|
||||||
mockAPIHelper.On("PatchNodeStatus", mockClient, mockNodeName, mock.MatchedBy(jsonPatchMatcher(statusPatches))).Return(nil)
|
mockAPIHelper.On("PatchNodeStatus", mockClient, mockNodeName, mock.MatchedBy(jsonPatchMatcher(statusPatches))).Return(nil)
|
||||||
mockAPIHelper.On("PatchNode", mockClient, mockNodeName, mock.Anything).Return(expectedError).Twice()
|
mockAPIHelper.On("PatchNode", mockClient, mockNodeName, mock.Anything).Return(expectedError).Twice()
|
||||||
err := mockMaster.updateNodeObject(mockClient, mockNodeName, fakeFeatureLabels, Annotations{}, fakeAnnotations, fakeExtResources, nil)
|
err := mockMaster.updateNodeObject(mockClient, mockNodeName, fakeFeatureLabels, fakeAnnotations, fakeExtResources, nil)
|
||||||
|
|
||||||
Convey("Error is produced", func() {
|
Convey("Error is produced", func() {
|
||||||
So(err.Error(), ShouldEndWith, expectedError.Error())
|
So(err.Error(), ShouldEndWith, expectedError.Error())
|
||||||
|
|
|
@ -465,7 +465,7 @@ func (m *nfdMaster) prune() error {
|
||||||
klog.InfoS("pruning node...", "nodeName", node.Name)
|
klog.InfoS("pruning node...", "nodeName", node.Name)
|
||||||
|
|
||||||
// Prune labels and extended resources
|
// Prune labels and extended resources
|
||||||
err := m.updateNodeObject(cli, node.Name, Labels{}, Annotations{}, Annotations{}, ExtendedResources{}, []corev1.Taint{})
|
err := m.updateNodeObject(cli, node.Name, Labels{}, Annotations{}, ExtendedResources{}, []corev1.Taint{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
nodeUpdateFailures.Inc()
|
nodeUpdateFailures.Inc()
|
||||||
return fmt.Errorf("failed to prune node %q: %v", node.Name, err)
|
return fmt.Errorf("failed to prune node %q: %v", node.Name, err)
|
||||||
|
@ -693,10 +693,8 @@ func (m *nfdMaster) SetLabels(c context.Context, r *pb.SetLabelsRequest) (*pb.Se
|
||||||
return &pb.SetLabelsReply{}, err
|
return &pb.SetLabelsReply{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
annotations := Annotations{}
|
|
||||||
|
|
||||||
// Create labels et al
|
// Create labels et al
|
||||||
if err := m.refreshNodeFeatures(cli, r.NodeName, annotations, r.GetLabels(), r.GetFeatures()); err != nil {
|
if err := m.refreshNodeFeatures(cli, r.NodeName, r.GetLabels(), r.GetFeatures()); err != nil {
|
||||||
nodeUpdateFailures.Inc()
|
nodeUpdateFailures.Inc()
|
||||||
return &pb.SetLabelsReply{}, err
|
return &pb.SetLabelsReply{}, err
|
||||||
}
|
}
|
||||||
|
@ -760,8 +758,6 @@ func (m *nfdMaster) nfdAPIUpdateOneNode(nodeName string) error {
|
||||||
|
|
||||||
features := nfdv1alpha1.NewNodeFeatureSpec()
|
features := nfdv1alpha1.NewNodeFeatureSpec()
|
||||||
|
|
||||||
annotations := Annotations{}
|
|
||||||
|
|
||||||
if len(objs) > 0 {
|
if len(objs) > 0 {
|
||||||
// Merge in features
|
// Merge in features
|
||||||
//
|
//
|
||||||
|
@ -782,7 +778,7 @@ func (m *nfdMaster) nfdAPIUpdateOneNode(nodeName string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := m.refreshNodeFeatures(cli, nodeName, annotations, features.Labels, &features.Features); err != nil {
|
if err := m.refreshNodeFeatures(cli, nodeName, features.Labels, &features.Features); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -837,7 +833,7 @@ func filterExtendedResource(name, value string, features *nfdv1alpha1.Features)
|
||||||
return q.String(), nil
|
return q.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *nfdMaster) refreshNodeFeatures(cli *kubernetes.Clientset, nodeName string, nfdAnnotations Annotations, labels map[string]string, features *nfdv1alpha1.Features) error {
|
func (m *nfdMaster) refreshNodeFeatures(cli *kubernetes.Clientset, nodeName string, labels map[string]string, features *nfdv1alpha1.Features) error {
|
||||||
if labels == nil {
|
if labels == nil {
|
||||||
labels = make(map[string]string)
|
labels = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
@ -860,7 +856,7 @@ func (m *nfdMaster) refreshNodeFeatures(cli *kubernetes.Clientset, nodeName stri
|
||||||
extendedResources = filterExtendedResources(features, extendedResources)
|
extendedResources = filterExtendedResources(features, extendedResources)
|
||||||
|
|
||||||
// Annotations
|
// Annotations
|
||||||
featureAnnotations := m.filterFeatureAnnotations(crAnnotations)
|
annotations := m.filterFeatureAnnotations(crAnnotations)
|
||||||
|
|
||||||
// Taints
|
// Taints
|
||||||
var taints []corev1.Taint
|
var taints []corev1.Taint
|
||||||
|
@ -868,7 +864,7 @@ func (m *nfdMaster) refreshNodeFeatures(cli *kubernetes.Clientset, nodeName stri
|
||||||
taints = filterTaints(crTaints)
|
taints = filterTaints(crTaints)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := m.updateNodeObject(cli, nodeName, labels, nfdAnnotations, featureAnnotations, extendedResources, taints)
|
err := m.updateNodeObject(cli, nodeName, labels, annotations, extendedResources, taints)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "failed to update node", "nodeName", nodeName)
|
klog.ErrorS(err, "failed to update node", "nodeName", nodeName)
|
||||||
return err
|
return err
|
||||||
|
@ -1040,7 +1036,7 @@ func (m *nfdMaster) processNodeFeatureRule(nodeName string, features *nfdv1alpha
|
||||||
// updateNodeObject ensures the Kubernetes node object is up to date,
|
// updateNodeObject ensures the Kubernetes node object is up to date,
|
||||||
// creating new labels and extended resources where necessary and removing
|
// creating new labels and extended resources where necessary and removing
|
||||||
// outdated ones. Also updates the corresponding annotations.
|
// outdated ones. Also updates the corresponding annotations.
|
||||||
func (m *nfdMaster) updateNodeObject(cli *kubernetes.Clientset, nodeName string, labels Labels, nfdAnnotations, featureAnnotations Annotations, extendedResources ExtendedResources, taints []corev1.Taint) error {
|
func (m *nfdMaster) updateNodeObject(cli *kubernetes.Clientset, nodeName string, labels Labels, featureAnnotations Annotations, extendedResources ExtendedResources, taints []corev1.Taint) error {
|
||||||
if cli == nil {
|
if cli == nil {
|
||||||
return fmt.Errorf("no client is passed, client: %v", cli)
|
return fmt.Errorf("no client is passed, client: %v", cli)
|
||||||
}
|
}
|
||||||
|
@ -1051,6 +1047,8 @@ func (m *nfdMaster) updateNodeObject(cli *kubernetes.Clientset, nodeName string,
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
annotations := make(Annotations)
|
||||||
|
|
||||||
// Store names of labels in an annotation
|
// Store names of labels in an annotation
|
||||||
if len(labels) > 0 {
|
if len(labels) > 0 {
|
||||||
labelKeys := make([]string, 0, len(labels))
|
labelKeys := make([]string, 0, len(labels))
|
||||||
|
@ -1059,7 +1057,7 @@ func (m *nfdMaster) updateNodeObject(cli *kubernetes.Clientset, nodeName string,
|
||||||
labelKeys = append(labelKeys, strings.TrimPrefix(key, nfdv1alpha1.FeatureLabelNs+"/"))
|
labelKeys = append(labelKeys, strings.TrimPrefix(key, nfdv1alpha1.FeatureLabelNs+"/"))
|
||||||
}
|
}
|
||||||
sort.Strings(labelKeys)
|
sort.Strings(labelKeys)
|
||||||
nfdAnnotations[m.instanceAnnotation(nfdv1alpha1.FeatureLabelsAnnotation)] = strings.Join(labelKeys, ",")
|
annotations[m.instanceAnnotation(nfdv1alpha1.FeatureLabelsAnnotation)] = strings.Join(labelKeys, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store names of extended resources in an annotation
|
// Store names of extended resources in an annotation
|
||||||
|
@ -1070,11 +1068,10 @@ func (m *nfdMaster) updateNodeObject(cli *kubernetes.Clientset, nodeName string,
|
||||||
extendedResourceKeys = append(extendedResourceKeys, strings.TrimPrefix(key, nfdv1alpha1.FeatureLabelNs+"/"))
|
extendedResourceKeys = append(extendedResourceKeys, strings.TrimPrefix(key, nfdv1alpha1.FeatureLabelNs+"/"))
|
||||||
}
|
}
|
||||||
sort.Strings(extendedResourceKeys)
|
sort.Strings(extendedResourceKeys)
|
||||||
nfdAnnotations[m.instanceAnnotation(nfdv1alpha1.ExtendedResourceAnnotation)] = strings.Join(extendedResourceKeys, ",")
|
annotations[m.instanceAnnotation(nfdv1alpha1.ExtendedResourceAnnotation)] = strings.Join(extendedResourceKeys, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store feature annotations
|
// Store feature annotations
|
||||||
annotations := make(Annotations)
|
|
||||||
if len(featureAnnotations) > 0 {
|
if len(featureAnnotations) > 0 {
|
||||||
// Store names of feature annotations in an annotation
|
// Store names of feature annotations in an annotation
|
||||||
annotationKeys := make([]string, 0, len(featureAnnotations))
|
annotationKeys := make([]string, 0, len(featureAnnotations))
|
||||||
|
@ -1083,18 +1080,12 @@ func (m *nfdMaster) updateNodeObject(cli *kubernetes.Clientset, nodeName string,
|
||||||
annotationKeys = append(annotationKeys, strings.TrimPrefix(key, nfdv1alpha1.FeatureAnnotationNs+"/"))
|
annotationKeys = append(annotationKeys, strings.TrimPrefix(key, nfdv1alpha1.FeatureAnnotationNs+"/"))
|
||||||
}
|
}
|
||||||
sort.Strings(annotationKeys)
|
sort.Strings(annotationKeys)
|
||||||
nfdAnnotations[m.instanceAnnotation(nfdv1alpha1.FeatureAnnotationsTrackingAnnotation)] = strings.Join(annotationKeys, ",")
|
annotations[m.instanceAnnotation(nfdv1alpha1.FeatureAnnotationsTrackingAnnotation)] = strings.Join(annotationKeys, ",")
|
||||||
for k, v := range featureAnnotations {
|
for k, v := range featureAnnotations {
|
||||||
annotations[k] = v
|
annotations[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(nfdAnnotations) > 0 {
|
|
||||||
for k, v := range nfdAnnotations {
|
|
||||||
annotations[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create JSON patches for changes in labels and annotations
|
// Create JSON patches for changes in labels and annotations
|
||||||
oldLabels := stringToNsNames(node.Annotations[m.instanceAnnotation(nfdv1alpha1.FeatureLabelsAnnotation)], nfdv1alpha1.FeatureLabelNs)
|
oldLabels := stringToNsNames(node.Annotations[m.instanceAnnotation(nfdv1alpha1.FeatureLabelsAnnotation)], nfdv1alpha1.FeatureLabelNs)
|
||||||
oldAnnotations := stringToNsNames(node.Annotations[m.instanceAnnotation(nfdv1alpha1.FeatureAnnotationsTrackingAnnotation)], nfdv1alpha1.FeatureAnnotationNs)
|
oldAnnotations := stringToNsNames(node.Annotations[m.instanceAnnotation(nfdv1alpha1.FeatureAnnotationsTrackingAnnotation)], nfdv1alpha1.FeatureAnnotationNs)
|
||||||
|
|
Loading…
Reference in a new issue