2019-04-25 14:41:26 +00:00
|
|
|
/*
|
|
|
|
Copyright 2018 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package e2e
|
|
|
|
|
|
|
|
import (
|
2020-11-17 14:40:33 +00:00
|
|
|
"context"
|
2019-04-25 20:19:57 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
2021-01-20 23:48:40 +00:00
|
|
|
"path/filepath"
|
2020-02-21 14:16:37 +00:00
|
|
|
"strings"
|
2019-04-25 20:19:57 +00:00
|
|
|
"time"
|
|
|
|
|
2022-07-07 07:40:19 +00:00
|
|
|
"github.com/google/go-cmp/cmp"
|
2022-09-07 16:25:57 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2021-01-20 23:48:40 +00:00
|
|
|
. "github.com/onsi/gomega"
|
2020-11-17 14:40:33 +00:00
|
|
|
|
2022-10-14 12:28:52 +00:00
|
|
|
corev1 "k8s.io/api/core/v1"
|
2022-07-07 07:40:19 +00:00
|
|
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
|
|
|
extclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
|
2019-04-25 20:19:57 +00:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
clientset "k8s.io/client-go/kubernetes"
|
2022-12-16 20:10:36 +00:00
|
|
|
taintutils "k8s.io/kubernetes/pkg/util/taints"
|
2019-04-25 14:41:26 +00:00
|
|
|
"k8s.io/kubernetes/test/e2e/framework"
|
2022-12-12 14:29:46 +00:00
|
|
|
e2elog "k8s.io/kubernetes/test/e2e/framework"
|
2020-11-17 14:40:33 +00:00
|
|
|
e2enetwork "k8s.io/kubernetes/test/e2e/framework/network"
|
2020-02-05 15:21:36 +00:00
|
|
|
e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
|
2022-12-15 14:40:20 +00:00
|
|
|
admissionapi "k8s.io/pod-security-admission/api"
|
2022-11-24 10:59:38 +00:00
|
|
|
|
2022-08-16 18:39:11 +00:00
|
|
|
nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/pkg/apis/nfd/v1alpha1"
|
2022-11-17 14:57:20 +00:00
|
|
|
nfdclient "sigs.k8s.io/node-feature-discovery/pkg/generated/clientset/versioned"
|
2021-01-20 23:48:40 +00:00
|
|
|
"sigs.k8s.io/node-feature-discovery/source/custom"
|
2020-11-23 16:37:42 +00:00
|
|
|
testutils "sigs.k8s.io/node-feature-discovery/test/e2e/utils"
|
2022-11-24 11:23:34 +00:00
|
|
|
testds "sigs.k8s.io/node-feature-discovery/test/e2e/utils/daemonset"
|
2022-11-24 10:59:38 +00:00
|
|
|
testpod "sigs.k8s.io/node-feature-discovery/test/e2e/utils/pod"
|
2019-04-25 20:19:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-11-30 23:21:21 +00:00
|
|
|
dockerRepo = flag.String("nfd.repo", "gcr.io/k8s-staging-nfd/node-feature-discovery", "Docker repository to fetch image from")
|
|
|
|
dockerTag = flag.String("nfd.tag", "master", "Docker tag to use")
|
|
|
|
dockerImage = fmt.Sprintf("%s:%s", *dockerRepo, *dockerTag)
|
|
|
|
testTolerations = []corev1.Toleration{
|
|
|
|
{
|
|
|
|
Key: "nfd.node.kubernetes.io/fake-special-node",
|
|
|
|
Value: "exists",
|
|
|
|
Effect: "NoExecute",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "nfd.node.kubernetes.io/fake-dedicated-node",
|
|
|
|
Value: "true",
|
|
|
|
Effect: "NoExecute",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "nfd.node.kubernetes.io/performance-optimized-node",
|
|
|
|
Value: "true",
|
|
|
|
Effect: "NoExecute",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "nfd.node.kubernetes.io/foo",
|
|
|
|
Value: "true",
|
|
|
|
Effect: "NoExecute",
|
|
|
|
},
|
|
|
|
}
|
2019-04-25 14:41:26 +00:00
|
|
|
)
|
|
|
|
|
2022-11-30 23:21:21 +00:00
|
|
|
const TestTaintNs = "nfd.node.kubernetes.io"
|
|
|
|
|
2020-02-21 14:16:37 +00:00
|
|
|
// cleanupNode deletes all NFD-related metadata from the Node object, i.e.
|
|
|
|
// labels and annotations
|
|
|
|
func cleanupNode(cs clientset.Interface) {
|
2020-11-17 14:40:33 +00:00
|
|
|
nodeList, err := cs.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2020-02-21 14:16:37 +00:00
|
|
|
|
|
|
|
for _, n := range nodeList.Items {
|
|
|
|
var err error
|
2022-10-14 12:28:52 +00:00
|
|
|
var node *corev1.Node
|
2020-02-21 14:16:37 +00:00
|
|
|
for retry := 0; retry < 5; retry++ {
|
2020-11-17 14:40:33 +00:00
|
|
|
node, err = cs.CoreV1().Nodes().Get(context.TODO(), n.Name, metav1.GetOptions{})
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-04-25 20:19:57 +00:00
|
|
|
|
2020-02-21 14:16:37 +00:00
|
|
|
update := false
|
|
|
|
// Remove labels
|
|
|
|
for key := range node.Labels {
|
2022-08-16 18:39:11 +00:00
|
|
|
if strings.HasPrefix(key, nfdv1alpha1.FeatureLabelNs) {
|
2020-02-21 14:16:37 +00:00
|
|
|
delete(node.Labels, key)
|
|
|
|
update = true
|
|
|
|
}
|
|
|
|
}
|
2019-04-25 20:19:57 +00:00
|
|
|
|
2020-02-21 14:16:37 +00:00
|
|
|
// Remove annotations
|
|
|
|
for key := range node.Annotations {
|
2022-08-16 18:39:11 +00:00
|
|
|
if strings.HasPrefix(key, nfdv1alpha1.AnnotationNs) {
|
2020-02-21 14:16:37 +00:00
|
|
|
delete(node.Annotations, key)
|
|
|
|
update = true
|
|
|
|
}
|
2019-04-25 20:19:57 +00:00
|
|
|
}
|
|
|
|
|
2022-11-30 23:21:21 +00:00
|
|
|
// Remove taints
|
|
|
|
for _, taint := range node.Spec.Taints {
|
|
|
|
if strings.HasPrefix(taint.Key, TestTaintNs) {
|
|
|
|
newTaints, removed := taintutils.DeleteTaint(node.Spec.Taints, &taint)
|
|
|
|
if removed {
|
|
|
|
node.Spec.Taints = newTaints
|
|
|
|
update = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 12:26:25 +00:00
|
|
|
if !update {
|
2020-02-21 14:16:37 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2022-11-30 23:21:21 +00:00
|
|
|
By("Deleting NFD labels, annotations and taints from node " + node.Name)
|
2020-11-17 14:40:33 +00:00
|
|
|
_, err = cs.CoreV1().Nodes().Update(context.TODO(), node, metav1.UpdateOptions{})
|
2020-02-21 14:16:37 +00:00
|
|
|
if err != nil {
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
2022-12-14 16:17:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func cleanupCRDs(cli *nfdclient.Clientset) {
|
|
|
|
// Drop NodeFeatureRule objects
|
|
|
|
nfrs, err := cli.NfdV1alpha1().NodeFeatureRules().List(context.TODO(), metav1.ListOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
By("Deleting NodeFeatureRule objects from the cluster")
|
|
|
|
for _, nfr := range nfrs.Items {
|
|
|
|
err = cli.NfdV1alpha1().NodeFeatureRules().Delete(context.TODO(), nfr.Name, metav1.DeleteOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
}
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Actual test suite
|
2022-12-14 19:59:15 +00:00
|
|
|
var _ = SIGDescribe("Node Feature Discovery", func() {
|
2020-02-21 14:16:37 +00:00
|
|
|
f := framework.NewDefaultFramework("node-feature-discovery")
|
|
|
|
|
2022-12-14 16:17:20 +00:00
|
|
|
Context("when deploying a single nfd-master pod", Ordered, func() {
|
|
|
|
var (
|
|
|
|
masterPod *corev1.Pod
|
|
|
|
crds []*apiextensionsv1.CustomResourceDefinition
|
|
|
|
extClient *extclient.Clientset
|
|
|
|
nfdClient *nfdclient.Clientset
|
|
|
|
)
|
|
|
|
|
|
|
|
BeforeAll(func() {
|
|
|
|
// Create clients for apiextensions and our CRD api
|
|
|
|
extClient = extclient.NewForConfigOrDie(f.ClientConfig())
|
|
|
|
nfdClient = nfdclient.NewForConfigOrDie(f.ClientConfig())
|
|
|
|
|
|
|
|
By("Creating NFD CRDs")
|
|
|
|
var err error
|
|
|
|
crds, err = testutils.CreateNfdCRDs(extClient)
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
|
|
|
|
AfterAll(func() {
|
|
|
|
for _, crd := range crds {
|
|
|
|
err := extClient.ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), crd.Name, metav1.DeleteOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
}
|
|
|
|
})
|
2020-02-21 14:16:37 +00:00
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
BeforeEach(func() {
|
2022-12-15 14:40:20 +00:00
|
|
|
// Drop the pod security admission label as nfd-worker needs host mounts
|
|
|
|
if _, ok := f.Namespace.Labels[admissionapi.EnforceLevelLabel]; ok {
|
|
|
|
e2elog.Logf("Deleting %s label from the test namespace", admissionapi.EnforceLevelLabel)
|
|
|
|
delete(f.Namespace.Labels, admissionapi.EnforceLevelLabel)
|
|
|
|
_, err := f.ClientSet.CoreV1().Namespaces().Update(context.TODO(), f.Namespace, metav1.UpdateOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
}
|
|
|
|
|
2020-11-23 16:37:42 +00:00
|
|
|
err := testutils.ConfigureRBAC(f.ClientSet, f.Namespace.Name)
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-04-25 20:19:57 +00:00
|
|
|
|
2022-12-14 16:17:20 +00:00
|
|
|
// Remove pre-existing stale annotations and labels etc and CRDs
|
2022-07-06 11:42:01 +00:00
|
|
|
cleanupNode(f.ClientSet)
|
2022-12-14 16:17:20 +00:00
|
|
|
cleanupCRDs(nfdClient)
|
2022-07-06 11:42:01 +00:00
|
|
|
|
2019-04-25 20:19:57 +00:00
|
|
|
// Launch nfd-master
|
2021-01-20 23:48:40 +00:00
|
|
|
By("Creating nfd master pod and nfd-master service")
|
2022-11-30 23:21:21 +00:00
|
|
|
|
|
|
|
imageOpt := []testpod.SpecOption{
|
|
|
|
testpod.SpecWithContainerImage(dockerImage),
|
|
|
|
testpod.SpecWithTolerations(testTolerations),
|
|
|
|
testpod.SpecWithContainerExtraArgs("-enable-taints"),
|
|
|
|
}
|
|
|
|
masterPod = e2epod.NewPodClient(f).CreateSync(testpod.NFDMaster(imageOpt...))
|
2019-04-25 20:19:57 +00:00
|
|
|
|
|
|
|
// Create nfd-master service
|
2020-11-23 16:37:42 +00:00
|
|
|
nfdSvc, err := testutils.CreateService(f.ClientSet, f.Namespace.Name)
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2019-04-25 20:19:57 +00:00
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
By("Waiting for the nfd-master pod to be running")
|
|
|
|
Expect(e2epod.WaitTimeoutForPodRunningInNamespace(f.ClientSet, masterPod.Name, masterPod.Namespace, time.Minute)).NotTo(HaveOccurred())
|
2019-04-25 20:19:57 +00:00
|
|
|
|
2022-06-29 11:06:59 +00:00
|
|
|
By("Verifying the node where nfd-master is running")
|
|
|
|
// Get updated masterPod object (we want to know where it was scheduled)
|
|
|
|
masterPod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(context.TODO(), masterPod.ObjectMeta.Name, metav1.GetOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
// Node running nfd-master should have master version annotation
|
|
|
|
masterPodNode, err := f.ClientSet.CoreV1().Nodes().Get(context.TODO(), masterPod.Spec.NodeName, metav1.GetOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2022-08-16 18:39:11 +00:00
|
|
|
Expect(masterPodNode.Annotations).To(HaveKey(nfdv1alpha1.AnnotationNs + "/master.version"))
|
2022-06-29 11:06:59 +00:00
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
By("Waiting for the nfd-master service to be up")
|
|
|
|
Expect(e2enetwork.WaitForService(f.ClientSet, f.Namespace.Name, nfdSvc.ObjectMeta.Name, true, time.Second, 10*time.Second)).NotTo(HaveOccurred())
|
2020-02-21 14:16:37 +00:00
|
|
|
})
|
2019-04-25 20:19:57 +00:00
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
AfterEach(func() {
|
2022-07-06 11:42:01 +00:00
|
|
|
Expect(testutils.DeconfigureRBAC(f.ClientSet, f.Namespace.Name)).NotTo(HaveOccurred())
|
2019-04-25 20:19:57 +00:00
|
|
|
|
2022-07-06 11:42:01 +00:00
|
|
|
cleanupNode(f.ClientSet)
|
2022-12-14 16:17:20 +00:00
|
|
|
cleanupCRDs(nfdClient)
|
2020-02-21 14:16:37 +00:00
|
|
|
})
|
2019-04-25 20:19:57 +00:00
|
|
|
|
2020-02-21 14:16:37 +00:00
|
|
|
//
|
|
|
|
// Simple test with only the fake source enabled
|
|
|
|
//
|
2021-01-20 23:48:40 +00:00
|
|
|
Context("and a single worker pod with fake source enabled", func() {
|
|
|
|
It("it should decorate the node with the fake feature labels", func() {
|
2020-02-21 14:16:37 +00:00
|
|
|
|
|
|
|
fakeFeatureLabels := map[string]string{
|
2022-08-16 18:39:11 +00:00
|
|
|
nfdv1alpha1.FeatureLabelNs + "/fake-fakefeature1": "true",
|
|
|
|
nfdv1alpha1.FeatureLabelNs + "/fake-fakefeature2": "true",
|
|
|
|
nfdv1alpha1.FeatureLabelNs + "/fake-fakefeature3": "true",
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Launch nfd-worker
|
2021-01-20 23:48:40 +00:00
|
|
|
By("Creating a nfd worker pod")
|
2022-11-24 10:59:38 +00:00
|
|
|
podSpecOpts := []testpod.SpecOption{
|
2022-12-01 14:03:56 +00:00
|
|
|
testpod.SpecWithRestartPolicy(corev1.RestartPolicyNever),
|
2022-12-14 15:16:03 +00:00
|
|
|
testpod.SpecWithContainerImage(dockerImage),
|
2022-11-24 10:59:38 +00:00
|
|
|
testpod.SpecWithContainerExtraArgs("-oneshot", "-label-sources=fake"),
|
2022-11-30 23:21:21 +00:00
|
|
|
testpod.SpecWithTolerations(testTolerations),
|
2022-11-22 15:50:54 +00:00
|
|
|
}
|
2022-11-24 10:59:38 +00:00
|
|
|
workerPod := testpod.NFDWorker(podSpecOpts...)
|
2020-11-17 14:40:33 +00:00
|
|
|
workerPod, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).Create(context.TODO(), workerPod, metav1.CreateOptions{})
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2020-02-21 14:16:37 +00:00
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
By("Waiting for the nfd-worker pod to succeed")
|
|
|
|
Expect(e2epod.WaitForPodSuccessInNamespace(f.ClientSet, workerPod.ObjectMeta.Name, f.Namespace.Name)).NotTo(HaveOccurred())
|
2020-11-17 14:40:33 +00:00
|
|
|
workerPod, err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Get(context.TODO(), workerPod.ObjectMeta.Name, metav1.GetOptions{})
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2020-02-21 14:16:37 +00:00
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
By(fmt.Sprintf("Making sure '%s' was decorated with the fake feature labels", workerPod.Spec.NodeName))
|
2020-11-17 14:40:33 +00:00
|
|
|
node, err := f.ClientSet.CoreV1().Nodes().Get(context.TODO(), workerPod.Spec.NodeName, metav1.GetOptions{})
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2020-02-21 14:16:37 +00:00
|
|
|
for k, v := range fakeFeatureLabels {
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(node.Labels[k]).To(Equal(v))
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check that there are no unexpected NFD labels
|
|
|
|
for k := range node.Labels {
|
2022-08-16 18:39:11 +00:00
|
|
|
if strings.HasPrefix(k, nfdv1alpha1.FeatureLabelNs) {
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(fakeFeatureLabels).Should(HaveKey(k))
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
By("Deleting the node-feature-discovery worker pod")
|
2020-11-17 14:40:33 +00:00
|
|
|
err = f.ClientSet.CoreV1().Pods(f.Namespace.Name).Delete(context.TODO(), workerPod.ObjectMeta.Name, metav1.DeleteOptions{})
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2020-02-21 14:16:37 +00:00
|
|
|
})
|
|
|
|
})
|
2019-04-25 20:19:57 +00:00
|
|
|
|
2020-02-21 14:16:37 +00:00
|
|
|
//
|
|
|
|
// More comprehensive test when --e2e-node-config is enabled
|
|
|
|
//
|
2021-01-20 23:48:40 +00:00
|
|
|
Context("and nfd-workers as a daemonset with default sources enabled", func() {
|
|
|
|
It("the node labels and annotations listed in the e2e config should be present", func() {
|
2020-11-23 16:37:42 +00:00
|
|
|
cfg, err := testutils.GetConfig()
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
if cfg == nil {
|
2021-01-20 23:48:40 +00:00
|
|
|
Skip("no e2e-config was specified")
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
2020-11-23 16:37:42 +00:00
|
|
|
if cfg.DefaultFeatures == nil {
|
2021-01-20 23:48:40 +00:00
|
|
|
Skip("no 'defaultFeatures' specified in e2e-config")
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
2020-11-23 16:37:42 +00:00
|
|
|
fConf := cfg.DefaultFeatures
|
2020-02-21 14:16:37 +00:00
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
By("Creating nfd-worker daemonset")
|
2022-11-30 23:21:21 +00:00
|
|
|
podSpecOpts := []testpod.SpecOption{
|
|
|
|
testpod.SpecWithContainerImage(dockerImage),
|
|
|
|
testpod.SpecWithTolerations(testTolerations),
|
|
|
|
}
|
2022-11-24 11:23:34 +00:00
|
|
|
workerDS := testds.NFDWorker(podSpecOpts...)
|
2020-11-23 16:37:42 +00:00
|
|
|
workerDS, err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Create(context.TODO(), workerDS, metav1.CreateOptions{})
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2020-02-21 14:16:37 +00:00
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
By("Waiting for daemonset pods to be ready")
|
2022-11-24 10:59:38 +00:00
|
|
|
Expect(testpod.WaitForReady(f.ClientSet, f.Namespace.Name, workerDS.Spec.Template.Labels["name"], 5)).NotTo(HaveOccurred())
|
2020-02-21 14:16:37 +00:00
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
By("Getting node objects")
|
2020-11-17 14:40:33 +00:00
|
|
|
nodeList, err := f.ClientSet.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2022-11-30 23:21:21 +00:00
|
|
|
Expect(len(nodeList.Items)).ToNot(BeZero())
|
2020-02-21 14:16:37 +00:00
|
|
|
|
|
|
|
for _, node := range nodeList.Items {
|
2020-11-23 16:37:42 +00:00
|
|
|
nodeConf := testutils.FindNodeConfig(cfg, node.Name)
|
2020-08-26 07:22:46 +00:00
|
|
|
if nodeConf == nil {
|
|
|
|
e2elog.Logf("node %q has no matching rule in e2e-config, skipping...", node.Name)
|
2020-02-21 14:16:37 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check labels
|
2020-05-25 12:33:06 +00:00
|
|
|
e2elog.Logf("verifying labels of node %q...", node.Name)
|
2020-02-21 14:16:37 +00:00
|
|
|
for k, v := range nodeConf.ExpectedLabelValues {
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(node.Labels).To(HaveKeyWithValue(k, v))
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
|
|
|
for k := range nodeConf.ExpectedLabelKeys {
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(node.Labels).To(HaveKey(k))
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
|
|
|
for k := range node.Labels {
|
2022-08-16 18:39:11 +00:00
|
|
|
if strings.HasPrefix(k, nfdv1alpha1.FeatureLabelNs) {
|
2020-02-21 14:16:37 +00:00
|
|
|
if _, ok := nodeConf.ExpectedLabelValues[k]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _, ok := nodeConf.ExpectedLabelKeys[k]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Ignore if the label key was not whitelisted
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(fConf.LabelWhitelist).NotTo(HaveKey(k))
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check annotations
|
2020-05-25 12:33:06 +00:00
|
|
|
e2elog.Logf("verifying annotations of node %q...", node.Name)
|
2020-02-21 14:16:37 +00:00
|
|
|
for k, v := range nodeConf.ExpectedAnnotationValues {
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(node.Annotations).To(HaveKeyWithValue(k, v))
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
|
|
|
for k := range nodeConf.ExpectedAnnotationKeys {
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(node.Annotations).To(HaveKey(k))
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
|
|
|
for k := range node.Annotations {
|
2022-08-16 18:39:11 +00:00
|
|
|
if strings.HasPrefix(k, nfdv1alpha1.AnnotationNs) {
|
2020-02-21 14:16:37 +00:00
|
|
|
if _, ok := nodeConf.ExpectedAnnotationValues[k]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if _, ok := nodeConf.ExpectedAnnotationKeys[k]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Ignore if the annotation was not whitelisted
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(fConf.AnnotationWhitelist).NotTo(HaveKey(k))
|
2020-02-21 14:16:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-01-20 23:48:40 +00:00
|
|
|
By("Deleting nfd-worker daemonset")
|
2020-11-17 14:40:33 +00:00
|
|
|
err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Delete(context.TODO(), workerDS.ObjectMeta.Name, metav1.DeleteOptions{})
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
2020-02-21 14:16:37 +00:00
|
|
|
})
|
2019-04-25 14:41:26 +00:00
|
|
|
})
|
2021-01-20 23:48:40 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Test custom nodename source configured in 2 additional ConfigMaps
|
|
|
|
//
|
|
|
|
Context("and nfd-workers as a daemonset with 2 additional configmaps for the custom source configured", func() {
|
|
|
|
It("the nodename matching features listed in the configmaps should be present", func() {
|
|
|
|
By("Getting a worker node")
|
|
|
|
|
|
|
|
// We need a valid nodename for the configmap
|
2022-12-16 20:10:36 +00:00
|
|
|
nodes, err := getNonControlPlaneNodes(f.ClientSet)
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2022-12-16 20:10:36 +00:00
|
|
|
targetNodeName := nodes[0].Name
|
2021-01-20 23:48:40 +00:00
|
|
|
Expect(targetNodeName).ToNot(BeEmpty(), "No worker node found")
|
|
|
|
|
|
|
|
// create a wildcard name as well for this node
|
|
|
|
targetNodeNameWildcard := fmt.Sprintf("%s.*%s", targetNodeName[:2], targetNodeName[4:])
|
|
|
|
|
|
|
|
By("Creating the configmaps")
|
|
|
|
targetLabelName := "nodename-test"
|
|
|
|
targetLabelValue := "true"
|
|
|
|
|
|
|
|
targetLabelNameWildcard := "nodename-test-wildcard"
|
|
|
|
targetLabelValueWildcard := "customValue"
|
|
|
|
|
|
|
|
targetLabelNameNegative := "nodename-test-negative"
|
|
|
|
|
|
|
|
// create 2 configmaps
|
2022-11-22 18:58:53 +00:00
|
|
|
data1 := `
|
2021-01-20 23:48:40 +00:00
|
|
|
- name: ` + targetLabelName + `
|
|
|
|
matchOn:
|
|
|
|
# default value is true
|
|
|
|
- nodename:
|
|
|
|
- ` + targetNodeName
|
|
|
|
|
2022-11-22 18:58:53 +00:00
|
|
|
cm1 := testutils.NewConfigMap("custom-config-extra-1", "custom.conf", data1)
|
2021-01-20 23:48:40 +00:00
|
|
|
cm1, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(context.TODO(), cm1, metav1.CreateOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2022-11-22 18:58:53 +00:00
|
|
|
data2 := `
|
2021-01-20 23:48:40 +00:00
|
|
|
- name: ` + targetLabelNameWildcard + `
|
|
|
|
value: ` + targetLabelValueWildcard + `
|
|
|
|
matchOn:
|
|
|
|
- nodename:
|
|
|
|
- ` + targetNodeNameWildcard + `
|
|
|
|
- name: ` + targetLabelNameNegative + `
|
|
|
|
matchOn:
|
|
|
|
- nodename:
|
|
|
|
- "thisNameShouldNeverMatch"`
|
|
|
|
|
2022-11-22 18:58:53 +00:00
|
|
|
cm2 := testutils.NewConfigMap("custom-config-extra-2", "custom.conf", data2)
|
2021-01-20 23:48:40 +00:00
|
|
|
cm2, err = f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(context.TODO(), cm2, metav1.CreateOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
By("Creating nfd-worker daemonset with configmap mounted")
|
2022-11-24 10:59:38 +00:00
|
|
|
podSpecOpts := []testpod.SpecOption{
|
2022-12-14 15:16:03 +00:00
|
|
|
testpod.SpecWithContainerImage(dockerImage),
|
2022-11-24 10:59:38 +00:00
|
|
|
testpod.SpecWithConfigMap(cm1.Name, filepath.Join(custom.Directory, "cm1")),
|
|
|
|
testpod.SpecWithConfigMap(cm2.Name, filepath.Join(custom.Directory, "cm2")),
|
2022-11-30 23:21:21 +00:00
|
|
|
testpod.SpecWithTolerations(testTolerations),
|
2022-11-22 15:50:54 +00:00
|
|
|
}
|
2022-11-24 11:23:34 +00:00
|
|
|
workerDS := testds.NFDWorker(podSpecOpts...)
|
2021-01-20 23:48:40 +00:00
|
|
|
|
|
|
|
workerDS, err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Create(context.TODO(), workerDS, metav1.CreateOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
By("Waiting for daemonset pods to be ready")
|
2022-11-24 10:59:38 +00:00
|
|
|
Expect(testpod.WaitForReady(f.ClientSet, f.Namespace.Name, workerDS.Spec.Template.Labels["name"], 5)).NotTo(HaveOccurred())
|
2021-01-20 23:48:40 +00:00
|
|
|
|
|
|
|
By("Getting target node and checking labels")
|
|
|
|
targetNode, err := f.ClientSet.CoreV1().Nodes().Get(context.TODO(), targetNodeName, metav1.GetOptions{})
|
|
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
|
|
|
|
labelFound := false
|
|
|
|
labelWildcardFound := false
|
|
|
|
labelNegativeFound := false
|
|
|
|
for k := range targetNode.Labels {
|
|
|
|
if strings.Contains(k, targetLabelName) {
|
|
|
|
if targetNode.Labels[k] == targetLabelValue {
|
|
|
|
labelFound = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if strings.Contains(k, targetLabelNameWildcard) {
|
|
|
|
if targetNode.Labels[k] == targetLabelValueWildcard {
|
|
|
|
labelWildcardFound = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if strings.Contains(k, targetLabelNameNegative) {
|
|
|
|
labelNegativeFound = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Expect(labelFound).To(BeTrue(), "label not found!")
|
|
|
|
Expect(labelWildcardFound).To(BeTrue(), "label for wildcard nodename not found!")
|
|
|
|
Expect(labelNegativeFound).To(BeFalse(), "label for not existing nodename found!")
|
|
|
|
|
|
|
|
By("Deleting nfd-worker daemonset")
|
|
|
|
err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Delete(context.TODO(), workerDS.ObjectMeta.Name, metav1.DeleteOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-07-07 07:40:19 +00:00
|
|
|
//
|
|
|
|
// Test NodeFeatureRule
|
|
|
|
//
|
|
|
|
Context("and nfd-worker and NodeFeatureRules objects deployed", func() {
|
|
|
|
It("custom labels from the NodeFeatureRule rules should be created", func() {
|
2022-11-29 08:19:11 +00:00
|
|
|
By("Creating nfd-worker config")
|
|
|
|
cm := testutils.NewConfigMap("nfd-worker-conf", "nfd-worker.conf", `
|
|
|
|
core:
|
|
|
|
sleepInterval: "1s"
|
|
|
|
featureSources: ["fake"]
|
|
|
|
labelSources: []
|
|
|
|
`)
|
|
|
|
cm, err := f.ClientSet.CoreV1().ConfigMaps(f.Namespace.Name).Create(context.TODO(), cm, metav1.CreateOptions{})
|
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
2022-07-07 07:40:19 +00:00
|
|
|
By("Creating nfd-worker daemonset")
|
2022-11-24 10:59:38 +00:00
|
|
|
podSpecOpts := []testpod.SpecOption{
|
2022-12-14 15:16:03 +00:00
|
|
|
testpod.SpecWithContainerImage(dockerImage),
|
2022-11-24 10:59:38 +00:00
|
|
|
testpod.SpecWithConfigMap(cm.Name, "/etc/kubernetes/node-feature-discovery"),
|
2022-11-30 23:21:21 +00:00
|
|
|
testpod.SpecWithTolerations(testTolerations),
|
2022-11-22 15:50:54 +00:00
|
|
|
}
|
2022-11-24 11:23:34 +00:00
|
|
|
workerDS := testds.NFDWorker(podSpecOpts...)
|
2022-11-29 08:19:11 +00:00
|
|
|
workerDS, err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Create(context.TODO(), workerDS, metav1.CreateOptions{})
|
2022-07-07 07:40:19 +00:00
|
|
|
Expect(err).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
By("Waiting for daemonset pods to be ready")
|
2022-11-24 10:59:38 +00:00
|
|
|
Expect(testpod.WaitForReady(f.ClientSet, f.Namespace.Name, workerDS.Spec.Template.Labels["name"], 5)).NotTo(HaveOccurred())
|
2022-07-07 07:40:19 +00:00
|
|
|
|
|
|
|
expected := map[string]string{
|
|
|
|
"feature.node.kubernetes.io/e2e-flag-test-1": "true",
|
|
|
|
"feature.node.kubernetes.io/e2e-attribute-test-1": "true",
|
|
|
|
"feature.node.kubernetes.io/e2e-instance-test-1": "true"}
|
|
|
|
|
|
|
|
By("Creating NodeFeatureRules #1")
|
2022-12-14 12:14:49 +00:00
|
|
|
Expect(testutils.CreateNodeFeatureRulesFromFile(nfdClient, "nodefeaturerule-1.yaml")).NotTo(HaveOccurred())
|
2022-07-07 07:40:19 +00:00
|
|
|
|
|
|
|
By("Verifying node labels from NodeFeatureRules #1")
|
|
|
|
Expect(waitForNfdNodeLabels(f.ClientSet, expected)).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
By("Creating NodeFeatureRules #2")
|
2022-12-14 12:14:49 +00:00
|
|
|
Expect(testutils.CreateNodeFeatureRulesFromFile(nfdClient, "nodefeaturerule-2.yaml")).NotTo(HaveOccurred())
|
2022-07-07 07:40:19 +00:00
|
|
|
|
|
|
|
// Add features from NodeFeatureRule #2
|
|
|
|
expected["feature.node.kubernetes.io/e2e-matchany-test-1"] = "true"
|
|
|
|
expected["feature.node.kubernetes.io/e2e-template-test-1-instance_1"] = "found"
|
|
|
|
expected["feature.node.kubernetes.io/e2e-template-test-1-instance_2"] = "found"
|
2020-02-21 14:16:37 +00:00
|
|
|
|
2022-07-07 07:40:19 +00:00
|
|
|
By("Verifying node labels from NodeFeatureRules #1 and #2")
|
|
|
|
Expect(waitForNfdNodeLabels(f.ClientSet, expected)).NotTo(HaveOccurred())
|
2022-11-30 23:21:21 +00:00
|
|
|
|
|
|
|
// Add features from NodeFeatureRule #3
|
|
|
|
By("Creating NodeFeatureRules #3")
|
|
|
|
Expect(testutils.CreateNodeFeatureRulesFromFile(nfdClient, "nodefeaturerule-3.yaml")).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
By("Verifying node taints and annotation from NodeFeatureRules #3")
|
|
|
|
expectedTaints := []corev1.Taint{
|
|
|
|
{
|
|
|
|
Key: "nfd.node.kubernetes.io/fake-special-node",
|
|
|
|
Value: "exists",
|
|
|
|
Effect: "PreferNoSchedule",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "nfd.node.kubernetes.io/fake-dedicated-node",
|
|
|
|
Value: "true",
|
|
|
|
Effect: "NoExecute",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "nfd.node.kubernetes.io/performance-optimized-node",
|
|
|
|
Value: "true",
|
|
|
|
Effect: "NoExecute",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expectedAnnotation := map[string]string{
|
|
|
|
"nfd.node.kubernetes.io/taints": "nfd.node.kubernetes.io/fake-special-node=exists:PreferNoSchedule,nfd.node.kubernetes.io/fake-dedicated-node=true:NoExecute,nfd.node.kubernetes.io/performance-optimized-node=true:NoExecute"}
|
|
|
|
Expect(waitForNfdNodeTaints(f.ClientSet, expectedTaints)).NotTo(HaveOccurred())
|
|
|
|
Expect(waitForNfdNodeAnnotations(f.ClientSet, expectedAnnotation)).NotTo(HaveOccurred())
|
|
|
|
|
|
|
|
By("Re-applying NodeFeatureRules #3 with updated taints")
|
|
|
|
Expect(testutils.UpdateNodeFeatureRulesFromFile(nfdClient, "nodefeaturerule-3-updated.yaml")).NotTo(HaveOccurred())
|
|
|
|
expectedTaintsUpdated := []corev1.Taint{
|
|
|
|
{
|
|
|
|
Key: "nfd.node.kubernetes.io/fake-special-node",
|
|
|
|
Value: "exists",
|
|
|
|
Effect: "PreferNoSchedule",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "nfd.node.kubernetes.io/foo",
|
|
|
|
Value: "true",
|
|
|
|
Effect: "NoExecute",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
expectedAnnotationUpdated := map[string]string{
|
|
|
|
"nfd.node.kubernetes.io/taints": "nfd.node.kubernetes.io/fake-special-node=exists:PreferNoSchedule,nfd.node.kubernetes.io/foo=true:NoExecute"}
|
|
|
|
|
|
|
|
By("Verifying updated node taints and annotation from NodeFeatureRules #3")
|
|
|
|
Expect(waitForNfdNodeTaints(f.ClientSet, expectedTaintsUpdated)).NotTo(HaveOccurred())
|
|
|
|
Expect(waitForNfdNodeAnnotations(f.ClientSet, expectedAnnotationUpdated)).NotTo(HaveOccurred())
|
2022-07-07 07:40:19 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-04-25 14:41:26 +00:00
|
|
|
})
|
2022-07-07 07:40:19 +00:00
|
|
|
|
2022-11-30 23:21:21 +00:00
|
|
|
// waitForNfdNodeAnnotations waits for node to be annotated as expected.
|
|
|
|
func waitForNfdNodeAnnotations(cli clientset.Interface, expected map[string]string) error {
|
|
|
|
poll := func() error {
|
|
|
|
nodes, err := getNonControlPlaneNodes(cli)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, node := range nodes {
|
|
|
|
for k, v := range expected {
|
|
|
|
if diff := cmp.Diff(v, node.Annotations[k]); diff != "" {
|
|
|
|
return fmt.Errorf("node %q annotation does not match expected, diff (expected vs. received): %s", node.Name, diff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simple and stupid re-try loop
|
|
|
|
var err error
|
|
|
|
for retry := 0; retry < 3; retry++ {
|
|
|
|
if err = poll(); err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-07-07 07:40:19 +00:00
|
|
|
// waitForNfdNodeLabels waits for node to be labeled as expected.
|
|
|
|
func waitForNfdNodeLabels(cli clientset.Interface, expected map[string]string) error {
|
|
|
|
poll := func() error {
|
2022-12-16 20:10:36 +00:00
|
|
|
nodes, err := getNonControlPlaneNodes(cli)
|
2022-07-07 07:40:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-16 20:10:36 +00:00
|
|
|
for _, node := range nodes {
|
2022-07-07 07:40:19 +00:00
|
|
|
labels := nfdLabels(node.Labels)
|
|
|
|
if !cmp.Equal(expected, labels) {
|
|
|
|
return fmt.Errorf("node %q labels do not match expected, diff (expected vs. received): %s", node.Name, cmp.Diff(expected, labels))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simple and stupid re-try loop
|
|
|
|
var err error
|
|
|
|
for retry := 0; retry < 3; retry++ {
|
|
|
|
if err = poll(); err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-30 23:21:21 +00:00
|
|
|
// waitForNfdNodeTaints waits for node to be tainted as expected.
|
|
|
|
func waitForNfdNodeTaints(cli clientset.Interface, expected []corev1.Taint) error {
|
|
|
|
poll := func() error {
|
|
|
|
nodes, err := getNonControlPlaneNodes(cli)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, node := range nodes {
|
|
|
|
taints := nfdTaints(node.Spec.Taints)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to fetch nfd owned taints for node: %s", node.Name)
|
|
|
|
}
|
|
|
|
if !cmp.Equal(expected, taints) {
|
|
|
|
return fmt.Errorf("node %q taints do not match expected, diff (expected vs. received): %s", node.Name, cmp.Diff(expected, taints))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simple and stupid re-try loop
|
|
|
|
var err error
|
|
|
|
for retry := 0; retry < 3; retry++ {
|
|
|
|
if err = poll(); err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
time.Sleep(10 * time.Second)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// nfdTaints returns taints that are owned by the nfd.
|
|
|
|
func nfdTaints(taints []corev1.Taint) []corev1.Taint {
|
|
|
|
nfdTaints := []corev1.Taint{}
|
|
|
|
for _, taint := range taints {
|
|
|
|
if strings.HasPrefix(taint.Key, TestTaintNs) {
|
|
|
|
nfdTaints = append(nfdTaints, taint)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nfdTaints
|
|
|
|
}
|
|
|
|
|
2022-12-16 20:10:36 +00:00
|
|
|
// getNonControlPlaneNodes gets the nodes that are not tainted for exclusive control-plane usage
|
|
|
|
func getNonControlPlaneNodes(cli clientset.Interface) ([]corev1.Node, error) {
|
|
|
|
nodeList, err := cli.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(nodeList.Items) == 0 {
|
|
|
|
return nil, fmt.Errorf("no nodes found in the cluster")
|
|
|
|
}
|
|
|
|
|
|
|
|
controlPlaneTaint := corev1.Taint{
|
|
|
|
Effect: corev1.TaintEffectNoSchedule,
|
|
|
|
Key: "node-role.kubernetes.io/control-plane",
|
|
|
|
}
|
|
|
|
out := []corev1.Node{}
|
|
|
|
for _, node := range nodeList.Items {
|
|
|
|
if !taintutils.TaintExists(node.Spec.Taints, &controlPlaneTaint) {
|
|
|
|
out = append(out, node)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(out) == 0 {
|
|
|
|
return nil, fmt.Errorf("no non-control-plane nodes found in the cluster")
|
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
2022-07-07 07:40:19 +00:00
|
|
|
// nfdLabels gets labels that are in the nfd label namespace.
|
|
|
|
func nfdLabels(labels map[string]string) map[string]string {
|
|
|
|
ret := map[string]string{}
|
|
|
|
|
|
|
|
for key, val := range labels {
|
|
|
|
if strings.HasPrefix(key, nfdv1alpha1.FeatureLabelNs) {
|
|
|
|
ret[key] = val
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
|
|
|
|
}
|