diff --git a/api/v2/checluster_types.go b/api/v2/checluster_types.go index 149f6208b..b7fabc245 100644 --- a/api/v2/checluster_types.go +++ b/api/v2/checluster_types.go @@ -185,6 +185,10 @@ type CheClusterDevEnvironments struct { // User configuration. // +optional User *UserConfiguration `json:"user,omitempty"` + // ImagePullPolicy defines the imagePullPolicy used for containers in a DevWorkspace. + // +optional + // +kubebuilder:validation:Enum=Always;IfNotPresent;Never + ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` } // Che components configuration. diff --git a/build/scripts/minikube-tests/test-helm.sh b/build/scripts/minikube-tests/test-helm.sh index f1fd9bf36..eebbef5fa 100755 --- a/build/scripts/minikube-tests/test-helm.sh +++ b/build/scripts/minikube-tests/test-helm.sh @@ -84,6 +84,9 @@ runTest() { make wait-devworkspace-running NAMESPACE="devworkspace-controller" popd + # Free up some cpu resources + kubectl scale deployment che --replicas=0 -n eclipse-che + createDevWorkspace startAndWaitDevWorkspace stopAndWaitDevWorkspace diff --git a/build/scripts/minikube-tests/test-operator.sh b/build/scripts/minikube-tests/test-operator.sh index 73b682ffd..0e6024756 100755 --- a/build/scripts/minikube-tests/test-operator.sh +++ b/build/scripts/minikube-tests/test-operator.sh @@ -40,6 +40,9 @@ runTest() { make wait-devworkspace-running NAMESPACE="devworkspace-controller" VERBOSE=1 + # Free up some cpu resources + kubectl scale deployment che --replicas=0 -n eclipse-che + createDevWorkspace startAndWaitDevWorkspace stopAndWaitDevWorkspace diff --git a/build/scripts/minikube-tests/test-upgrade-from-stable-to-next.sh b/build/scripts/minikube-tests/test-upgrade-from-stable-to-next.sh index eb90ef5c6..9c4b25eea 100755 --- a/build/scripts/minikube-tests/test-upgrade-from-stable-to-next.sh +++ b/build/scripts/minikube-tests/test-upgrade-from-stable-to-next.sh @@ -59,6 +59,9 @@ runTest() { minikube image rm quay.io/eclipse/che-server:${LAST_PACKAGE_VERSION} minikube image rm quay.io/eclipse/che-operator:${LAST_PACKAGE_VERSION} + # Free up some cpu resources + kubectl scale deployment che --replicas=0 -n eclipse-che + startAndWaitDevWorkspace stopAndWaitDevWorkspace deleteDevWorkspace diff --git a/build/scripts/minikube-tests/test-upgrade-from-stable-to-stable.sh b/build/scripts/minikube-tests/test-upgrade-from-stable-to-stable.sh index 668baffeb..e571368c8 100755 --- a/build/scripts/minikube-tests/test-upgrade-from-stable-to-stable.sh +++ b/build/scripts/minikube-tests/test-upgrade-from-stable-to-stable.sh @@ -54,6 +54,9 @@ runTest() { minikube image rm quay.io/eclipse/che-server:${PREVIOUS_PACKAGE_VERSION} minikube image rm quay.io/eclipse/che-operator:${PREVIOUS_PACKAGE_VERSION} + # Free up some cpu resources + kubectl scale deployment che --replicas=0 -n eclipse-che + startAndWaitDevWorkspace stopAndWaitDevWorkspace deleteDevWorkspace diff --git a/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml b/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml index 266974205..491967ad7 100644 --- a/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml +++ b/bundle/next/eclipse-che/manifests/che-operator.clusterserviceversion.yaml @@ -77,7 +77,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.72.0-806.next + name: eclipse-che.v7.73.0-808.next namespace: placeholder spec: apiservicedefinitions: {} @@ -1234,7 +1234,7 @@ spec: minKubeVersion: 1.19.0 provider: name: Eclipse Foundation - version: 7.72.0-806.next + version: 7.73.0-808.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 e6f233ee5..3de02f1ff 100644 --- a/bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml +++ b/bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml @@ -6995,6 +6995,14 @@ spec: type: object type: object type: object + imagePullPolicy: + description: ImagePullPolicy defines the imagePullPolicy used + for containers in a DevWorkspace. + enum: + - Always + - IfNotPresent + - Never + type: string maxNumberOfRunningWorkspacesPerUser: description: The maximum number of running workspaces per user. The value, -1, allows users to run an unlimited number of diff --git a/config/crd/bases/org.eclipse.che_checlusters.yaml b/config/crd/bases/org.eclipse.che_checlusters.yaml index c6dc5b206..de8bcde8e 100644 --- a/config/crd/bases/org.eclipse.che_checlusters.yaml +++ b/config/crd/bases/org.eclipse.che_checlusters.yaml @@ -6799,6 +6799,14 @@ spec: type: object type: object type: object + imagePullPolicy: + description: ImagePullPolicy defines the imagePullPolicy used + for containers in a DevWorkspace. + enum: + - Always + - IfNotPresent + - Never + type: string maxNumberOfRunningWorkspacesPerUser: description: The maximum number of running workspaces per user. The value, -1, allows users to run an unlimited number of workspaces. diff --git a/deploy/deployment/kubernetes/combined.yaml b/deploy/deployment/kubernetes/combined.yaml index 4ed9ea9f0..2b1cba23b 100644 --- a/deploy/deployment/kubernetes/combined.yaml +++ b/deploy/deployment/kubernetes/combined.yaml @@ -6818,6 +6818,14 @@ spec: type: object type: object type: object + imagePullPolicy: + description: ImagePullPolicy defines the imagePullPolicy used + for containers in a DevWorkspace. + enum: + - Always + - IfNotPresent + - Never + type: string maxNumberOfRunningWorkspacesPerUser: description: The maximum number of running workspaces per user. The value, -1, allows users to run an unlimited number of workspaces. 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 d29a3c5da..b9d368dbe 100644 --- a/deploy/deployment/kubernetes/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml +++ b/deploy/deployment/kubernetes/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml @@ -6813,6 +6813,14 @@ spec: type: object type: object type: object + imagePullPolicy: + description: ImagePullPolicy defines the imagePullPolicy used + for containers in a DevWorkspace. + enum: + - Always + - IfNotPresent + - Never + type: string maxNumberOfRunningWorkspacesPerUser: description: The maximum number of running workspaces per user. The value, -1, allows users to run an unlimited number of workspaces. diff --git a/deploy/deployment/openshift/combined.yaml b/deploy/deployment/openshift/combined.yaml index 562172381..32657b6c2 100644 --- a/deploy/deployment/openshift/combined.yaml +++ b/deploy/deployment/openshift/combined.yaml @@ -6818,6 +6818,14 @@ spec: type: object type: object type: object + imagePullPolicy: + description: ImagePullPolicy defines the imagePullPolicy used + for containers in a DevWorkspace. + enum: + - Always + - IfNotPresent + - Never + type: string maxNumberOfRunningWorkspacesPerUser: description: The maximum number of running workspaces per user. The value, -1, allows users to run an unlimited number of workspaces. 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 d9d644510..001b92704 100644 --- a/deploy/deployment/openshift/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml +++ b/deploy/deployment/openshift/objects/checlusters.org.eclipse.che.CustomResourceDefinition.yaml @@ -6813,6 +6813,14 @@ spec: type: object type: object type: object + imagePullPolicy: + description: ImagePullPolicy defines the imagePullPolicy used + for containers in a DevWorkspace. + enum: + - Always + - IfNotPresent + - Never + type: string maxNumberOfRunningWorkspacesPerUser: description: The maximum number of running workspaces per user. The value, -1, allows users to run an unlimited number of workspaces. diff --git a/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml b/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml index d29a3c5da..b9d368dbe 100644 --- a/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml +++ b/helmcharts/next/crds/checlusters.org.eclipse.che.CustomResourceDefinition.yaml @@ -6813,6 +6813,14 @@ spec: type: object type: object type: object + imagePullPolicy: + description: ImagePullPolicy defines the imagePullPolicy used + for containers in a DevWorkspace. + enum: + - Always + - IfNotPresent + - Never + type: string maxNumberOfRunningWorkspacesPerUser: description: The maximum number of running workspaces per user. The value, -1, allows users to run an unlimited number of workspaces. diff --git a/pkg/deploy/dev-workspace-config/dev_workspace_config.go b/pkg/deploy/dev-workspace-config/dev_workspace_config.go index f060bc676..3a5c27ebb 100644 --- a/pkg/deploy/dev-workspace-config/dev_workspace_config.go +++ b/pkg/deploy/dev-workspace-config/dev_workspace_config.go @@ -102,6 +102,8 @@ func updateWorkspaceConfig(cheCluster *chev2.CheCluster, operatorConfig *control updatePersistUserHomeConfig(devEnvironments.PersistUserHome, operatorConfig.Workspace) + updateWorkspaceImagePullPolicy(devEnvironments.ImagePullPolicy, operatorConfig.Workspace) + operatorConfig.Workspace.DeploymentStrategy = v1.DeploymentStrategyType(utils.GetValue(string(devEnvironments.DeploymentStrategy), constants.DefaultDeploymentStrategy)) return nil } @@ -176,6 +178,10 @@ func updatePersistUserHomeConfig(persistentHomeConfig *chev2.PersistentHomeConfi } } +func updateWorkspaceImagePullPolicy(imagePullPolicy corev1.PullPolicy, workspaceConfig *controllerv1alpha1.WorkspaceConfig) { + workspaceConfig.ImagePullPolicy = string(imagePullPolicy) +} + 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 54b70abc7..2a478f2cf 100644 --- a/pkg/deploy/dev-workspace-config/dev_workspace_config_test.go +++ b/pkg/deploy/dev-workspace-config/dev_workspace_config_test.go @@ -339,9 +339,6 @@ func TestReconcileDevWorkspaceConfigStorage(t *testing.T) { Routing: &controllerv1alpha1.RoutingConfig{ DefaultRoutingClass: "routing-class", }, - Workspace: &controllerv1alpha1.WorkspaceConfig{ - ImagePullPolicy: "Always", - }, }, }, }, @@ -350,7 +347,6 @@ func TestReconcileDevWorkspaceConfigStorage(t *testing.T) { DefaultRoutingClass: "routing-class", }, Workspace: &controllerv1alpha1.WorkspaceConfig{ - ImagePullPolicy: "Always", StorageClassName: pointer.String("test-storage"), DefaultStorageSize: &controllerv1alpha1.StorageSizes{ Common: &quantity15Gi, @@ -2187,3 +2183,86 @@ func TestReconcileDevWorkspacePodSecurityContext(t *testing.T) { }) } } + +func TestReconcileDevWorkspaceImagePullPolicy(t *testing.T) { + type testCase struct { + name string + cheCluster *chev2.CheCluster + existedObjects []runtime.Object + expectedOperatorConfig *controllerv1alpha1.OperatorConfiguration + } + + var testCases = []testCase{ + { + name: "Set specific pull policy", + cheCluster: &chev2.CheCluster{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "eclipse-che", + Name: "eclipse-che", + }, + Spec: chev2.CheClusterSpec{ + DevEnvironments: chev2.CheClusterDevEnvironments{ + ImagePullPolicy: corev1.PullAlways, + }, + }, + }, + expectedOperatorConfig: &controllerv1alpha1.OperatorConfiguration{ + Workspace: &controllerv1alpha1.WorkspaceConfig{ + ImagePullPolicy: string(corev1.PullAlways), + }, + }, + }, + { + name: "Clean up pull policy", + cheCluster: &chev2.CheCluster{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: "eclipse-che", + Name: "eclipse-che", + }, + Spec: chev2.CheClusterSpec{ + DevEnvironments: chev2.CheClusterDevEnvironments{ + ImagePullPolicy: "", + }, + }, + }, + expectedOperatorConfig: &controllerv1alpha1.OperatorConfiguration{ + Workspace: &controllerv1alpha1.WorkspaceConfig{ + ImagePullPolicy: "", + }, + }, + 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{ + ImagePullPolicy: string(corev1.PullAlways), + }, + }, + }, + }, + }, + } + + 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.ImagePullPolicy, dwoc.Config.Workspace.ImagePullPolicy) + }) + } +}