Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use APITimeout and RetryInterval constant in tests #600

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is odd that we need it. probably related to where this test is executed.

i mean we just spin up apiserver +etcd with envtest then a simple reconcile

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, that's something we have to fix in the future in a sepatare PR

})
})
})
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
Loading