From e76ef770a58be403846cc7f29be3ceb035734d47 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Thu, 14 Jan 2021 18:36:06 +0100 Subject: [PATCH 1/3] Add support for configuring the workspace routing controllers through annotations on DevWorkspace. --- controllers/workspace/provision/routing.go | 9 +++++++++ pkg/config/constants.go | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/controllers/workspace/provision/routing.go b/controllers/workspace/provision/routing.go index 9f0b62836..18f2f961c 100644 --- a/controllers/workspace/provision/routing.go +++ b/controllers/workspace/provision/routing.go @@ -15,6 +15,7 @@ package provision import ( "context" "fmt" + "strings" devworkspace "github.com/devfile/api/pkg/apis/workspaces/v1alpha2" "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1" @@ -147,6 +148,14 @@ func getSpecRouting( annotations[config.WorkspaceRestrictedAccessAnnotation] = val } + // copy the annotations for the specific routingClass from the workspace object to the routing + expectedAnnotationPrefix := workspace.Spec.RoutingClass + config.RoutingClassAnnotationInfix + for k, v := range workspace.GetAnnotations() { + if strings.Index(k, expectedAnnotationPrefix) == 0 { + annotations[k] = v + } + } + routing := &v1alpha1.WorkspaceRouting{ ObjectMeta: metav1.ObjectMeta{ Name: fmt.Sprintf("routing-%s", workspace.Status.WorkspaceId), diff --git a/pkg/config/constants.go b/pkg/config/constants.go index beefa02d2..df5e7dbd9 100644 --- a/pkg/config/constants.go +++ b/pkg/config/constants.go @@ -70,6 +70,10 @@ const ( // PVCCleanupPodMemoryLimit is the memory limit used for PVC clean up pods PVCCleanupPodMemoryLimit = "32Mi" + + // RoutingClassAnnotationInfix is the infix of the annotations of DevWorkspace that are passed down as annotation to the WorkspaceRouting objects. + // The full annotation name is supposed to be ".routingclass.controller.devfile.io/" + RoutingClassAnnotationInfix = ".routingclass.controller.devfile.io/" ) // Constants for che-rest-apis From 50832d14d783df12a1b7d1b4f5f066210f09fc39 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Fri, 15 Jan 2021 11:52:37 +0100 Subject: [PATCH 2/3] Use strings.HasPrefix instead of strings.Index() == 0. --- controllers/workspace/provision/routing.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/workspace/provision/routing.go b/controllers/workspace/provision/routing.go index 18f2f961c..9d6ce0798 100644 --- a/controllers/workspace/provision/routing.go +++ b/controllers/workspace/provision/routing.go @@ -151,7 +151,7 @@ func getSpecRouting( // copy the annotations for the specific routingClass from the workspace object to the routing expectedAnnotationPrefix := workspace.Spec.RoutingClass + config.RoutingClassAnnotationInfix for k, v := range workspace.GetAnnotations() { - if strings.Index(k, expectedAnnotationPrefix) == 0 { + if strings.HasPrefix(k, expectedAnnotationPrefix) { annotations[k] = v } } From 4be61ec632499f505f2a8d7a14888e2d74ae3f55 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Fri, 15 Jan 2021 11:54:03 +0100 Subject: [PATCH 3/3] Simplify the infix of the routing controller config annotations. --- controllers/workspace/provision/routing.go | 2 +- pkg/config/constants.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/workspace/provision/routing.go b/controllers/workspace/provision/routing.go index 9d6ce0798..3483d79e0 100644 --- a/controllers/workspace/provision/routing.go +++ b/controllers/workspace/provision/routing.go @@ -149,7 +149,7 @@ func getSpecRouting( } // copy the annotations for the specific routingClass from the workspace object to the routing - expectedAnnotationPrefix := workspace.Spec.RoutingClass + config.RoutingClassAnnotationInfix + expectedAnnotationPrefix := workspace.Spec.RoutingClass + config.RoutingAnnotationInfix for k, v := range workspace.GetAnnotations() { if strings.HasPrefix(k, expectedAnnotationPrefix) { annotations[k] = v diff --git a/pkg/config/constants.go b/pkg/config/constants.go index df5e7dbd9..5f8ac3a5e 100644 --- a/pkg/config/constants.go +++ b/pkg/config/constants.go @@ -71,9 +71,9 @@ const ( // PVCCleanupPodMemoryLimit is the memory limit used for PVC clean up pods PVCCleanupPodMemoryLimit = "32Mi" - // RoutingClassAnnotationInfix is the infix of the annotations of DevWorkspace that are passed down as annotation to the WorkspaceRouting objects. - // The full annotation name is supposed to be ".routingclass.controller.devfile.io/" - RoutingClassAnnotationInfix = ".routingclass.controller.devfile.io/" + // RoutingAnnotationInfix is the infix of the annotations of DevWorkspace that are passed down as annotation to the WorkspaceRouting objects. + // The full annotation name is supposed to be ".routing.controller.devfile.io/" + RoutingAnnotationInfix = ".routing.controller.devfile.io/" ) // Constants for che-rest-apis