Skip to content

Commit 58cd8f0

Browse files
committed
Adds controller environment tests for pod runtimeClass
Signed-off-by: admin <[email protected]>
1 parent f8dc118 commit 58cd8f0

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

controllers/workspace/devworkspace_controller_test.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,85 @@ var _ = Describe("DevWorkspace Controller", func() {
602602
})
603603
})
604604

605+
Context("DevWorkspace deployment", func() {
606+
const testURL = "test-url"
607+
608+
BeforeEach(func() {
609+
workspacecontroller.SetupHttpClientsForTesting(&http.Client{
610+
Transport: &testutil.TestRoundTripper{
611+
Data: map[string]testutil.TestResponse{
612+
fmt.Sprintf("%s/healthz", testURL): {
613+
StatusCode: http.StatusOK,
614+
},
615+
},
616+
},
617+
})
618+
})
619+
620+
AfterEach(func() {
621+
deleteDevWorkspace(devWorkspaceName)
622+
workspacecontroller.SetupHttpClientsForTesting(getBasicTestHttpClient())
623+
})
624+
625+
It("Sets the runtimeClassName from the DWOC", func() {
626+
By("Creating DWOC with a runtimeClassName")
627+
runtimeClassName := "test-runtime-class"
628+
config.SetGlobalConfigForTesting(&controllerv1alpha1.OperatorConfiguration{
629+
Workspace: &controllerv1alpha1.WorkspaceConfig{
630+
RuntimeClassName: &runtimeClassName,
631+
},
632+
})
633+
defer config.SetGlobalConfigForTesting(nil)
634+
635+
createDevWorkspace(devWorkspaceName, "test-devworkspace.yaml")
636+
devworkspace := getExistingDevWorkspace(devWorkspaceName)
637+
workspaceID := devworkspace.Status.DevWorkspaceId
638+
639+
By("Manually making Routing ready to continue")
640+
markRoutingReady(testURL, common.DevWorkspaceRoutingName(workspaceID))
641+
642+
deploy := &appsv1.Deployment{}
643+
deployNN := namespacedName(common.DeploymentName(workspaceID), testNamespace)
644+
Eventually(func() error {
645+
return k8sClient.Get(ctx, deployNN, deploy)
646+
}, timeout, interval).Should(Succeed(), "Getting workspace deployment from cluster")
647+
Expect(*deploy.Spec.Template.Spec.RuntimeClassName).Should(Equal("test-runtime-class"))
648+
})
649+
650+
It("Sets the runtimeClassName from the attribute instead of the DWOC", func() {
651+
By("Creating DWOC with a runtimeClassName")
652+
runtimeClassName := "test-runtime-class"
653+
config.SetGlobalConfigForTesting(&controllerv1alpha1.OperatorConfiguration{
654+
Workspace: &controllerv1alpha1.WorkspaceConfig{
655+
RuntimeClassName: &runtimeClassName,
656+
},
657+
})
658+
defer config.SetGlobalConfigForTesting(nil)
659+
660+
devworkspace := &dw.DevWorkspace{}
661+
createDevWorkspace(devWorkspaceName, "test-devworkspace.yaml")
662+
663+
By("Adding runtime-class attribute to the DevWorkspace")
664+
Eventually(func() error {
665+
devworkspace = getExistingDevWorkspace(devWorkspaceName)
666+
devworkspace.Spec.Template.Attributes.PutString(constants.RuntimeClassNameAttribute, "test-runtime-class-attribute")
667+
return k8sClient.Update(ctx, devworkspace)
668+
}, timeout, interval).Should(Succeed(), "DevWorkspace should get `runtime-class: test-runtime-class-attribute` attribute")
669+
670+
workspaceID := devworkspace.Status.DevWorkspaceId
671+
672+
By("Manually making Routing ready to continue")
673+
markRoutingReady(testURL, common.DevWorkspaceRoutingName(workspaceID))
674+
675+
deploy := &appsv1.Deployment{}
676+
deployNN := namespacedName(common.DeploymentName(workspaceID), testNamespace)
677+
Eventually(func() error {
678+
return k8sClient.Get(ctx, deployNN, deploy)
679+
}, timeout, interval).Should(Succeed(), "Getting workspace deployment from cluster")
680+
Expect(*deploy.Spec.Template.Spec.RuntimeClassName).Should(Equal("test-runtime-class-attribute"))
681+
})
682+
})
683+
605684
Context("Stopping DevWorkspaces", func() {
606685
const testURL = "test-url"
607686

0 commit comments

Comments
 (0)