Skip to content

Commit

Permalink
feat: Add option to deploy che component on specific nodes (eclipse-c…
Browse files Browse the repository at this point in the history
…he#1902)

* feat: Add option to deploy che component on specific nodes

Signed-off-by: Anatolii Bazko <[email protected]>
  • Loading branch information
tolusha authored Sep 20, 2024
1 parent 4bacfff commit d5e7499
Show file tree
Hide file tree
Showing 12 changed files with 1,720 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api/v2/checluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,12 @@ type Deployment struct {
// Security options the pod should run with.
// +optional
SecurityContext *PodSecurityContext `json:"securityContext,omitempty"`
// The node selector limits the nodes that can run the pod.
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// The pod tolerations of the component pod limit where the pod can run.
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
}

// Container custom settings.
Expand Down
14 changes: 14 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 @@ -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.92.0-886.next
name: eclipse-che.v7.92.0-887.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -1035,7 +1035,7 @@ spec:
minKubeVersion: 1.19.0
provider:
name: Eclipse Foundation
version: 7.92.0-886.next
version: 7.92.0-887.next
webhookdefinitions:
- admissionReviewVersions:
- v1
Expand Down
230 changes: 230 additions & 0 deletions bundle/next/eclipse-che/manifests/org.eclipse.che_checlusters.yaml

Large diffs are not rendered by default.

230 changes: 230 additions & 0 deletions config/crd/bases/org.eclipse.che_checlusters.yaml

Large diffs are not rendered by default.

230 changes: 230 additions & 0 deletions deploy/deployment/kubernetes/combined.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

230 changes: 230 additions & 0 deletions deploy/deployment/openshift/combined.yaml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions pkg/deploy/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ func OverrideDeployment(
}
}

if overrideDeploymentSettings != nil {
if len(overrideDeploymentSettings.NodeSelector) > 0 {
deployment.Spec.Template.Spec.NodeSelector = make(map[string]string, len(overrideDeploymentSettings.NodeSelector))
for i, s := range overrideDeploymentSettings.NodeSelector {
deployment.Spec.Template.Spec.NodeSelector[i] = s
}
}

if len(overrideDeploymentSettings.Tolerations) > 0 {
deployment.Spec.Template.Spec.Tolerations = make([]corev1.Toleration, len(overrideDeploymentSettings.Tolerations))
for i, t := range overrideDeploymentSettings.Tolerations {
deployment.Spec.Template.Spec.Tolerations[i] = t
}
}
}

if !infrastructure.IsOpenShift() {
if overrideDeploymentSettings != nil {
if overrideDeploymentSettings.SecurityContext != nil {
Expand Down
72 changes: 72 additions & 0 deletions pkg/deploy/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1189,3 +1189,75 @@ func TestOverrideContainerCpuLimit(t *testing.T) {
})
}
}

func TestOverrideNodeSelector(t *testing.T) {
ctx := test.GetDeployContext(nil, []runtime.Object{})
deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "eclipse-che",
},
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test",
},
},
},
},
},
}
overrideDeployment := &chev2.Deployment{
NodeSelector: map[string]string{
"a": "b",
"c": "d",
},
}

err := OverrideDeployment(ctx, deployment, overrideDeployment)
assert.NoError(t, err)
assert.Equal(t, overrideDeployment.NodeSelector, deployment.Spec.Template.Spec.NodeSelector)
}

func TestOverrideTolerations(t *testing.T) {
ctx := test.GetDeployContext(nil, []runtime.Object{})
deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "eclipse-che",
},
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "test",
},
},
},
},
},
}
overrideDeployment := &chev2.Deployment{
Tolerations: []corev1.Toleration{
{
Key: "a",
Operator: corev1.TolerationOpEqual,
Value: "b",
Effect: corev1.TaintEffectNoSchedule,
},
{
Key: "b",
Operator: corev1.TolerationOpExists,
Value: "c",
Effect: corev1.TaintEffectNoExecute,
},
},
}

err := OverrideDeployment(ctx, deployment, overrideDeployment)
assert.NoError(t, err)
assert.Equal(t, overrideDeployment.Tolerations, deployment.Spec.Template.Spec.Tolerations)
}

0 comments on commit d5e7499

Please sign in to comment.