Skip to content

Commit

Permalink
feat: add a way to exclude nodes
Browse files Browse the repository at this point in the history
Signed-off-by: wangyizhi1 <[email protected]>
  • Loading branch information
wangyizhi1 committed Nov 24, 2023
1 parent e923865 commit 79fa5e3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
17 changes: 17 additions & 0 deletions deploy/clusterlink-elector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ spec:
labels:
app: elector
spec:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kosmos.io/exclude
operator: DoesNotExist
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- elector
namespaces:
- kosmos-system
topologyKey: kubernetes.io/hostname
containers:
- command:
- clusterlink-elector
Expand Down
6 changes: 3 additions & 3 deletions pkg/clusterlink/controllers/node/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ type Reconciler struct {
var predicatesFunc = predicate.Funcs{
CreateFunc: func(createEvent event.CreateEvent) bool {
node := createEvent.Object.(*corev1.Node)
return !utils.IsKosmosNode(node)
return !utils.IsKosmosNode(node) && !utils.IsExcludeNode(node)
},
UpdateFunc: func(updateEvent event.UpdateEvent) bool {
node := updateEvent.ObjectNew.(*corev1.Node)
return !utils.IsKosmosNode(node)
return !utils.IsKosmosNode(node) && !utils.IsExcludeNode(node)
},
DeleteFunc: func(deleteEvent event.DeleteEvent) bool {
node := deleteEvent.Object.(*corev1.Node)
return !utils.IsKosmosNode(node)
return !utils.IsKosmosNode(node) && !utils.IsExcludeNode(node)
},
GenericFunc: func(genericEvent event.GenericEvent) bool {
return false
Expand Down
6 changes: 6 additions & 0 deletions pkg/operator/clusterlink/elector/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ spec:
spec:
serviceAccountName: {{ .Name }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kosmos.io/exclude
operator: DoesNotExist
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
Expand Down
2 changes: 2 additions & 0 deletions pkg/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const (
KosmosSelectorKey = "kosmos.io/cluster-selector"
KosmosTrippedLabels = "kosmos-io/tripped"
KosmosPvcLabelSelector = "kosmos-io/label-selector"
KosmosExcludeNodeLabel = "kosmos.io/exclude"
KosmosExcludeNodeValue = "true"

// on resorce (pv, configmap, secret), represents which cluster this resource belongs to
KosmosResourceOwnersAnnotations = "kosmos-io/cluster-owners"
Expand Down
11 changes: 11 additions & 0 deletions pkg/utils/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ func IsKosmosNode(node *corev1.Node) bool {
return labelVal == KosmosNodeValue
}

func IsExcludeNode(node *corev1.Node) bool {
if node == nil {
return false
}
labelVal, exist := node.ObjectMeta.Labels[KosmosExcludeNodeLabel]
if !exist {
return false
}
return labelVal == KosmosExcludeNodeValue
}

func IsVirtualPod(pod *corev1.Pod) bool {
if pod.Labels != nil && pod.Labels[KosmosPodLabel] == "true" {
return true
Expand Down

0 comments on commit 79fa5e3

Please sign in to comment.