diff --git a/controllers/sriovnetworkpoolconfig_controller_test.go b/controllers/sriovnetworkpoolconfig_controller_test.go index b95f5edac..ff20c0535 100644 --- a/controllers/sriovnetworkpoolconfig_controller_test.go +++ b/controllers/sriovnetworkpoolconfig_controller_test.go @@ -16,6 +16,7 @@ import ( "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts" constants "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars" + "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util" ) var _ = Describe("Operator", func() { @@ -65,7 +66,7 @@ var _ = Describe("Operator", func() { return err } return nil - }, timeout*3, interval).Should(Succeed()) + }, util.APITimeout*3, util.RetryInterval).Should(Succeed()) }) }) }) diff --git a/controllers/sriovoperatorconfig_controller_test.go b/controllers/sriovoperatorconfig_controller_test.go index 70ec3fd07..c36b2a91f 100644 --- a/controllers/sriovoperatorconfig_controller_test.go +++ b/controllers/sriovoperatorconfig_controller_test.go @@ -56,7 +56,7 @@ var _ = Describe("Operator", func() { Context("When is up", func() { JustBeforeEach(func() { config = &sriovnetworkv1.SriovOperatorConfig{} - err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", interval, timeout) + err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) config.Spec = sriovnetworkv1.SriovOperatorConfigSpec{ EnableInjector: func() *bool { b := true; return &b }(), @@ -70,11 +70,11 @@ var _ = Describe("Operator", func() { It("should have webhook enable", func() { mutateCfg := &admv1.MutatingWebhookConfiguration{} - err := util.WaitForNamespacedObject(mutateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", interval, timeout) + err := util.WaitForNamespacedObject(mutateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) validateCfg := &admv1.ValidatingWebhookConfiguration{} - err = util.WaitForNamespacedObject(validateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", interval, timeout) + err = util.WaitForNamespacedObject(validateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) }) @@ -82,7 +82,7 @@ var _ = Describe("Operator", func() { func(dsName string) { // wait for sriov-network-operator to be ready daemonSet := &appsv1.DaemonSet{} - err := util.WaitForNamespacedObject(daemonSet, k8sClient, testNamespace, dsName, interval, timeout) + err := util.WaitForNamespacedObject(daemonSet, k8sClient, testNamespace, dsName, util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) }, Entry("operator-webhook", "operator-webhook"), @@ -93,7 +93,7 @@ var _ = Describe("Operator", func() { It("should be able to turn network-resources-injector on/off", func() { By("set disable to enableInjector") config := &sriovnetworkv1.SriovOperatorConfig{} - err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", interval, timeout) + err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) *config.Spec.EnableInjector = false @@ -101,15 +101,15 @@ var _ = Describe("Operator", func() { Expect(err).NotTo(HaveOccurred()) daemonSet := &appsv1.DaemonSet{} - err = util.WaitForNamespacedObjectDeleted(daemonSet, k8sClient, testNamespace, "network-resources-injector", interval, timeout) + err = util.WaitForNamespacedObjectDeleted(daemonSet, k8sClient, testNamespace, "network-resources-injector", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) mutateCfg := &admv1.MutatingWebhookConfiguration{} - err = util.WaitForNamespacedObjectDeleted(mutateCfg, k8sClient, testNamespace, "network-resources-injector-config", interval, timeout) + err = util.WaitForNamespacedObjectDeleted(mutateCfg, k8sClient, testNamespace, "network-resources-injector-config", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) By("set enable to enableInjector") - err = util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", interval, timeout) + err = util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) *config.Spec.EnableInjector = true @@ -117,11 +117,11 @@ var _ = Describe("Operator", func() { Expect(err).NotTo(HaveOccurred()) daemonSet = &appsv1.DaemonSet{} - err = util.WaitForNamespacedObject(daemonSet, k8sClient, testNamespace, "network-resources-injector", interval, timeout) + err = util.WaitForNamespacedObject(daemonSet, k8sClient, testNamespace, "network-resources-injector", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) mutateCfg = &admv1.MutatingWebhookConfiguration{} - err = util.WaitForNamespacedObject(mutateCfg, k8sClient, testNamespace, "network-resources-injector-config", interval, timeout) + err = util.WaitForNamespacedObject(mutateCfg, k8sClient, testNamespace, "network-resources-injector-config", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) }) @@ -129,7 +129,7 @@ var _ = Describe("Operator", func() { By("set disable to enableOperatorWebhook") config := &sriovnetworkv1.SriovOperatorConfig{} - err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", interval, timeout) + err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) *config.Spec.EnableOperatorWebhook = false @@ -137,19 +137,19 @@ var _ = Describe("Operator", func() { Expect(err).NotTo(HaveOccurred()) daemonSet := &appsv1.DaemonSet{} - err = util.WaitForNamespacedObjectDeleted(daemonSet, k8sClient, testNamespace, "operator-webhook", interval, timeout) + err = util.WaitForNamespacedObjectDeleted(daemonSet, k8sClient, testNamespace, "operator-webhook", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) mutateCfg := &admv1.MutatingWebhookConfiguration{} - err = util.WaitForNamespacedObjectDeleted(mutateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", interval, timeout) + err = util.WaitForNamespacedObjectDeleted(mutateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) validateCfg := &admv1.ValidatingWebhookConfiguration{} - err = util.WaitForNamespacedObjectDeleted(validateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", interval, timeout) + err = util.WaitForNamespacedObjectDeleted(validateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) By("set disable to enableOperatorWebhook") - err = util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", interval, timeout) + err = util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) *config.Spec.EnableOperatorWebhook = true @@ -157,22 +157,22 @@ var _ = Describe("Operator", func() { Expect(err).NotTo(HaveOccurred()) daemonSet = &appsv1.DaemonSet{} - err = util.WaitForNamespacedObject(daemonSet, k8sClient, testNamespace, "operator-webhook", interval, timeout) + err = util.WaitForNamespacedObject(daemonSet, k8sClient, testNamespace, "operator-webhook", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) mutateCfg = &admv1.MutatingWebhookConfiguration{} - err = util.WaitForNamespacedObject(mutateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", interval, timeout) + err = util.WaitForNamespacedObject(mutateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) validateCfg = &admv1.ValidatingWebhookConfiguration{} - err = util.WaitForNamespacedObject(validateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", interval, timeout) + err = util.WaitForNamespacedObject(validateCfg, k8sClient, testNamespace, "sriov-operator-webhook-config", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) }) It("should be able to update the node selector of sriov-network-config-daemon", func() { By("specify the configDaemonNodeSelector") config := &sriovnetworkv1.SriovOperatorConfig{} - err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", interval, timeout) + err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) config.Spec.ConfigDaemonNodeSelector = map[string]string{"node-role.kubernetes.io/worker": ""} err = k8sClient.Update(goctx.TODO(), config) @@ -186,13 +186,13 @@ var _ = Describe("Operator", func() { return nil } return daemonSet.Spec.Template.Spec.NodeSelector - }, timeout*10, interval).Should(Equal(config.Spec.ConfigDaemonNodeSelector)) + }, util.APITimeout*10, util.RetryInterval).Should(Equal(config.Spec.ConfigDaemonNodeSelector)) }) It("should be able to do multiple updates to the node selector of sriov-network-config-daemon", func() { By("changing the configDaemonNodeSelector") config := &sriovnetworkv1.SriovOperatorConfig{} - err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", interval, timeout) + err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout) Expect(err).NotTo(HaveOccurred()) config.Spec.ConfigDaemonNodeSelector = map[string]string{"labelA": "", "labelB": "", "labelC": ""} err = k8sClient.Update(goctx.TODO(), config) @@ -208,7 +208,7 @@ var _ = Describe("Operator", func() { return nil } return daemonSet.Spec.Template.Spec.NodeSelector - }, timeout*10, interval).Should(Equal(config.Spec.ConfigDaemonNodeSelector)) + }, util.APITimeout*10, util.RetryInterval).Should(Equal(config.Spec.ConfigDaemonNodeSelector)) }) }) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 6a9b1af5d..07bc9a7c1 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -46,6 +46,7 @@ import ( constants "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts" mock_platforms "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms/mock" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms/openshift" + "github.com/k8snetworkplumbingwg/sriov-network-operator/test/util" ) // These tests use Ginkgo (BDD-style Go testing framework). Refer to @@ -60,12 +61,7 @@ var ( ) // Define utility constants for object names and testing timeouts/durations and intervals. -const ( - testNamespace = "openshift-sriov-network-operator" - - timeout = time.Second * 10 - interval = time.Millisecond * 250 -) +const testNamespace = "openshift-sriov-network-operator" var _ = BeforeSuite(func() { logf.SetLogger(zap.New( @@ -221,7 +217,7 @@ var _ = AfterSuite(func() { if testEnv != nil { Eventually(func() error { return testEnv.Stop() - }, timeout, time.Second).ShouldNot(HaveOccurred()) + }, util.APITimeout, time.Second).ShouldNot(HaveOccurred()) } })