Skip to content

Commit

Permalink
feat: implement devEnvironments.runtimeClassName field
Browse files Browse the repository at this point in the history
Signed-off-by: admin <dakwon@redhat.com>
  • Loading branch information
dkwon17 committed Sep 19, 2024
1 parent c022714 commit 4bacfff
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 0 deletions.
3 changes: 3 additions & 0 deletions api/v2/checluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ type CheClusterDevEnvironments struct {
// If not specified, the pod scheduler is set to the default scheduler on the cluster.
// +optional
PodSchedulerName string `json:"podSchedulerName,omitempty"`
// RuntimeClassName specifies the spec.runtimeClassName for workspace pods.
// +optional
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
// StartTimeoutSeconds determines the maximum duration (in seconds) that a workspace can take to start
// before it is automatically failed.
// If not specified, the default value of 300 seconds (5 minutes) is used.
Expand Down
5 changes: 5 additions & 0 deletions api/v2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7289,6 +7289,10 @@ spec:
type: object
type: object
type: object
runtimeClassName:
description: RuntimeClassName specifies the spec.runtimeClassName
for workspace pods.
type: string
secondsOfInactivityBeforeIdling:
default: 1800
description: |-
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/org.eclipse.che_checlusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7241,6 +7241,10 @@ spec:
type: object
type: object
type: object
runtimeClassName:
description: RuntimeClassName specifies the spec.runtimeClassName
for workspace pods.
type: string
secondsOfInactivityBeforeIdling:
default: 1800
description: |-
Expand Down
4 changes: 4 additions & 0 deletions deploy/deployment/kubernetes/combined.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7262,6 +7262,10 @@ spec:
type: object
type: object
type: object
runtimeClassName:
description: RuntimeClassName specifies the spec.runtimeClassName
for workspace pods.
type: string
secondsOfInactivityBeforeIdling:
default: 1800
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7257,6 +7257,10 @@ spec:
type: object
type: object
type: object
runtimeClassName:
description: RuntimeClassName specifies the spec.runtimeClassName
for workspace pods.
type: string
secondsOfInactivityBeforeIdling:
default: 1800
description: |-
Expand Down
4 changes: 4 additions & 0 deletions deploy/deployment/openshift/combined.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7262,6 +7262,10 @@ spec:
type: object
type: object
type: object
runtimeClassName:
description: RuntimeClassName specifies the spec.runtimeClassName
for workspace pods.
type: string
secondsOfInactivityBeforeIdling:
default: 1800
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7257,6 +7257,10 @@ spec:
type: object
type: object
type: object
runtimeClassName:
description: RuntimeClassName specifies the spec.runtimeClassName
for workspace pods.
type: string
secondsOfInactivityBeforeIdling:
default: 1800
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7257,6 +7257,10 @@ spec:
type: object
type: object
type: object
runtimeClassName:
description: RuntimeClassName specifies the spec.runtimeClassName
for workspace pods.
type: string
secondsOfInactivityBeforeIdling:
default: 1800
description: |-
Expand Down
6 changes: 6 additions & 0 deletions pkg/deploy/dev-workspace-config/dev_workspace_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ func updateWorkspaceConfig(ctx *chetypes.DeployContext, operatorConfig *controll

updateWorkspacePodSchedulerNameConfig(devEnvironments, operatorConfig.Workspace)

updateWorkspaceRuntimeClassNameConfig(devEnvironments, operatorConfig.Workspace)

updateProjectCloneConfig(devEnvironments, operatorConfig.Workspace)

if err := updateSecurityContext(operatorConfig, cheCluster); err != nil {
Expand Down Expand Up @@ -222,6 +224,10 @@ func updateWorkspacePodSchedulerNameConfig(devEnvironments *chev2.CheClusterDevE
workspaceConfig.SchedulerName = devEnvironments.PodSchedulerName
}

func updateWorkspaceRuntimeClassNameConfig(devEnvironments *chev2.CheClusterDevEnvironments, workspaceConfig *controllerv1alpha1.WorkspaceConfig) {
workspaceConfig.RuntimeClassName = devEnvironments.RuntimeClassName
}

func updateProjectCloneConfig(devEnvironments *chev2.CheClusterDevEnvironments, workspaceConfig *controllerv1alpha1.WorkspaceConfig) {
if devEnvironments.ProjectCloneContainer == nil {
workspaceConfig.ProjectCloneConfig = nil
Expand Down
148 changes: 148 additions & 0 deletions pkg/deploy/dev-workspace-config/dev_workspace_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,154 @@ func TestReconcileDevWorkspaceConfigPodSchedulerName(t *testing.T) {
}
}

func TestReconcileDevWorkspaceConfigRuntimeClassName(t *testing.T) {
type testCase struct {
name string
cheCluster *chev2.CheCluster
existedObjects []runtime.Object
expectedOperatorConfig *controllerv1alpha1.OperatorConfiguration
}

var testCases = []testCase{
{
name: "Create DevWorkspaceOperatorConfig with RuntimeClassName",
cheCluster: &chev2.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: "eclipse-che",
Name: "eclipse-che",
},
Spec: chev2.CheClusterSpec{
DevEnvironments: chev2.CheClusterDevEnvironments{
RuntimeClassName: pointer.StringPtr("test-runtime-class"),
},
},
},
expectedOperatorConfig: &controllerv1alpha1.OperatorConfiguration{
Workspace: &controllerv1alpha1.WorkspaceConfig{
RuntimeClassName: pointer.StringPtr("test-runtime-class"),
},
},
},
{
name: "Update existing DevWorkspaceOperatorConfig when RuntimeClassName is added",
cheCluster: &chev2.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: "eclipse-che",
Name: "eclipse-che",
},
Spec: chev2.CheClusterSpec{
DevEnvironments: chev2.CheClusterDevEnvironments{
RuntimeClassName: pointer.StringPtr("test-runtime-class"),
},
},
},
existedObjects: []runtime.Object{
&controllerv1alpha1.DevWorkspaceOperatorConfig{
ObjectMeta: metav1.ObjectMeta{
Name: devWorkspaceConfigName,
Namespace: "eclipse-che",
},
TypeMeta: metav1.TypeMeta{
Kind: "DevWorkspaceOperatorConfig",
APIVersion: controllerv1alpha1.GroupVersion.String(),
},
},
},
expectedOperatorConfig: &controllerv1alpha1.OperatorConfiguration{
Workspace: &controllerv1alpha1.WorkspaceConfig{
RuntimeClassName: pointer.StringPtr("test-runtime-class"),
},
},
},
{
name: "Update existing DevWorkspaceOperatorConfig when RuntimeClassName is changed",
cheCluster: &chev2.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: "eclipse-che",
Name: "eclipse-che",
},
Spec: chev2.CheClusterSpec{
DevEnvironments: chev2.CheClusterDevEnvironments{
RuntimeClassName: pointer.StringPtr("test-runtime-class"),
},
},
},
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{
RuntimeClassName: pointer.StringPtr("previous-runtime-class"),
},
},
},
},
expectedOperatorConfig: &controllerv1alpha1.OperatorConfiguration{
Workspace: &controllerv1alpha1.WorkspaceConfig{
RuntimeClassName: pointer.StringPtr("test-runtime-class"),
},
},
},
{
name: "Update existing DevWorkspaceOperatorConfig when RuntimeClassName is removed",
cheCluster: &chev2.CheCluster{
ObjectMeta: metav1.ObjectMeta{
Namespace: "eclipse-che",
Name: "eclipse-che",
},
Spec: chev2.CheClusterSpec{
DevEnvironments: chev2.CheClusterDevEnvironments{
RuntimeClassName: 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{
RuntimeClassName: pointer.StringPtr("previous-runtime-class"),
},
},
},
},
expectedOperatorConfig: &controllerv1alpha1.OperatorConfiguration{
Workspace: &controllerv1alpha1.WorkspaceConfig{},
},
},
}

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.SchedulerName, dwoc.Config.Workspace.SchedulerName)
})
}
}

func TestReconcileDevWorkspaceConfigServiceAccountTokens(t *testing.T) {
type testCase struct {
name string
Expand Down

0 comments on commit 4bacfff

Please sign in to comment.