Skip to content

Commit

Permalink
controller/test: adjust controller-test for new webhook
Browse files Browse the repository at this point in the history
Theoretically, we just setup the webhook and can use the webhook in our
controller test. Somehow related to WebhookInstallOptions it should
work. Except, I don't get it to work.

Instead, there webhook is not running in this unit test. We however have
them in the "Webhook Suite", so there are unit tests about the webhook
there.

Instead, adjust the controller test for the (lack of) webhook changes.
Note that this doesn't actually check the webhook, since it's not
running in this setup. It rather tests, that the webhook is not running.
If we ever make the webhook working for dpuoperatorconfig_controller_test
test, we will need to adjust this. That is intentional.
  • Loading branch information
thom311 committed Jan 30, 2025
1 parent d384f16 commit afae1b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions internal/controller/dpuoperatorconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (

var (
testNamespace = "openshift-dpu-operator"
testDpuOperatorConfigName = "default"
testDpuOperatorConfigName = "dpu-operator-config"
testDpuOperatorConfigKind = "DpuOperatorConfig"
testDpuDaemonName = "dpu-daemon"
testNetworkFunctionNADDpu = "dpunfcni-conf"
Expand Down Expand Up @@ -218,7 +218,7 @@ var _ = Describe("Main Controller", Ordered, func() {
Context("When DpuOperatorConfig CR exists with host mode", func() {
BeforeAll(func() {
ns := dpuOperatorNameSpace()
cr = dpuOperatorCR("operator-config", "host", ns)
cr = dpuOperatorCR(testDpuOperatorConfigName, "host", ns)
createNameSpace(mgr.GetClient(), ns)
createDpuOperatorCR(mgr.GetClient(), cr)
})
Expand All @@ -233,9 +233,21 @@ var _ = Describe("Main Controller", Ordered, func() {
return mgr.GetClient().Get(context.Background(), types.NamespacedName{Namespace: "default", Name: testNetworkFunctionNADHost}, nad)
}, testutils.TestAPITimeout*3, testutils.TestRetryInterval).ShouldNot(HaveOccurred())
})
It("only DpuOperatorConfig \"openshift-dpu-operator/dpu-operator-config\" is allowed", func() {
ns := dpuOperatorNameSpace()
client := mgr.GetClient()

cr2 := dpuOperatorCR("foo", "host", ns)
err2 := client.Create(context.Background(), cr2)
/* The validating webhook does not run in this setup. If it were, adding
* this CR would be rejected. Instead, it passes. This indicates that the
* webhook is not running. */
Expect(err2).NotTo(HaveOccurred())
deleteDpuOperatorCR(mgr.GetClient(), cr2)
})
AfterAll(func() {
ns := dpuOperatorNameSpace()
cr = dpuOperatorCR("operator-config", "host", ns)
cr = dpuOperatorCR(testDpuOperatorConfigName, "host", ns)
deleteDpuOperatorCR(mgr.GetClient(), cr)
})
})
Expand Down
2 changes: 1 addition & 1 deletion internal/testutils/kindcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

var (
testNamespace = "openshift-dpu-operator"
testDpuOperatorConfigName = "default"
testDpuOperatorConfigName = "dpu-operator-config"
testDpuOperatorConfigKind = "DpuOperatorConfig"
testDpuDaemonName = "dpu-daemon"
testClusterName = "dpu-operator-test-cluster"
Expand Down

0 comments on commit afae1b7

Please sign in to comment.