@@ -35,7 +35,6 @@ import (
3535 rbacv1 "k8s.io/api/rbac/v1"
3636 k8sErrors "k8s.io/apimachinery/pkg/api/errors"
3737 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
38- "k8s.io/apimachinery/pkg/types"
3938 "sigs.k8s.io/controller-runtime/pkg/client"
4039 "sigs.k8s.io/yaml"
4140)
@@ -66,10 +65,7 @@ var _ = Describe("DevWorkspace Controller", func() {
6665
6766 By ("Creating a new DevWorkspace" )
6867 Expect (k8sClient .Create (ctx , devworkspace )).Should (Succeed ())
69- dwNamespacedName := types.NamespacedName {
70- Namespace : testNamespace ,
71- Name : devWorkspaceName ,
72- }
68+ dwNamespacedName := namespacedName (devWorkspaceName , testNamespace )
7369 defer deleteDevWorkspace (devWorkspaceName )
7470
7571 createdDW := & dw.DevWorkspace {}
@@ -112,10 +108,7 @@ var _ = Describe("DevWorkspace Controller", func() {
112108
113109 By ("Creating a new DevWorkspace" )
114110 Expect (k8sClient .Create (ctx , devworkspace )).Should (Succeed ())
115- dwNamespacedName := types.NamespacedName {
116- Namespace : testNamespace ,
117- Name : devWorkspaceName ,
118- }
111+ dwNamespacedName := namespacedName (devWorkspaceName , testNamespace )
119112 defer deleteDevWorkspace (devWorkspaceName )
120113
121114 createdDW := & dw.DevWorkspace {}
@@ -150,10 +143,7 @@ var _ = Describe("DevWorkspace Controller", func() {
150143
151144 By ("Creating a new DevWorkspace" )
152145 Expect (k8sClient .Create (ctx , devworkspace )).Should (Succeed ())
153- dwNamespacedName := types.NamespacedName {
154- Namespace : testNamespace ,
155- Name : devWorkspaceName ,
156- }
146+ dwNamespacedName := namespacedName (devWorkspaceName , testNamespace )
157147 defer deleteDevWorkspace (devWorkspaceName )
158148
159149 createdDW := & dw.DevWorkspace {}
@@ -169,10 +159,7 @@ var _ = Describe("DevWorkspace Controller", func() {
169159 By ("Checking that duplicate DevWorkspace enters failed Phase" )
170160 createdDW2 := & dw.DevWorkspace {}
171161 Eventually (func () (phase dw.DevWorkspacePhase , err error ) {
172- if err := k8sClient .Get (ctx , types.NamespacedName {
173- Name : devworkspace2 .Name ,
174- Namespace : testNamespace ,
175- }, createdDW2 ); err != nil {
162+ if err := k8sClient .Get (ctx , namespacedName (devworkspace2 .Name , testNamespace ), createdDW2 ); err != nil {
176163 return "" , err
177164 }
178165 return createdDW2 .Status .Phase , nil
@@ -195,7 +182,7 @@ var _ = Describe("DevWorkspace Controller", func() {
195182 By ("Checking that common role is created" )
196183 dwRole := & rbacv1.Role {}
197184 Eventually (func () bool {
198- if err := k8sClient .Get (ctx , types. NamespacedName { Name : common .WorkspaceRoleName (), Namespace : testNamespace } , dwRole ); err != nil {
185+ if err := k8sClient .Get (ctx , namespacedName ( common .WorkspaceRoleName (), testNamespace ) , dwRole ); err != nil {
199186 return false
200187 }
201188 return true
@@ -204,7 +191,7 @@ var _ = Describe("DevWorkspace Controller", func() {
204191 By ("Checking that common rolebinding is created" )
205192 dwRoleBinding := & rbacv1.RoleBinding {}
206193 Eventually (func () bool {
207- if err := k8sClient .Get (ctx , types. NamespacedName { Name : common .WorkspaceRolebindingName (), Namespace : testNamespace } , dwRoleBinding ); err != nil {
194+ if err := k8sClient .Get (ctx , namespacedName ( common .WorkspaceRolebindingName (), testNamespace ) , dwRoleBinding ); err != nil {
208195 return false
209196 }
210197 return true
@@ -226,7 +213,7 @@ var _ = Describe("DevWorkspace Controller", func() {
226213 dwr := & controllerv1alpha1.DevWorkspaceRouting {}
227214 dwrName := common .DevWorkspaceRoutingName (workspaceID )
228215 Eventually (func () error {
229- return k8sClient .Get (ctx , types. NamespacedName { Name : dwrName , Namespace : testNamespace } , dwr )
216+ return k8sClient .Get (ctx , namespacedName ( dwrName , testNamespace ) , dwr )
230217 }, timeout , interval ).Should (Succeed (), "DevWorkspaceRouting is present on cluster" )
231218
232219 Expect (string (dwr .Spec .RoutingClass )).Should (Equal (devworkspace .Spec .RoutingClass ), "RoutingClass should be propagated to DevWorkspaceRouting" )
@@ -243,7 +230,7 @@ var _ = Describe("DevWorkspace Controller", func() {
243230 markRoutingReady ("test-url" , common .DevWorkspaceRoutingName (workspaceID ))
244231
245232 Eventually (func () (string , error ) {
246- if err := k8sClient .Get (ctx , types. NamespacedName { Name : devWorkspaceName , Namespace : testNamespace } , devworkspace ); err != nil {
233+ if err := k8sClient .Get (ctx , namespacedName ( devWorkspaceName , testNamespace ) , devworkspace ); err != nil {
247234 return "" , err
248235 }
249236 return devworkspace .Status .MainUrl , nil
@@ -260,10 +247,7 @@ var _ = Describe("DevWorkspace Controller", func() {
260247
261248 metadataCM := & corev1.ConfigMap {}
262249 Eventually (func () error {
263- cmNN := types.NamespacedName {
264- Name : common .MetadataConfigMapName (workspaceID ),
265- Namespace : testNamespace ,
266- }
250+ cmNN := namespacedName (common .MetadataConfigMapName (workspaceID ), testNamespace )
267251 return k8sClient .Get (ctx , cmNN , metadataCM )
268252 }, timeout , interval ).Should (Succeed (), "Should create workspace metadata configmap" )
269253
@@ -290,10 +274,7 @@ var _ = Describe("DevWorkspace Controller", func() {
290274
291275 sa := & corev1.ServiceAccount {}
292276 Eventually (func () error {
293- saNN := types.NamespacedName {
294- Name : common .ServiceAccountName (workspaceID ),
295- Namespace : testNamespace ,
296- }
277+ saNN := namespacedName (common .ServiceAccountName (workspaceID ), testNamespace )
297278 return k8sClient .Get (ctx , saNN , sa )
298279 }, timeout , interval ).Should (Succeed (), "Should create DevWorkspace ServiceAccount" )
299280
@@ -312,10 +293,7 @@ var _ = Describe("DevWorkspace Controller", func() {
312293
313294 deploy := & appsv1.Deployment {}
314295 Eventually (func () error {
315- deployNN := types.NamespacedName {
316- Name : common .DeploymentName (workspaceID ),
317- Namespace : testNamespace ,
318- }
296+ deployNN := namespacedName (common .DeploymentName (workspaceID ), testNamespace )
319297 return k8sClient .Get (ctx , deployNN , deploy )
320298 }, timeout , interval ).Should (Succeed (), "Should create DevWorkspace Deployment" )
321299
@@ -346,10 +324,7 @@ var _ = Describe("DevWorkspace Controller", func() {
346324
347325 currDW := & dw.DevWorkspace {}
348326 Eventually (func () (dw.DevWorkspacePhase , error ) {
349- err := k8sClient .Get (ctx , types.NamespacedName {
350- Name : devworkspace .Name ,
351- Namespace : devworkspace .Namespace ,
352- }, currDW )
327+ err := k8sClient .Get (ctx , namespacedName (devworkspace .Name , devworkspace .Namespace ), currDW )
353328 if err != nil {
354329 return "" , err
355330 }
@@ -410,10 +385,7 @@ var _ = Describe("DevWorkspace Controller", func() {
410385 markRoutingReady (testURL , common .DevWorkspaceRoutingName (workspaceID ))
411386
412387 deploy := & appsv1.Deployment {}
413- deployNN := types.NamespacedName {
414- Name : common .DeploymentName (workspaceID ),
415- Namespace : testNamespace ,
416- }
388+ deployNN := namespacedName (common .DeploymentName (workspaceID ), testNamespace )
417389 Eventually (func () error {
418390 return k8sClient .Get (ctx , deployNN , deploy )
419391 }, timeout , interval ).Should (Succeed (), "Getting workspace deployment from cluster" )
@@ -439,10 +411,7 @@ var _ = Describe("DevWorkspace Controller", func() {
439411 markRoutingReady (testURL , common .DevWorkspaceRoutingName (workspaceID ))
440412
441413 deploy := & appsv1.Deployment {}
442- deployNN := types.NamespacedName {
443- Name : common .DeploymentName (workspaceID ),
444- Namespace : testNamespace ,
445- }
414+ deployNN := namespacedName (common .DeploymentName (workspaceID ), testNamespace )
446415 Eventually (func () error {
447416 return k8sClient .Get (ctx , deployNN , deploy )
448417 }, timeout , interval ).Should (Succeed (), "Getting workspace deployment from cluster" )
@@ -525,10 +494,7 @@ var _ = Describe("DevWorkspace Controller", func() {
525494 markRoutingReady (testURL , common .DevWorkspaceRoutingName (workspaceID ))
526495
527496 deploy := & appsv1.Deployment {}
528- deployNN := types.NamespacedName {
529- Name : common .DeploymentName (workspaceID ),
530- Namespace : testNamespace ,
531- }
497+ deployNN := namespacedName (common .DeploymentName (workspaceID ), testNamespace )
532498 Eventually (func () error {
533499 return k8sClient .Get (ctx , deployNN , deploy )
534500 }, timeout , interval ).Should (Succeed (), "Getting workspace deployment from cluster" )
@@ -572,10 +538,7 @@ var _ = Describe("DevWorkspace Controller", func() {
572538 By ("Manually making Routing ready to continue" )
573539 markRoutingReady (testURL , common .DevWorkspaceRoutingName (workspaceID ))
574540 deploy := & appsv1.Deployment {}
575- deployNN := types.NamespacedName {
576- Name : common .DeploymentName (workspaceID ),
577- Namespace : testNamespace ,
578- }
541+ deployNN := namespacedName (common .DeploymentName (workspaceID ), testNamespace )
579542 Eventually (func () error {
580543 return k8sClient .Get (ctx , deployNN , deploy )
581544 }, timeout , interval ).Should (Succeed (), "Getting workspace deployment from cluster" )
@@ -632,10 +595,7 @@ var _ = Describe("DevWorkspace Controller", func() {
632595 By ("Adds devworkspace-started annotation to false on DevWorkspaceRouting" )
633596 Eventually (func () (string , error ) {
634597 dwr := & controllerv1alpha1.DevWorkspaceRouting {}
635- if err := k8sClient .Get (ctx , types.NamespacedName {
636- Name : common .DevWorkspaceRoutingName (devworkspace .Status .DevWorkspaceId ),
637- Namespace : testNamespace ,
638- }, dwr ); err != nil {
598+ if err := k8sClient .Get (ctx , namespacedName (common .DevWorkspaceRoutingName (devworkspace .Status .DevWorkspaceId ), testNamespace ), dwr ); err != nil {
639599 return "" , err
640600 }
641601 annotation , ok := dwr .Annotations [constants .DevWorkspaceStartedStatusAnnotation ]
@@ -648,10 +608,7 @@ var _ = Describe("DevWorkspace Controller", func() {
648608 By ("Checking that workspace deployment is scaled to zero" )
649609 Eventually (func () (replicas int32 , err error ) {
650610 deploy := & appsv1.Deployment {}
651- if err := k8sClient .Get (ctx , types.NamespacedName {
652- Name : common .DeploymentName (devworkspace .Status .DevWorkspaceId ),
653- Namespace : testNamespace ,
654- }, deploy ); err != nil {
611+ if err := k8sClient .Get (ctx , namespacedName (common .DeploymentName (devworkspace .Status .DevWorkspaceId ), testNamespace ), deploy ); err != nil {
655612 return - 1 , err
656613 }
657614 return * deploy .Spec .Replicas , nil
@@ -662,10 +619,7 @@ var _ = Describe("DevWorkspace Controller", func() {
662619
663620 currDW := & dw.DevWorkspace {}
664621 Eventually (func () (dw.DevWorkspacePhase , error ) {
665- if err := k8sClient .Get (ctx , types.NamespacedName {
666- Name : devworkspace .Name ,
667- Namespace : devworkspace .Namespace ,
668- }, currDW ); err != nil {
622+ if err := k8sClient .Get (ctx , namespacedName (devworkspace .Name , devworkspace .Namespace ), currDW ); err != nil {
669623 return "" , err
670624 }
671625 GinkgoWriter .Printf ("Waiting for DevWorkspace to enter Stopped phase -- Phase: %s, Message %s\n " , currDW .Status .Phase , currDW .Status .Message )
@@ -705,10 +659,7 @@ var _ = Describe("DevWorkspace Controller", func() {
705659 }
706660 for _ , obj := range objects {
707661 Eventually (func () error {
708- err := k8sClient .Get (ctx , types.NamespacedName {
709- Name : obj .GetName (),
710- Namespace : testNamespace ,
711- }, obj )
662+ err := k8sClient .Get (ctx , namespacedName (obj .GetName (), testNamespace ), obj )
712663 switch {
713664 case err == nil :
714665 return fmt .Errorf ("Object exists" )
@@ -722,10 +673,7 @@ var _ = Describe("DevWorkspace Controller", func() {
722673
723674 currDW := & dw.DevWorkspace {}
724675 Eventually (func () (dw.DevWorkspacePhase , error ) {
725- if err := k8sClient .Get (ctx , types.NamespacedName {
726- Name : devworkspace .Name ,
727- Namespace : devworkspace .Namespace ,
728- }, currDW ); err != nil {
676+ if err := k8sClient .Get (ctx , namespacedName (devworkspace .Name , devworkspace .Namespace ), currDW ); err != nil {
729677 return "" , err
730678 }
731679 GinkgoWriter .Printf ("Waiting for DevWorkspace to enter Stopped phase -- Phase: %s, Message %s\n " , currDW .Status .Phase , currDW .Status .Message )
0 commit comments