From 73524afb9e92a263a0a997dd408d60ce29a6defc Mon Sep 17 00:00:00 2001 From: Ram Lavi Date: Mon, 5 Feb 2024 12:17:13 +0200 Subject: [PATCH] node-labeller: Remove obsolete node labeller functionality Node labeller was moved into core Kubevirt as part of v0.40 release [0]. As part of this move the labels were renamed to match Kubevirt practice and functionality to remove the old ones was introduced. Now when we don't support upgrade from the old version we can remove this functionality. [0] https://github.com/kubevirt/kubevirt/commit/5eb88073d8675657dd0b0b4f998e2f99663150d1 Signed-off-by: Luboslav Pivarc Signed-off-by: Ram Lavi --- .../node-labeller/node_labeller.go | 25 +--- pkg/virt-handler/node-labeller/util/util.go | 13 +- tests/infrastructure/node-labeller.go | 113 ------------------ 3 files changed, 5 insertions(+), 146 deletions(-) diff --git a/pkg/virt-handler/node-labeller/node_labeller.go b/pkg/virt-handler/node-labeller/node_labeller.go index 49574cc98695..24991cd236f9 100644 --- a/pkg/virt-handler/node-labeller/node_labeller.go +++ b/pkg/virt-handler/node-labeller/node_labeller.go @@ -44,13 +44,9 @@ import ( "kubevirt.io/kubevirt/pkg/apimachinery/patch" virtconfig "kubevirt.io/kubevirt/pkg/virt-config" "kubevirt.io/kubevirt/pkg/virt-handler/node-labeller/api" - "kubevirt.io/kubevirt/pkg/virt-handler/node-labeller/util" ) var nodeLabellerLabels = []string{ - util.DeprecatedLabelNamespace + util.DeprecatedcpuModelPrefix, - util.DeprecatedLabelNamespace + util.DeprecatedcpuFeaturePrefix, - util.DeprecatedLabelNamespace + util.DeprecatedHyperPrefix, kubevirtv1.CPUFeatureLabel, kubevirtv1.CPUModelLabel, kubevirtv1.SupportedHostModelMigrationCPU, @@ -230,20 +226,7 @@ func (n *NodeLabeller) patchNode(originalNode, node *v1.Node) error { }) } - if !equality.Semantic.DeepEqual(originalNode.Annotations, node.Annotations) { - p = append(p, patch.PatchOperation{ - Op: "test", - Path: "/metadata/annotations", - Value: originalNode.Annotations, - }, patch.PatchOperation{ - Op: "replace", - Path: "/metadata/annotations", - Value: node.Annotations, - }, - ) - } - - //patch node only if there is change in labels or annotations + // patch node only if there is change in labels if len(p) > 0 { payloadBytes, err := json.Marshal(p) if err != nil { @@ -345,12 +328,6 @@ func (n *NodeLabeller) removeLabellerLabels(node *v1.Node) { delete(node.Labels, label) } } - - for annotation := range node.Annotations { - if strings.HasPrefix(annotation, util.DeprecatedLabellerNamespaceAnnotation) { - delete(node.Annotations, annotation) - } - } } const kernelSchedRealtimeRuntimeInMicrosecods = "kernel.sched_rt_runtime_us" diff --git a/pkg/virt-handler/node-labeller/util/util.go b/pkg/virt-handler/node-labeller/util/util.go index e1f0f104a269..f0d450ed7a8a 100644 --- a/pkg/virt-handler/node-labeller/util/util.go +++ b/pkg/virt-handler/node-labeller/util/util.go @@ -20,15 +20,10 @@ package util const ( - DeprecatedLabelNamespace string = "feature.node.kubernetes.io" - DeprecatedLabellerNamespaceAnnotation = "node-labeller-feature.node.kubernetes.io" - DeprecatedcpuFeaturePrefix = "/cpu-feature-" - DeprecatedcpuModelPrefix = "/cpu-model-" - DeprecatedHyperPrefix = "/kvm-info-cap-hyperv-" - DefaultMinCPUModel = "Penryn" - RequirePolicy = "require" - KVMPath = "/dev/kvm" - VmxFeature = "vmx" + DefaultMinCPUModel = "Penryn" + RequirePolicy = "require" + KVMPath = "/dev/kvm" + VmxFeature = "vmx" ) var DefaultObsoleteCPUModels = map[string]bool{ diff --git a/tests/infrastructure/node-labeller.go b/tests/infrastructure/node-labeller.go index 5f17160d69c5..4ff11b322fcb 100644 --- a/tests/infrastructure/node-labeller.go +++ b/tests/infrastructure/node-labeller.go @@ -405,117 +405,4 @@ var _ = DescribeInfra("Node-labeller", func() { }) }) - - Context("Clean up after old labeller", func() { - nfdLabel := "feature.node.kubernetes.io/some-fancy-feature-which-should-not-be-deleted" - var originalKubeVirt *v1.KubeVirt - - BeforeEach(func() { - originalKubeVirt = util.GetCurrentKv(virtClient) - - }) - - AfterEach(func() { - originalNode, err := virtClient.CoreV1().Nodes().Get(context.Background(), nodesWithKVM[0].Name, metav1.GetOptions{}) - Expect(err).ToNot(HaveOccurred()) - - node := originalNode.DeepCopy() - - for key := range node.Labels { - if strings.Contains(key, nfdLabel) { - delete(node.Labels, nfdLabel) - } - } - originalLabelsBytes, err := json.Marshal(originalNode.Labels) - Expect(err).ToNot(HaveOccurred()) - - labelsBytes, err := json.Marshal(node.Labels) - Expect(err).ToNot(HaveOccurred()) - - patchTestLabels := fmt.Sprintf(`{ "op": "test", "path": "/metadata/labels", "value": %s}`, string(originalLabelsBytes)) - patchLabels := fmt.Sprintf(`{ "op": "replace", "path": "/metadata/labels", "value": %s}`, string(labelsBytes)) - - data := []byte(fmt.Sprintf("[ %s, %s ]", patchTestLabels, patchLabels)) - - _, err = virtClient.CoreV1().Nodes().Patch(context.Background(), nodesWithKVM[0].Name, types.JSONPatchType, data, metav1.PatchOptions{}) - Expect(err).ToNot(HaveOccurred()) - }) - - It("[test_id:6253] should remove old labeller labels and annotations", func() { - originalNode, err := virtClient.CoreV1().Nodes().Get(context.Background(), nodesWithKVM[0].Name, metav1.GetOptions{}) - Expect(err).ToNot(HaveOccurred()) - - node := originalNode.DeepCopy() - - node.Labels[nodelabellerutil.DeprecatedLabelNamespace+nodelabellerutil.DeprecatedcpuModelPrefix+"Penryn"] = "true" - node.Labels[nodelabellerutil.DeprecatedLabelNamespace+nodelabellerutil.DeprecatedcpuFeaturePrefix+"mmx"] = "true" - node.Labels[nodelabellerutil.DeprecatedLabelNamespace+nodelabellerutil.DeprecatedHyperPrefix+"synic"] = "true" - node.Labels[nfdLabel] = "true" - node.Annotations[nodelabellerutil.DeprecatedLabellerNamespaceAnnotation+nodelabellerutil.DeprecatedcpuModelPrefix+"Penryn"] = "true" - node.Annotations[nodelabellerutil.DeprecatedLabellerNamespaceAnnotation+nodelabellerutil.DeprecatedcpuFeaturePrefix+"mmx"] = "true" - node.Annotations[nodelabellerutil.DeprecatedLabellerNamespaceAnnotation+nodelabellerutil.DeprecatedHyperPrefix+"synic"] = "true" - - originalLabelsBytes, err := json.Marshal(originalNode.Labels) - Expect(err).ToNot(HaveOccurred()) - - originalAnnotationsBytes, err := json.Marshal(originalNode.Annotations) - Expect(err).ToNot(HaveOccurred()) - - labelsBytes, err := json.Marshal(node.Labels) - Expect(err).ToNot(HaveOccurred()) - - annotationsBytes, err := json.Marshal(node.Annotations) - Expect(err).ToNot(HaveOccurred()) - - patchTestLabels := fmt.Sprintf(`{ "op": "test", "path": "/metadata/labels", "value": %s}`, string(originalLabelsBytes)) - patchTestAnnotations := fmt.Sprintf(`{ "op": "test", "path": "/metadata/annotations", "value": %s}`, string(originalAnnotationsBytes)) - patchLabels := fmt.Sprintf(`{ "op": "replace", "path": "/metadata/labels", "value": %s}`, string(labelsBytes)) - patchAnnotations := fmt.Sprintf(`{ "op": "replace", "path": "/metadata/annotations", "value": %s}`, string(annotationsBytes)) - - data := []byte(fmt.Sprintf("[ %s, %s, %s, %s ]", patchTestLabels, patchLabels, patchTestAnnotations, patchAnnotations)) - - _, err = virtClient.CoreV1().Nodes().Patch(context.Background(), nodesWithKVM[0].Name, types.JSONPatchType, data, metav1.PatchOptions{}) - Expect(err).ToNot(HaveOccurred()) - kvConfig := originalKubeVirt.Spec.Configuration.DeepCopy() - kvConfig.ObsoleteCPUModels = map[string]bool{"486": true} - tests.UpdateKubeVirtConfigValueAndWait(*kvConfig) - - expectNodeLabels(node.Name, func(m map[string]string) (valid bool, errorMsg string) { - foundSpecialLabel := false - - for key := range m { - for _, deprecatedPrefix := range []string{nodelabellerutil.DeprecatedcpuModelPrefix, nodelabellerutil.DeprecatedcpuFeaturePrefix, nodelabellerutil.DeprecatedHyperPrefix} { - fullDeprecationLabel := nodelabellerutil.DeprecatedLabelNamespace + deprecatedPrefix - if strings.Contains(key, fullDeprecationLabel) { - return false, fmt.Sprintf("node %s should not contain any label with prefix %s", node.Name, fullDeprecationLabel) - } - } - - if key == nfdLabel { - foundSpecialLabel = true - } - } - - if !foundSpecialLabel { - return false, "labeller should not delete NFD labels" - } - - return true, "" - }) - - Eventually(func() error { - node, err = virtClient.CoreV1().Nodes().Get(context.Background(), nodesWithKVM[0].Name, metav1.GetOptions{}) - Expect(err).ToNot(HaveOccurred()) - - for key := range node.Annotations { - if strings.Contains(key, nodelabellerutil.DeprecatedLabellerNamespaceAnnotation) { - return fmt.Errorf("node %s shouldn't contain any annotations with prefix %s, but found annotation key %s", node.Name, nodelabellerutil.DeprecatedLabellerNamespaceAnnotation, key) - } - } - - return nil - }, 30*time.Second, 2*time.Second).ShouldNot(HaveOccurred()) - }) - - }) })