diff --git a/api/v2/checluster_types.go b/api/v2/checluster_types.go index fc3d4bf8d4..a9c0083605 100644 --- a/api/v2/checluster_types.go +++ b/api/v2/checluster_types.go @@ -189,6 +189,9 @@ type CheClusterDevEnvironments struct { // +optional // +kubebuilder:validation:Enum=Always;IfNotPresent;Never ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` + // WorkspacesPodAnnotations defines additional annotations for workspace pods. + // +optional + WorkspacesPodAnnotations map[string]string `json:"workspacesPodAnnotations,omitempty"` } // Che components configuration. diff --git a/api/v2/zz_generated.deepcopy.go b/api/v2/zz_generated.deepcopy.go index 0c55c3010e..63c613e5e4 100644 --- a/api/v2/zz_generated.deepcopy.go +++ b/api/v2/zz_generated.deepcopy.go @@ -302,6 +302,13 @@ func (in *CheClusterDevEnvironments) DeepCopyInto(out *CheClusterDevEnvironments *out = new(UserConfiguration) (*in).DeepCopyInto(*out) } + if in.WorkspacesPodAnnotations != nil { + in, out := &in.WorkspacesPodAnnotations, &out.WorkspacesPodAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CheClusterDevEnvironments. diff --git a/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml b/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml index cb45f3f165..7c51ff1a14 100644 --- a/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml +++ b/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml @@ -104,7 +104,7 @@ metadata: operators.operatorframework.io/project_layout: go.kubebuilder.io/v3 repository: https://github.com/eclipse-che/che-operator support: Eclipse Foundation - name: eclipse-che.v7.87.0-872.next + name: eclipse-che.v7.88.0-873.next namespace: placeholder spec: apiservicedefinitions: {} @@ -1036,7 +1036,7 @@ spec: minKubeVersion: 1.19.0 provider: name: Eclipse Foundation - version: 7.87.0-872.next + version: 7.88.0-873.next webhookdefinitions: - admissionReviewVersions: - v1 diff --git a/bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml b/bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml index 98cf1908ca..af26cebcfe 100644 --- a/bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml +++ b/bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml @@ -7790,6 +7790,12 @@ spec: type: string type: array type: object + workspacesPodAnnotations: + additionalProperties: + type: string + description: WorkspacesPodAnnotations defines additional annotations + for workspace pods. + type: object type: object gitServices: description: A configuration that allows users to work with remote diff --git a/config/crd/bases/org.eclipse.che_checlusters.yaml b/config/crd/bases/org.eclipse.che_checlusters.yaml index 37a683c808..ddab2990a0 100644 --- a/config/crd/bases/org.eclipse.che_checlusters.yaml +++ b/config/crd/bases/org.eclipse.che_checlusters.yaml @@ -7741,6 +7741,12 @@ spec: type: string type: array type: object + workspacesPodAnnotations: + additionalProperties: + type: string + description: WorkspacesPodAnnotations defines additional annotations + for workspace pods. + type: object type: object gitServices: description: A configuration that allows users to work with remote diff --git a/deploy/deployment/kubernetes/combined.yaml b/deploy/deployment/kubernetes/combined.yaml index c58a11aaef..4e32ca2125 100644 --- a/deploy/deployment/kubernetes/combined.yaml +++ b/deploy/deployment/kubernetes/combined.yaml @@ -7762,6 +7762,12 @@ spec: type: string type: array type: object + workspacesPodAnnotations: + additionalProperties: + type: string + description: WorkspacesPodAnnotations defines additional annotations + for workspace pods. + type: object type: object gitServices: description: A configuration that allows users to work with remote diff --git a/deploy/deployment/kubernetes/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml b/deploy/deployment/kubernetes/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml index cec9a14d63..b2706cb2b3 100644 --- a/deploy/deployment/kubernetes/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml +++ b/deploy/deployment/kubernetes/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml @@ -7757,6 +7757,12 @@ spec: type: string type: array type: object + workspacesPodAnnotations: + additionalProperties: + type: string + description: WorkspacesPodAnnotations defines additional annotations + for workspace pods. + type: object type: object gitServices: description: A configuration that allows users to work with remote diff --git a/deploy/deployment/openshift/combined.yaml b/deploy/deployment/openshift/combined.yaml index 864912dfd0..a115b46c25 100644 --- a/deploy/deployment/openshift/combined.yaml +++ b/deploy/deployment/openshift/combined.yaml @@ -7762,6 +7762,12 @@ spec: type: string type: array type: object + workspacesPodAnnotations: + additionalProperties: + type: string + description: WorkspacesPodAnnotations defines additional annotations + for workspace pods. + type: object type: object gitServices: description: A configuration that allows users to work with remote diff --git a/deploy/deployment/openshift/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml b/deploy/deployment/openshift/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml index 635fd14d7c..b77bd53046 100644 --- a/deploy/deployment/openshift/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml +++ b/deploy/deployment/openshift/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml @@ -7757,6 +7757,12 @@ spec: type: string type: array type: object + workspacesPodAnnotations: + additionalProperties: + type: string + description: WorkspacesPodAnnotations defines additional annotations + for workspace pods. + type: object type: object gitServices: description: A configuration that allows users to work with remote diff --git a/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml b/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml index cec9a14d63..b2706cb2b3 100644 --- a/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml +++ b/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml @@ -7757,6 +7757,12 @@ spec: type: string type: array type: object + workspacesPodAnnotations: + additionalProperties: + type: string + description: WorkspacesPodAnnotations defines additional annotations + for workspace pods. + type: object type: object gitServices: description: A configuration that allows users to work with remote diff --git a/pkg/deploy/dev-workspace-config/dev_workspace_config.go b/pkg/deploy/dev-workspace-config/dev_workspace_config.go index 1c85777590..59ed273c90 100644 --- a/pkg/deploy/dev-workspace-config/dev_workspace_config.go +++ b/pkg/deploy/dev-workspace-config/dev_workspace_config.go @@ -105,6 +105,8 @@ func updateWorkspaceConfig(ctx *chetypes.DeployContext, operatorConfig *controll updateWorkspaceImagePullPolicy(devEnvironments.ImagePullPolicy, operatorConfig.Workspace) + updateAnnotations(devEnvironments.WorkspacesPodAnnotations, operatorConfig.Workspace) + // If the CheCluster has a configured proxy, or if the Che Operator has detected a proxy configuration, // we need to disable automatic proxy handling in the DevWorkspace Operator as its implementation collides // with ours -- they set environment variables the deployment spec explicitly, which overrides the proxy-settings @@ -194,6 +196,10 @@ func updateWorkspaceImagePullPolicy(imagePullPolicy corev1.PullPolicy, workspace workspaceConfig.ImagePullPolicy = string(imagePullPolicy) } +func updateAnnotations(annotations map[string]string, workspaceConfig *controllerv1alpha1.WorkspaceConfig) { + workspaceConfig.PodAnnotations = annotations +} + func updateWorkspaceServiceAccountConfig(devEnvironments *chev2.CheClusterDevEnvironments, workspaceConfig *controllerv1alpha1.WorkspaceConfig) { isNamespaceAutoProvisioned := pointer.BoolDeref(devEnvironments.DefaultNamespace.AutoProvision, constants.DefaultAutoProvision) diff --git a/pkg/deploy/dev-workspace-config/dev_workspace_config_test.go b/pkg/deploy/dev-workspace-config/dev_workspace_config_test.go index 9b81276777..0a8e4b5896 100644 --- a/pkg/deploy/dev-workspace-config/dev_workspace_config_test.go +++ b/pkg/deploy/dev-workspace-config/dev_workspace_config_test.go @@ -2266,3 +2266,95 @@ func TestReconcileDevWorkspaceImagePullPolicy(t *testing.T) { }) } } + +func TestReconcileDevWorkspaceAnnotations(t *testing.T) { + type testCase struct { + name string + cheCluster *chev2.CheCluster + existedObjects []runtime.Object + expectedOperatorConfig *controllerv1alpha1.OperatorConfiguration + } + + var testCases = []testCase{ + { + name: "Set specific annotations", + cheCluster: &chev2.CheCluster{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "eclipse-che", + Name: "eclipse-che", + }, + Spec: chev2.CheClusterSpec{ + DevEnvironments: chev2.CheClusterDevEnvironments{ + WorkspacesPodAnnotations: map[string]string{ + "key1": "value1", + "key2": "value2", + }, + }, + }, + }, + expectedOperatorConfig: &controllerv1alpha1.OperatorConfiguration{ + Workspace: &controllerv1alpha1.WorkspaceConfig{ + PodAnnotations: map[string]string{ + "key1": "value1", + "key2": "value2", + }, + }, + }, + }, + { + name: "Remove annotations", + cheCluster: &chev2.CheCluster{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "eclipse-che", + Name: "eclipse-che", + }, + Spec: chev2.CheClusterSpec{ + DevEnvironments: chev2.CheClusterDevEnvironments{ + WorkspacesPodAnnotations: nil, + }, + }, + }, + expectedOperatorConfig: &controllerv1alpha1.OperatorConfiguration{ + Workspace: &controllerv1alpha1.WorkspaceConfig{ + PodAnnotations: nil, + }, + }, + existedObjects: []runtime.Object{ + &controllerv1alpha1.DevWorkspaceOperatorConfig{ + ObjectMeta: metav1.ObjectMeta{ + Name: devWorkspaceConfigName, + Namespace: "eclipse-che", + }, + TypeMeta: metav1.TypeMeta{ + Kind: "DevWorkspaceOperatorConfig", + APIVersion: controllerv1alpha1.GroupVersion.String(), + }, + Config: &controllerv1alpha1.OperatorConfiguration{ + Workspace: &controllerv1alpha1.WorkspaceConfig{ + PodAnnotations: map[string]string{ + "key1": "value1", + "key2": "value2", + }, + }, + }, + }, + }, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + deployContext := test.GetDeployContext(testCase.cheCluster, []runtime.Object{}) + infrastructure.InitializeForTesting(infrastructure.OpenShiftv4) + + devWorkspaceConfigReconciler := NewDevWorkspaceConfigReconciler() + _, _, err := devWorkspaceConfigReconciler.Reconcile(deployContext) + assert.NoError(t, err) + + dwoc := &controllerv1alpha1.DevWorkspaceOperatorConfig{} + err = deployContext.ClusterAPI.Client.Get(context.TODO(), types.NamespacedName{Name: devWorkspaceConfigName, Namespace: testCase.cheCluster.Namespace}, dwoc) + assert.NoError(t, err) + assert.Equal(t, testCase.expectedOperatorConfig.Workspace.PodAnnotations, dwoc.Config.Workspace.PodAnnotations) + }) + } +}