feat: Allow to configure ImagePullPolicyt for a user workspace (#1747)
* fear: Allow to configure ImagePullPolicy for a user workspace Signed-off-by: Anatolii Bazko <abazko@redhat.com>pull/1749/head
parent
65199e6815
commit
6cf8df2b86
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue