Skip to content

Commit 9fb9928

Browse files
committed
Add a nodeSelector option to enable the controller to manage only a subset of nodes.
Signed-off-by: bingshen.wbs <[email protected]>
1 parent 2632909 commit 9fb9928

File tree

6 files changed

+48
-17
lines changed

6 files changed

+48
-17
lines changed

deploy/helm/templates/configmap.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ data:
1616
"enableDevicePlugin": {{ .Values.config.enableDevicePlugin }},
1717
"enableWebhook": {{ .Values.config.enableWebhook }},
1818
"smcInitImage": "{{ .Values.config.smcInitImage }}",
19-
"enableInitContainerInject": {{ .Values.config.enableInitContainerInject }}
19+
"enableInitContainerInject": {{ .Values.config.enableInitContainerInject }},
20+
"nodeSelector": {{ .Values.nodeSelector | toJson }}
2021
}

deploy/helm/templates/daemonset.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ spec:
88
selector:
99
matchLabels:
1010
{{- include "alibabacloud-erdma-controller.selectorLabels" . | nindent 6 }}
11+
tier: agent
1112
template:
1213
metadata:
1314
{{- with .Values.podAnnotations }}
@@ -16,6 +17,7 @@ spec:
1617
{{- end }}
1718
labels:
1819
{{- include "alibabacloud-erdma-controller.selectorLabels" . | nindent 8 }}
20+
tier: agent
1921
spec:
2022
hostPID: true
2123
hostNetwork: true
@@ -83,6 +85,7 @@ spec:
8385
- name: var-run
8486
hostPath:
8587
path: /var/run/
88+
priorityClassName: system-node-critical
8689
{{- with .Values.nodeSelector }}
8790
nodeSelector:
8891
{{- toYaml . | nindent 8 }}

deploy/helm/templates/deployment.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ spec:
99
selector:
1010
matchLabels:
1111
{{- include "alibabacloud-erdma-controller.selectorLabels" . | nindent 6 }}
12+
tier: controller
1213
template:
1314
metadata:
1415
{{- with .Values.podAnnotations }}
@@ -17,6 +18,7 @@ spec:
1718
{{- end }}
1819
labels:
1920
{{- include "alibabacloud-erdma-controller.selectorLabels" . | nindent 8 }}
21+
tier: controller
2022
spec:
2123
{{- with .Values.controller.imagePullSecrets }}
2224
imagePullSecrets:
@@ -50,11 +52,11 @@ spec:
5052
secretName: {{ .Release.Name }}
5153
- name: webhook-vol
5254
emptyDir: { }
53-
{{- with .Values.nodeSelector }}
55+
{{- with .Values.controller.nodeSelector }}
5456
nodeSelector:
5557
{{- toYaml . | nindent 8 }}
5658
{{- end }}
57-
{{- with .Values.affinity }}
59+
{{- with .Values.controller.affinity }}
5860
affinity:
5961
{{- toYaml . | nindent 8 }}
6062
{{- end }}

deploy/helm/values.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ controller:
1313
imagePullSecrets: []
1414
nameOverride: ""
1515
fullnameOverride: ""
16+
nodeSelector: {}
17+
affinity: {}
1618

1719
agent:
1820
image:
@@ -39,7 +41,8 @@ podAnnotations: {}
3941

4042
nodeSelector: {}
4143

42-
tolerations: []
44+
tolerations:
45+
- operator: "Exists"
4346

4447
affinity: {}
4548

internal/controller/node_controller.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"time"
66

7+
"github.com/AliyunContainerService/alibabacloud-erdma-controller/internal/config"
78
"github.com/AliyunContainerService/alibabacloud-erdma-controller/internal/types"
89
"github.com/samber/lo"
910
k8stypes "k8s.io/apimachinery/pkg/types"
@@ -173,23 +174,43 @@ func RemoveERdmaDevices(erdmaClient client.Client, ctx context.Context, nodeName
173174
return ctrl.Result{}, nil
174175
}
175176

177+
func (r *NodeReconciler) OwnNode(node *v1.Node) bool {
178+
if node == nil {
179+
return false
180+
}
181+
for k, v := range config.GetConfig().NodeSelector {
182+
if node.Labels[k] != v {
183+
return false
184+
}
185+
}
186+
return true
187+
}
188+
176189
// SetupWithManager sets up the controller with the Manager.
177190
func (r *NodeReconciler) SetupWithManager(mgr ctrl.Manager) error {
178191
pred := predicate.TypedFuncs[*v1.Node]{
179192
CreateFunc: func(e event.TypedCreateEvent[*v1.Node]) bool {
180-
return true
193+
return r.OwnNode(e.Object)
181194
},
182195
DeleteFunc: func(e event.TypedDeleteEvent[*v1.Node]) bool {
183-
return true
196+
return r.OwnNode(e.Object)
184197
},
185198
UpdateFunc: func(e event.TypedUpdateEvent[*v1.Node]) bool {
199+
if !r.OwnNode(e.ObjectNew) {
200+
return false
201+
}
202+
if !r.OwnNode(e.ObjectOld) && r.OwnNode(e.ObjectNew) {
203+
return true
204+
}
205+
186206
if e.ObjectNew.DeletionTimestamp != nil {
187207
return true
188208
}
209+
189210
return e.ObjectOld.Spec.ProviderID != e.ObjectNew.Spec.ProviderID
190211
},
191212
GenericFunc: func(e event.TypedGenericEvent[*v1.Node]) bool {
192-
return true
213+
return r.OwnNode(e.Object)
193214
},
194215
}
195216
c, err := controller.New("node-controller", mgr, controller.Options{Reconciler: r})

internal/types/config.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package types
22

33
type Config struct {
4-
Region string `json:"region"`
5-
ManageNonOwnedERIs bool `json:"manageNonOwnedENIs"`
6-
ControllerNamespace string `json:"controllerNamespace"`
7-
ControllerName string `json:"controllerName"`
8-
ClusterDomain string `json:"clusterDomain"`
9-
CertDir string `json:"certDir"`
10-
EnableDevicePlugin *bool `json:"enableDevicePlugin"`
11-
EnableWebhook *bool `json:"enableWebhook"`
12-
SMCInitImage string `json:"smcInitImage"`
13-
EnableInitContainerInject *bool `json:"enableInitContainerInject"`
4+
Region string `json:"region"`
5+
ManageNonOwnedERIs bool `json:"manageNonOwnedENIs"`
6+
ControllerNamespace string `json:"controllerNamespace"`
7+
ControllerName string `json:"controllerName"`
8+
ClusterDomain string `json:"clusterDomain"`
9+
CertDir string `json:"certDir"`
10+
EnableDevicePlugin *bool `json:"enableDevicePlugin"`
11+
EnableWebhook *bool `json:"enableWebhook"`
12+
SMCInitImage string `json:"smcInitImage"`
13+
EnableInitContainerInject *bool `json:"enableInitContainerInject"`
14+
NodeSelector map[string]string `json:"nodeSelector"`
1415
}
1516

1617
type Sensitive string

0 commit comments

Comments
 (0)