diff --git a/test/e2e/node_feature_discovery.go b/test/e2e/node_feature_discovery.go index 78ec5b8c3..8ea5647ca 100644 --- a/test/e2e/node_feature_discovery.go +++ b/test/e2e/node_feature_discovery.go @@ -42,6 +42,7 @@ import ( nfdclient "sigs.k8s.io/node-feature-discovery/pkg/generated/clientset/versioned" "sigs.k8s.io/node-feature-discovery/source/custom" testutils "sigs.k8s.io/node-feature-discovery/test/e2e/utils" + testds "sigs.k8s.io/node-feature-discovery/test/e2e/utils/daemonset" testpod "sigs.k8s.io/node-feature-discovery/test/e2e/utils/pod" ) @@ -207,7 +208,7 @@ var _ = SIGDescribe("Node Feature Discovery", func() { By("Creating nfd-worker daemonset") podSpecOpts := []testpod.SpecOption{testpod.SpecWithContainerImage(fmt.Sprintf("%s:%s", *dockerRepo, *dockerTag))} - workerDS := testpod.NFDWorkerDaemonSet(podSpecOpts...) + workerDS := testds.NFDWorker(podSpecOpts...) workerDS, err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Create(context.TODO(), workerDS, metav1.CreateOptions{}) Expect(err).NotTo(HaveOccurred()) @@ -341,7 +342,7 @@ var _ = SIGDescribe("Node Feature Discovery", func() { testpod.SpecWithConfigMap(cm1.Name, filepath.Join(custom.Directory, "cm1")), testpod.SpecWithConfigMap(cm2.Name, filepath.Join(custom.Directory, "cm2")), } - workerDS := testpod.NFDWorkerDaemonSet(podSpecOpts...) + workerDS := testds.NFDWorker(podSpecOpts...) workerDS, err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Create(context.TODO(), workerDS, metav1.CreateOptions{}) Expect(err).NotTo(HaveOccurred()) @@ -423,7 +424,7 @@ core: testpod.SpecWithContainerImage(fmt.Sprintf("%s:%s", *dockerRepo, *dockerTag)), testpod.SpecWithConfigMap(cm.Name, "/etc/kubernetes/node-feature-discovery"), } - workerDS := testpod.NFDWorkerDaemonSet(podSpecOpts...) + workerDS := testds.NFDWorker(podSpecOpts...) workerDS, err = f.ClientSet.AppsV1().DaemonSets(f.Namespace.Name).Create(context.TODO(), workerDS, metav1.CreateOptions{}) Expect(err).NotTo(HaveOccurred()) diff --git a/test/e2e/topology_updater.go b/test/e2e/topology_updater.go index d67cbf185..043983a99 100644 --- a/test/e2e/topology_updater.go +++ b/test/e2e/topology_updater.go @@ -39,6 +39,7 @@ import ( admissionapi "k8s.io/pod-security-admission/api" testutils "sigs.k8s.io/node-feature-discovery/test/e2e/utils" + testds "sigs.k8s.io/node-feature-discovery/test/e2e/utils/daemonset" testpod "sigs.k8s.io/node-feature-discovery/test/e2e/utils/pod" ) @@ -121,7 +122,7 @@ var _ = SIGDescribe("Node Feature Discovery topology updater", func() { By(fmt.Sprintf("Using config (%#v)", kcfg)) podSpecOpts := []testpod.SpecOption{testpod.SpecWithContainerImage(fmt.Sprintf("%s:%s", *dockerRepo, *dockerTag))} - topologyUpdaterDaemonSet = testpod.NFDTopologyUpdaterDaemonSet(kcfg, podSpecOpts...) + topologyUpdaterDaemonSet = testds.NFDTopologyUpdater(kcfg, podSpecOpts...) }) It("should fill the node resource topologies CR with the data", func() { @@ -279,7 +280,7 @@ excludeList: testpod.SpecWithContainerImage(fmt.Sprintf("%s:%s", *dockerRepo, *dockerTag)), testpod.SpecWithConfigMap(cm.Name, "/etc/kubernetes/node-feature-discovery"), } - topologyUpdaterDaemonSet = testpod.NFDTopologyUpdaterDaemonSet(kcfg, podSpecOpts...) + topologyUpdaterDaemonSet = testds.NFDTopologyUpdater(kcfg, podSpecOpts...) }) It("noderesourcetopology should not advertise the memory resource", func() { diff --git a/test/e2e/utils/daemonset/daemonset.go b/test/e2e/utils/daemonset/daemonset.go new file mode 100644 index 000000000..920f0de0c --- /dev/null +++ b/test/e2e/utils/daemonset/daemonset.go @@ -0,0 +1,58 @@ +/* +Copyright 2022 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 daemonset + +import ( + appsv1 "k8s.io/api/apps/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/uuid" + + "sigs.k8s.io/node-feature-discovery/test/e2e/utils" + "sigs.k8s.io/node-feature-discovery/test/e2e/utils/pod" +) + +// NFDWorker provides the NFD daemon set worker definition +func NFDWorker(opts ...pod.SpecOption) *appsv1.DaemonSet { + return new("nfd-worker", &pod.NFDWorker(opts...).Spec) +} + +// NFDTopologyUpdater provides the NFD daemon set topology updater +func NFDTopologyUpdater(kc utils.KubeletConfig, opts ...pod.SpecOption) *appsv1.DaemonSet { + return new("nfd-topology-updater", pod.NFDTopologyUpdaterSpec(kc, opts...)) +} + +// new provide the new daemon set +func new(name string, podSpec *corev1.PodSpec) *appsv1.DaemonSet { + return &appsv1.DaemonSet{ + ObjectMeta: metav1.ObjectMeta{ + Name: name + "-" + string(uuid.NewUUID()), + }, + Spec: appsv1.DaemonSetSpec{ + Selector: &metav1.LabelSelector{ + MatchLabels: map[string]string{"name": name}, + }, + Template: corev1.PodTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: map[string]string{"name": name}, + }, + Spec: *podSpec, + }, + MinReadySeconds: 5, + }, + } +} diff --git a/test/e2e/utils/pod/pod.go b/test/e2e/utils/pod/pod.go index 2751fa93f..75d39aeaa 100644 --- a/test/e2e/utils/pod/pod.go +++ b/test/e2e/utils/pod/pod.go @@ -24,7 +24,6 @@ import ( "github.com/onsi/ginkgo/v2" - appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -179,16 +178,6 @@ func NFDWorker(opts ...SpecOption) *corev1.Pod { return p } -// NFDWorkerDaemonSet provides the NFD daemon set worker definition -func NFDWorkerDaemonSet(opts ...SpecOption) *appsv1.DaemonSet { - return newDaemonSet("nfd-worker", nfdWorkerSpec(opts...)) -} - -// NFDTopologyUpdaterDaemonSet provides the NFD daemon set topology updater -func NFDTopologyUpdaterDaemonSet(kc utils.KubeletConfig, opts ...SpecOption) *appsv1.DaemonSet { - return newDaemonSet("nfd-topology-updater", nfdTopologyUpdaterSpec(kc, opts...)) -} - // SpecWithContainerImage returns a SpecOption that sets the image used by the first container. func SpecWithContainerImage(image string) SpecOption { return func(spec *corev1.PodSpec) { @@ -246,27 +235,6 @@ func SpecWithConfigMap(name, mountPath string) SpecOption { } } -// newDaemonSet provide the new daemon set -func newDaemonSet(name string, podSpec *corev1.PodSpec) *appsv1.DaemonSet { - return &appsv1.DaemonSet{ - ObjectMeta: metav1.ObjectMeta{ - Name: name + "-" + string(uuid.NewUUID()), - }, - Spec: appsv1.DaemonSetSpec{ - Selector: &metav1.LabelSelector{ - MatchLabels: map[string]string{"name": name}, - }, - Template: corev1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{"name": name}, - }, - Spec: *podSpec, - }, - MinReadySeconds: 5, - }, - } -} - func nfdWorkerSpec(opts ...SpecOption) *corev1.PodSpec { yes := true no := false @@ -382,7 +350,7 @@ func nfdWorkerSpec(opts ...SpecOption) *corev1.PodSpec { return p } -func nfdTopologyUpdaterSpec(kc utils.KubeletConfig, opts ...SpecOption) *corev1.PodSpec { +func NFDTopologyUpdaterSpec(kc utils.KubeletConfig, opts ...SpecOption) *corev1.PodSpec { p := &corev1.PodSpec{ Containers: []corev1.Container{ {