Skip to content

Commit

Permalink
node-labeller: Remove obsolete node labeller functionality
Browse files Browse the repository at this point in the history
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]
kubevirt@5eb8807

Signed-off-by: Luboslav Pivarc <[email protected]>
Signed-off-by: Ram Lavi <[email protected]>
  • Loading branch information
RamLavi committed Feb 5, 2024
1 parent 0ad95ac commit 73524af
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 146 deletions.
25 changes: 1 addition & 24 deletions pkg/virt-handler/node-labeller/node_labeller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
13 changes: 4 additions & 9 deletions pkg/virt-handler/node-labeller/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
113 changes: 0 additions & 113 deletions tests/infrastructure/node-labeller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})

})
})

0 comments on commit 73524af

Please sign in to comment.