MCPcopy
hub / github.com/NVIDIA/k8s-device-plugin / cleanupNode

Function cleanupNode

tests/e2e/e2e_test.go:667–752  ·  view source on GitHub ↗

cleanupNode deletes all NFD/GFD related metadata from the Node object, i.e. labels and annotations

(cs clientset.Interface)

Source from the content-addressed store, hash-verified

665// cleanupNode deletes all NFD/GFD related metadata from the Node object, i.e.
666// labels and annotations
667func cleanupNode(cs clientset.Interface) {
668 // Per-node cleanup function
669 cleanup := func(nodeName string) error {
670 node, err := cs.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
671 Expect(err).NotTo(HaveOccurred())
672
673 update := false
674 updateStatus := false
675 // Gather info about all NFD-managed node assets outside the default prefix
676 nfdLabels := map[string]struct{}{}
677 for _, name := range strings.Split(node.Annotations[nfdv1alpha1.FeatureLabelsAnnotation], ",") {
678 if strings.Contains(name, "/") {
679 nfdLabels[name] = struct{}{}
680 }
681 }
682 nfdERs := map[string]struct{}{}
683 for _, name := range strings.Split(node.Annotations[nfdv1alpha1.ExtendedResourceAnnotation], ",") {
684 if strings.Contains(name, "/") {
685 nfdERs[name] = struct{}{}
686 }
687 }
688
689 // Remove labels
690 for key := range node.Labels {
691 _, ok := nfdLabels[key]
692 if ok || strings.HasPrefix(key, nfdv1alpha1.FeatureLabelNs) {
693 delete(node.Labels, key)
694 update = true
695 }
696 }
697
698 // Remove annotations
699 for key := range node.Annotations {
700 if strings.HasPrefix(key, nfdv1alpha1.AnnotationNs) {
701 delete(node.Annotations, key)
702 update = true
703 }
704 }
705
706 // Remove nvidia.com/ labels
707 for key := range node.Labels {
708 if strings.HasPrefix(key, "nvidia.com/") {
709 delete(node.Labels, key)
710 update = true
711 }
712 }
713
714 // Remove extended resources
715 for key := range node.Status.Capacity {
716 // We check for FeatureLabelNs as -resource-labels can create ERs there
717 _, ok := nfdERs[string(key)]
718 if ok || strings.HasPrefix(string(key), nfdv1alpha1.FeatureLabelNs) {
719 delete(node.Status.Capacity, key)
720 delete(node.Status.Allocatable, key)
721 updateStatus = true
722 }
723 }
724

Callers 1

Calls 3

GetMethod · 0.80
ContainsMethod · 0.80
SplitMethod · 0.45

Tested by

no test coverage detected