Skip to content

Commit 07dedef

Browse files
committed
feat: allow users to specify nodeSelector map
1 parent 4780032 commit 07dedef

9 files changed

Lines changed: 41 additions & 5 deletions

api/v1alphav1/overcommit_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type OvercommitSpec struct {
2626
// +kubebuilder:validation:Optional
2727
Annotations map[string]string `json:"annotations,omitempty"`
2828
// +kubebuilder:validation:Optional
29+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
30+
// +kubebuilder:validation:Optional
2931
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
3032
}
3133

api/v1alphav1/overcommitclass_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type OvercommitClassSpec struct {
3434
Labels map[string]string `json:"labels,omitempty"`
3535
Annotations map[string]string `json:"annotations,omitempty"`
3636
// +kubebuilder:validation:Optional
37+
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
38+
// +kubebuilder:validation:Optional
3739
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
3840
}
3941

api/v1alphav1/zz_generated.deepcopy.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/overcommit.inditex.dev_overcommitclasses.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ spec:
7676
maximum: 1
7777
minimum: 0.0001
7878
type: number
79+
nodeSelector:
80+
additionalProperties:
81+
type: string
82+
type: object
7983
tolerations:
8084
items:
8185
description: |-

config/crd/bases/overcommit.inditex.dev_overcommits.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ spec:
5252
additionalProperties:
5353
type: string
5454
type: object
55+
nodeSelector:
56+
additionalProperties:
57+
type: string
58+
type: object
5559
overcommitLabel:
5660
minLength: 1
5761
type: string

internal/resources/generate_resources_overcommit_class_controller_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ func GenerateOvercommitClassControllerDeployment(overcommitObject overcommit.Ove
9494
},
9595
},
9696
},
97-
Tolerations: overcommitObject.Spec.Tolerations,
97+
NodeSelector: overcommitObject.Spec.NodeSelector,
98+
Tolerations: overcommitObject.Spec.Tolerations,
9899
},
99100
},
100101
},

internal/resources/generate_resources_pod_mutating_webhooks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ func CreateDeployment(class overcommit.OvercommitClass) *appsv1.Deployment {
9797
},
9898
},
9999
},
100-
Tolerations: class.Spec.Tolerations,
100+
NodeSelector: class.Spec.NodeSelector,
101+
Tolerations: class.Spec.Tolerations,
101102
Volumes: []corev1.Volume{
102103
{
103104
Name: "webhook-tls-secret",

internal/resources/generate_resources_pod_mutating_webhooks_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestCreateDeployment(t *testing.T) {
4242
}
4343
}
4444

45-
func TestCreateDeploymentWithTolerations(t *testing.T) {
45+
func TestCreateDeploymentWithTolerationsAndNodeSelector(t *testing.T) {
4646
os.Setenv("POD_NAMESPACE", "test-namespace")
4747
os.Setenv("IMAGE_REGISTRY", "test-registry")
4848
os.Setenv("IMAGE_REPOSITORY", "test-repo")
@@ -55,6 +55,9 @@ func TestCreateDeploymentWithTolerations(t *testing.T) {
5555
Spec: overcommit.OvercommitClassSpec{
5656
Labels: map[string]string{"key": "value"},
5757
Annotations: map[string]string{"annotation-key": "annotation-value"},
58+
NodeSelector: map[string]string{
59+
"disktype": "ssd",
60+
},
5861
Tolerations: []corev1.Toleration{
5962
{
6063
Key: "key1",
@@ -81,6 +84,9 @@ func TestCreateDeploymentWithTolerations(t *testing.T) {
8184
if deployment.Spec.Template.Spec.Tolerations[0].Key != "key1" {
8285
t.Errorf("Expected toleration key 'key1', got '%s'", deployment.Spec.Template.Spec.Tolerations[0].Key)
8386
}
87+
if val, ok := deployment.Spec.Template.Spec.NodeSelector["disktype"]; !ok || val != "ssd" {
88+
t.Errorf("Expected node selector 'disktype: ssd', got '%v'", deployment.Spec.Template.Spec.NodeSelector)
89+
}
8490
}
8591

8692
func TestCreateService(t *testing.T) {

internal/resources/generate_resources_validating_webhooks.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ func GeneratePodValidatingDeployment(overcommitObject overcommit.Overcommit) *ap
128128
},
129129
},
130130
},
131-
Tolerations: overcommitObject.Spec.Tolerations,
131+
NodeSelector: overcommitObject.Spec.NodeSelector,
132+
Tolerations: overcommitObject.Spec.Tolerations,
132133
Volumes: []corev1.Volume{
133134
{
134135
Name: "webhook-cert",
@@ -300,7 +301,8 @@ func GenerateOvercommitClassValidatingDeployment(overcommitObject overcommit.Ove
300301
},
301302
},
302303
},
303-
Tolerations: overcommitObject.Spec.Tolerations,
304+
NodeSelector: overcommitObject.Spec.NodeSelector,
305+
Tolerations: overcommitObject.Spec.Tolerations,
304306
Volumes: []corev1.Volume{
305307
{
306308
Name: "webhook-cert",

0 commit comments

Comments
 (0)