Skip to content

Commit

Permalink
Merge pull request #600 from e0ne/api-timeout
Browse files Browse the repository at this point in the history
Use APITimeout and RetryInterval constant in tests
  • Loading branch information
zeeke authored Jan 31, 2024
2 parents 54b342c + 4d080de commit 8b36f09
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
3 changes: 2 additions & 1 deletion controllers/sriovnetworkpoolconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -65,7 +66,7 @@ var _ = Describe("Operator", func() {
return err
}
return nil
}, timeout*3, interval).Should(Succeed())
}, util.APITimeout*3, util.RetryInterval).Should(Succeed())
})
})
})
44 changes: 22 additions & 22 deletions controllers/sriovoperatorconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }(),
Expand All @@ -70,19 +70,19 @@ 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())
})

DescribeTable("should have daemonset enabled by default",
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"),
Expand All @@ -93,86 +93,86 @@ 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
err = k8sClient.Update(goctx.TODO(), config)
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
err = k8sClient.Update(goctx.TODO(), config)
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())
})

It("should be able to turn operator-webhook on/off", 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
err = k8sClient.Update(goctx.TODO(), config)
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
err = k8sClient.Update(goctx.TODO(), config)
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)
Expand All @@ -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)
Expand All @@ -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))
})

})
Expand Down
10 changes: 3 additions & 7 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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())
}
})

Expand Down

0 comments on commit 8b36f09

Please sign in to comment.