Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spec.devEnvironments.runtimeClassName field to CR #1899

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@
| [golang.org/x/mobile@d3739f865fa66d07c1f506505c18aac71a8ead6e](https://cs.opensource.google/go) | BSD-3-Clause | N/A |
| [github.com/devfile/api/[email protected]](https://github.com/devfile/api.git) | Apache-2.0 | [clearlydefined](https://clearlydefined.io/definitions/git/github/devfile/api/a6ec0a38307b63a29fad2eea945cc69bee97a683) |
| [github.com/che-incubator/kubernetes-image-puller-operator@0128446f5af78587c0427a35d693bbb8d24036bc](https://github.com/che-incubator/kubernetes-image-puller-operator.git) | EPL-2.0 | todo |
| [github.com/devfile/devworkspace-operator@v0.29.0](https://github.com/devfile/devworkspace-operator.git) | Apache-2.0 | [clearlydefined](https://clearlydefined.io/definitions/git/github/devfile/devworkspace-operator/629bc2658ff0f6abb6687fc054c9e547ac3e3fc3) |
| [github.com/devfile/devworkspace-operator@v0.31.0](https://github.com/devfile/devworkspace-operator.git) | Apache-2.0 | [clearlydefined](https://clearlydefined.io/definitions/git/github/devfile/devworkspace-operator/419adb5eb92b6bdcd4ab33887455c59dc790529e) |
| [github.com/gophercloud/[email protected]](https://github.com/gophercloud/gophercloud) | Apache-2.0 | [clearlydefined](https://clearlydefined.io/definitions/go/golang/github.com%2Fgophercloud/gophercloud/v0.1.0) |
| [gopkg.in/imdario/[email protected]](https://github.com/imdario/mergo/) | BSD-3-Clause | [clearlydefined](https://clearlydefined.io/definitions/go/golang/github.com%2Fimdario/mergo/v0.3.7) |
| [github.com/mikefarah/yq/[email protected]](https://github.com/mikefarah/yq) | MIT | [clearlydefined](https://clearlydefined.io/definitions/git/github/mikefarah/yq/b8b2c9de6189471c0cdbd459b5b0b49a57844bd4) |
Expand Down
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"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've set the type to *string because that is the type for RuntimeClassName in PodSpec struct:

https://github.com/kubernetes/api/blob/9dc1a952bda9aeb400aa6409b7d89eff50d6ea77/core/v1/types.go#L3920

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe PodRuntimeClassName ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO I don't know if it's necessary since we have names such as:

// The node selector limits the nodes that can run the workspace pods.
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// The pod tolerations of the workspace pods limit where the workspace pods can run.
// +optional
Tolerations []corev1.Toleration `json:"tolerations,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 @@ -7287,6 +7287,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 @@ -7239,6 +7239,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 @@ -7260,6 +7260,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 @@ -7255,6 +7255,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 @@ -7260,6 +7260,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 @@ -7255,6 +7255,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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/che-incubator/kubernetes-image-puller-operator v0.0.0-20210929175054-0128446f5af7
github.com/devfile/api/v2 v2.2.2
github.com/devfile/devworkspace-operator v0.29.0
github.com/devfile/devworkspace-operator v0.31.0
github.com/go-logr/logr v1.2.4
github.com/google/go-cmp v0.6.0
github.com/openshift/api v0.0.0-20200331152225-585af27e34fd
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,8 @@ github.com/deislabs/oras v0.8.1/go.mod h1:Mx0rMSbBNaNfY9hjpccEnxkOqJL6KGjtxNHPLC
github.com/denisenkom/go-mssqldb v0.0.0-20190204142019-df6d76eb9289/go.mod h1:xN/JuLBIz4bjkxNmByTiV1IbhfnYb6oo99phBn4Eqhc=
github.com/devfile/api/v2 v2.2.2 h1:DXRCPWFlZhTIE38Of2jzTRjQHadfbxBC8GS+m+EjoCU=
github.com/devfile/api/v2 v2.2.2/go.mod h1:qp8jcw12y1JdCsxjK/7LJ7uWaJOxcY1s2LUk5PhbkbM=
github.com/devfile/devworkspace-operator v0.29.0 h1:SB46ueI7LEA6vYv8qH4nsyUiG67XDZkvvyLyL2yeWO8=
github.com/devfile/devworkspace-operator v0.29.0/go.mod h1:b2fBHTA6szY4uN46w0PlPKLJO/dzA8N2vvepBxSFmYk=
github.com/devfile/devworkspace-operator v0.31.0 h1:mrlBqo1wRR3dzhJm2IL3FmX3eHp8N8z/DobP6goN1qY=
github.com/devfile/devworkspace-operator v0.31.0/go.mod h1:b2fBHTA6szY4uN46w0PlPKLJO/dzA8N2vvepBxSFmYk=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dhui/dktest v0.3.2/go.mod h1:l1/ib23a/CmxAe7yixtrYPc8Iy90Zy2udyaHINM5p58=
github.com/docker/cli v0.0.0-20200130152716-5d0cf8839492 h1:FwssHbCDJD025h+BchanCwE1Q8fyMgqDr2mOQAWOLGw=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7255,6 +7255,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

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

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

Loading
Loading