Fix zookeeper antiaffinity (#52)
Fixes #39
### Motivation
The match expression for the "app" label was incorrect breaking the antiaffinity since they would never match. Fixing this makes the podAntiAffinity work, but now requires at least N nodes to be in the cluster where N = largest replica set with affinity. Added the option to set the affinity type to preferredDuringSchedulingIgnoredDuringExecution where it will try to follow the affinity, but will still deploy a pod if it needs to break it.
### Modifications
- Fixed app matchExpression
- Added option to set the affinity type
- bumped chart version
### Verifying this change
- [X] Make sure that the change passes the CI checks.
diff --git a/charts/pulsar/Chart.yaml b/charts/pulsar/Chart.yaml
index 2ea2fbf..3e1577a 100644
--- a/charts/pulsar/Chart.yaml
+++ b/charts/pulsar/Chart.yaml
@@ -21,7 +21,7 @@
appVersion: "2.6.0"
description: Apache Pulsar Helm chart for Kubernetes
name: pulsar
-version: 2.6.0-2
+version: 2.6.0-3
home: https://pulsar.apache.org
sources:
- https://github.com/apache/pulsar
diff --git a/charts/pulsar/templates/autorecovery-statefulset.yaml b/charts/pulsar/templates/autorecovery-statefulset.yaml
index 1a944c8..3fb22ce 100644
--- a/charts/pulsar/templates/autorecovery-statefulset.yaml
+++ b/charts/pulsar/templates/autorecovery-statefulset.yaml
@@ -62,13 +62,14 @@
affinity:
{{- if and .Values.affinity.anti_affinity .Values.autorecovery.affinity.anti_affinity}}
podAntiAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
+ {{ if eq .Values.autorecovery.affinity.type "requiredDuringSchedulingIgnoredDuringExecution"}}
+ {{ .Values.autorecovery.affinity.type }}:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- - "{{ template "pulsar.name" . }}-{{ .Values.bookkeeper.component }}"
+ - "{{ template "pulsar.name" . }}"
- key: "release"
operator: In
values:
@@ -76,8 +77,28 @@
- key: "component"
operator: In
values:
- - {{ .Values.bookkeeper.component }}
+ - {{ .Values.autorecovery.component }}
topologyKey: "kubernetes.io/hostname"
+ {{ else }}
+ {{ .Values.autorecovery.affinity.type }}:
+ - weight: 100
+ podAffinityTerm:
+ labelSelector:
+ matchExpressions:
+ - key: "app"
+ operator: In
+ values:
+ - "{{ template "pulsar.name" . }}"
+ - key: "release"
+ operator: In
+ values:
+ - {{ .Release.Name }}
+ - key: "component"
+ operator: In
+ values:
+ - {{ .Values.autorecovery.component }}
+ topologyKey: "kubernetes.io/hostname"
+ {{ end }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.autorecovery.gracePeriod }}
initContainers:
diff --git a/charts/pulsar/templates/bookkeeper-statefulset.yaml b/charts/pulsar/templates/bookkeeper-statefulset.yaml
index 46d7dc7..93db78d 100644
--- a/charts/pulsar/templates/bookkeeper-statefulset.yaml
+++ b/charts/pulsar/templates/bookkeeper-statefulset.yaml
@@ -59,13 +59,14 @@
affinity:
{{- if and .Values.affinity.anti_affinity .Values.bookkeeper.affinity.anti_affinity}}
podAntiAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
+ {{ if eq .Values.bookkeeper.affinity.type "requiredDuringSchedulingIgnoredDuringExecution"}}
+ {{ .Values.bookkeeper.affinity.type }}:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- - "{{ template "pulsar.name" . }}-{{ .Values.bookkeeper.component }}"
+ - "{{ template "pulsar.name" . }}"
- key: "release"
operator: In
values:
@@ -75,6 +76,26 @@
values:
- {{ .Values.bookkeeper.component }}
topologyKey: "kubernetes.io/hostname"
+ {{ else }}
+ {{ .Values.bookkeeper.affinity.type }}:
+ - weight: 100
+ podAffinityTerm:
+ labelSelector:
+ matchExpressions:
+ - key: "app"
+ operator: In
+ values:
+ - "{{ template "pulsar.name" . }}"
+ - key: "release"
+ operator: In
+ values:
+ - {{ .Release.Name }}
+ - key: "component"
+ operator: In
+ values:
+ - {{ .Values.bookkeeper.component }}
+ topologyKey: "kubernetes.io/hostname"
+ {{ end }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.bookkeeper.gracePeriod }}
initContainers:
diff --git a/charts/pulsar/templates/broker-statefulset.yaml b/charts/pulsar/templates/broker-statefulset.yaml
index 605cd64..63c9596 100644
--- a/charts/pulsar/templates/broker-statefulset.yaml
+++ b/charts/pulsar/templates/broker-statefulset.yaml
@@ -60,13 +60,14 @@
affinity:
{{- if and .Values.affinity.anti_affinity .Values.broker.affinity.anti_affinity}}
podAntiAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
+ {{ if eq .Values.broker.affinity.type "requiredDuringSchedulingIgnoredDuringExecution"}}
+ {{ .Values.broker.affinity.type }}:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- - "{{ template "pulsar.name" . }}-{{ .Values.broker.component }}"
+ - "{{ template "pulsar.name" . }}"
- key: "release"
operator: In
values:
@@ -76,6 +77,26 @@
values:
- {{ .Values.broker.component }}
topologyKey: "kubernetes.io/hostname"
+ {{ else }}
+ {{ .Values.broker.affinity.type }}:
+ - weight: 100
+ podAffinityTerm:
+ labelSelector:
+ matchExpressions:
+ - key: "app"
+ operator: In
+ values:
+ - "{{ template "pulsar.name" . }}"
+ - key: "release"
+ operator: In
+ values:
+ - {{ .Release.Name }}
+ - key: "component"
+ operator: In
+ values:
+ - {{ .Values.broker.component }}
+ topologyKey: "kubernetes.io/hostname"
+ {{ end }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.broker.gracePeriod }}
initContainers:
diff --git a/charts/pulsar/templates/proxy-statefulset.yaml b/charts/pulsar/templates/proxy-statefulset.yaml
index d92d5b0..1044f52 100644
--- a/charts/pulsar/templates/proxy-statefulset.yaml
+++ b/charts/pulsar/templates/proxy-statefulset.yaml
@@ -59,13 +59,14 @@
affinity:
{{- if and .Values.affinity.anti_affinity .Values.proxy.affinity.anti_affinity}}
podAntiAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
+ {{ if eq .Values.proxy.affinity.type "requiredDuringSchedulingIgnoredDuringExecution"}}
+ {{ .Values.proxy.affinity.type }}:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- - "{{ template "pulsar.name" . }}-{{ .Values.proxy.component }}"
+ - "{{ template "pulsar.name" . }}"
- key: "release"
operator: In
values:
@@ -75,6 +76,26 @@
values:
- {{ .Values.proxy.component }}
topologyKey: "kubernetes.io/hostname"
+ {{ else }}
+ {{ .Values.proxy.affinity.type }}:
+ - weight: 100
+ podAffinityTerm:
+ labelSelector:
+ matchExpressions:
+ - key: "app"
+ operator: In
+ values:
+ - "{{ template "pulsar.name" . }}"
+ - key: "release"
+ operator: In
+ values:
+ - {{ .Release.Name }}
+ - key: "component"
+ operator: In
+ values:
+ - {{ .Values.proxy.component }}
+ topologyKey: "kubernetes.io/hostname"
+ {{ end }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.proxy.gracePeriod }}
initContainers:
diff --git a/charts/pulsar/templates/zookeeper-statefulset.yaml b/charts/pulsar/templates/zookeeper-statefulset.yaml
index c32678d..205d540 100644
--- a/charts/pulsar/templates/zookeeper-statefulset.yaml
+++ b/charts/pulsar/templates/zookeeper-statefulset.yaml
@@ -56,13 +56,14 @@
affinity:
{{- if and .Values.affinity.anti_affinity .Values.zookeeper.affinity.anti_affinity}}
podAntiAffinity:
- requiredDuringSchedulingIgnoredDuringExecution:
+ {{ if eq .Values.zookeeper.affinity.type "requiredDuringSchedulingIgnoredDuringExecution"}}
+ {{ .Values.zookeeper.affinity.type }}:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- - "{{ template "pulsar.name" . }}-{{ .Values.zookeeper.component }}"
+ - "{{ template "pulsar.name" . }}"
- key: "release"
operator: In
values:
@@ -72,6 +73,26 @@
values:
- {{ .Values.zookeeper.component }}
topologyKey: "kubernetes.io/hostname"
+ {{ else }}
+ {{ .Values.zookeeper.affinity.type }}:
+ - weight: 100
+ podAffinityTerm:
+ labelSelector:
+ matchExpressions:
+ - key: "app"
+ operator: In
+ values:
+ - "{{ template "pulsar.name" . }}"
+ - key: "release"
+ operator: In
+ values:
+ - {{ .Release.Name }}
+ - key: "component"
+ operator: In
+ values:
+ - {{ .Values.zookeeper.component }}
+ topologyKey: "kubernetes.io/hostname"
+ {{ end }}
{{- end }}
terminationGracePeriodSeconds: {{ .Values.zookeeper.gracePeriod }}
containers:
diff --git a/charts/pulsar/values.yaml b/charts/pulsar/values.yaml
index 2c7eb2c..c71991c 100644
--- a/charts/pulsar/values.yaml
+++ b/charts/pulsar/values.yaml
@@ -66,6 +66,10 @@
## the `affinity.anti_affinity` settings to `false` for that component.
affinity:
anti_affinity: true
+ # Set the anti affinity type. Valid values:
+ # requiredDuringSchedulingIgnoredDuringExecution - rules must be met for pod to be scheduled (hard) requires at least one node per replica
+ # preferredDuringSchedulingIgnoredDuringExecution - scheduler will try to enforce but not guranentee
+ type: requiredDuringSchedulingIgnoredDuringExecution
## Components
##
@@ -285,6 +289,10 @@
periodSeconds: 30
affinity:
anti_affinity: true
+ # Set the anti affinity type. Valid values:
+ # requiredDuringSchedulingIgnoredDuringExecution - rules must be met for pod to be scheduled (hard) requires at least one node per replica
+ # preferredDuringSchedulingIgnoredDuringExecution - scheduler will try to enforce but not guranentee
+ type: requiredDuringSchedulingIgnoredDuringExecution
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8000"
@@ -391,6 +399,10 @@
periodSeconds: 30
affinity:
anti_affinity: true
+ # Set the anti affinity type. Valid values:
+ # requiredDuringSchedulingIgnoredDuringExecution - rules must be met for pod to be scheduled (hard) requires at least one node per replica
+ # preferredDuringSchedulingIgnoredDuringExecution - scheduler will try to enforce but not guranentee
+ type: requiredDuringSchedulingIgnoredDuringExecution
annotations: {}
tolerations: []
gracePeriod: 30
@@ -492,6 +504,10 @@
# cloud.google.com/gke-nodepool: default-pool
affinity:
anti_affinity: true
+ # Set the anti affinity type. Valid values:
+ # requiredDuringSchedulingIgnoredDuringExecution - rules must be met for pod to be scheduled (hard) requires at least one node per replica
+ # preferredDuringSchedulingIgnoredDuringExecution - scheduler will try to enforce but not guranentee
+ type: requiredDuringSchedulingIgnoredDuringExecution
annotations: {}
# tolerations: []
gracePeriod: 30
@@ -567,6 +583,10 @@
periodSeconds: 10
affinity:
anti_affinity: true
+ # Set the anti affinity type. Valid values:
+ # requiredDuringSchedulingIgnoredDuringExecution - rules must be met for pod to be scheduled (hard) requires at least one node per replica
+ # preferredDuringSchedulingIgnoredDuringExecution - scheduler will try to enforce but not guranentee
+ type: preferredDuringSchedulingIgnoredDuringExecution
annotations: {}
tolerations: []
gracePeriod: 30
@@ -654,6 +674,10 @@
periodSeconds: 10
affinity:
anti_affinity: true
+ # Set the anti affinity type. Valid values:
+ # requiredDuringSchedulingIgnoredDuringExecution - rules must be met for pod to be scheduled (hard) requires at least one node per replica
+ # preferredDuringSchedulingIgnoredDuringExecution - scheduler will try to enforce but not guranentee
+ type: requiredDuringSchedulingIgnoredDuringExecution
annotations: {}
tolerations: []
gracePeriod: 30