Skip to content

Commit

Permalink
Issue 417: Harden zookeeper post-install hook (#418)
Browse files Browse the repository at this point in the history
Signed-off-by: anishakj <[email protected]>
  • Loading branch information
anishakj authored Dec 2, 2021
1 parent d7b042f commit f32c9fe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 66 deletions.
46 changes: 32 additions & 14 deletions charts/zookeeper/templates/post-install-upgrade-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,44 @@ metadata:
data:
validations.sh: |
#!/bin/sh
set -e
set +e
sleep 30
replicas=`kubectl get zk -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.spec.replicas}'`
readyReplicas=`kubectl get zk -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.status.readyReplicas}'`
currentVersion=`kubectl get zk -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.status.currentVersion}'`
targetVersion=`kubectl get zk -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.spec.image.tag}'`
echo "ZookeeperCluster replicas: $currentReplicas"
echo "ZookeeperCluster readyReplicas: $readyReplicas"
echo "ZookeeperCluster currentVersion: $currentVersion"
echo "ZookeeperCluster targetVersion: $targetVersion"
if [ $readyReplicas != $replicas ]; then
echo "Checking for ready ZK replicas"
kubectl get ZookeeperCluster -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.status.conditions[?(@.type=="PodsReady")].status}' | grep True
if [ $? != 0 ]; then
echo "ZK replicas not ready"
exit 1
fi
set -e
replicasZk=`kubectl get ZookeeperCluster -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.spec.replicas}'`
readyReplicasZk=`kubectl get ZookeeperCluster -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.status.readyReplicas}'`
currentVersionZk=`kubectl get ZookeeperCluster -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.status.currentVersion}'`
targetVersionZk=`kubectl get ZookeeperCluster -n {{ .Release.Namespace }} {{ template "zookeeper.fullname" . }} -o jsonpath='{.spec.image.tag}'`
if [ $currentVersion != $targetVersion ]; then
echo
echo "ZookeeperCluster replicas: $replicasZk"
echo "ZookeeperCluster readyReplicas: $readyReplicasZk"
echo "ZookeeperCluster currentVersion: $currentVersionZk"
echo "ZookeeperCluster targetVersion: $targetVersionZk"
echo
if [[ -z $readyReplicasZk ]]; then
echo "No ready ZK replicas"
exit 2
fi
if [[ $replicasZk != $readyReplicasZk ]]; then
echo "Wrong number of ZK replicas"
exit 3
fi
if [[ -z $currentVersionZk ]]; then
echo "Current ZK version not set"
exit 4
fi
if [[ $currentVersionZk != $targetVersionZk ]]; then
echo "Wrong current ZK version"
exit 5
fi
echo "ZookeeperCluster is ready"
---

apiVersion: batch/v1
Expand Down
50 changes: 1 addition & 49 deletions charts/zookeeper/templates/zookeeper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,55 +128,7 @@ spec:
{{- end }}
{{- if .Values.config }}
config:
{{- if .Values.config.initLimit }}
initLimit: {{ .Values.config.initLimit }}
{{- end }}
{{- if .Values.config.tickTime }}
tickTime: {{ .Values.config.tickTime }}
{{- end }}
{{- if .Values.config.syncLimit }}
syncLimit: {{ .Values.config.syncLimit }}
{{- end }}
{{- if .Values.config.globalOutstandingLimit }}
globalOutstandingLimit: {{ .Values.config.globalOutstandingLimit }}
{{- end }}
{{- if .Values.config.preAllocSize }}
preAllocSize: {{ .Values.config.preAllocSize }}
{{- end }}
{{- if .Values.config.snapCount }}
snapCount: {{ .Values.config.snapCount }}
{{- end }}
{{- if .Values.config.commitLogCount }}
commitLogCount: {{ .Values.config.commitLogCount }}
{{- end }}
{{- if .Values.config.snapSizeLimitInKb }}
snapSizeLimitInKb: {{ .Values.config.snapSizeLimitInKb }}
{{- end }}
{{- if .Values.config.maxCnxns }}
maxCnxns: {{ .Values.config.maxCnxns }}
{{- end }}
{{- if .Values.config.maxClientCnxns }}
maxClientCnxns: {{ .Values.config.maxClientCnxns }}
{{- end }}
{{- if .Values.config.minSessionTimeout }}
minSessionTimeout: {{ .Values.config.minSessionTimeout }}
{{- end }}
{{- if .Values.config.maxSessionTimeout }}
maxSessionTimeout: {{ .Values.config.maxSessionTimeout }}
{{- end }}
{{- if .Values.config.autoPurgeSnapRetainCount }}
autoPurgeSnapRetainCount: {{ .Values.config.autoPurgeSnapRetainCount }}
{{- end }}
{{- if .Values.config.autoPurgePurgeInterval }}
autoPurgePurgeInterval: {{ .Values.config.autoPurgePurgeInterval }}
{{- end }}
{{- if .Values.config.quorumListenOnAllIPs }}
quorumListenOnAllIPs: {{ .Values.config.quorumListenOnAllIPs }}
{{- end }}
{{- if .Values.config.additionalConfig }}
additionalConfig:
{{- toYaml .Values.config.additionalConfig | nindent 6 }}
{{- end }}
{{- toYaml .Values.config | nindent 4 }}
{{- end }}
storageType: {{ $storageType }}
{{- if eq $storageType "ephemeral" }}
Expand Down
6 changes: 3 additions & 3 deletions charts/zookeeper/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ clientService: {}
headlessService: {}
# annotations: {}

config: {}
config:
# initLimit: 10
# tickTime: 2000
# syncLimit: 2
# globalOutstandingLimit: 1000
# preAllocSize: 65536
preAllocSize: 16384 # default 65536
# snapCount: 100000
# commitLogCount: 500
# snapSizeLimitInKb: 4194304
Expand All @@ -69,7 +69,7 @@ config: {}
# autoPurgePurgeInterval: 1
# quorumListenOnAllIPs: false
# additionalConfig: {}

## configure the storage type
## accepted values : persistence/ephemeral
## default option is persistence
Expand Down

0 comments on commit f32c9fe

Please sign in to comment.