-
Notifications
You must be signed in to change notification settings - Fork 153
fix: run init-job on first install #450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,10 @@ metadata: | |
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
| annotations: | ||
| helm.sh/hook: post-install,post-upgrade | ||
| helm.sh/hook-delete-policy: before-hook-creation | ||
| {{- if not .Release.IsInstall }} | ||
| helm.sh/hook: post-upgrade | ||
| helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded | ||
| {{- end }} | ||
| {{- with .Values.init.jobAnnotations }} | ||
| {{- toYaml . | nindent 4 }} | ||
| {{- end }} | ||
|
|
@@ -97,57 +99,32 @@ spec: | |
| - name: cluster-init | ||
| image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" | ||
| imagePullPolicy: {{ .Values.image.pullPolicy | quote }} | ||
| # Run the command in an `while true` loop because this Job is bound | ||
| # to come up before the CockroachDB Pods (due to the time needed to | ||
| # get PersistentVolumes attached to Nodes), and sleeping 5 seconds | ||
| # between attempts is much better than letting the Pod fail when | ||
| # the init command does and waiting out Kubernetes' non-configurable | ||
| # exponential back-off for Pod restarts. | ||
| # Command completes either when cluster initialization succeeds, | ||
| # or when cluster has been initialized already. | ||
| command: | ||
| - /bin/bash | ||
| - -c | ||
| - >- | ||
| - | | ||
| {{- if $isClusterInitEnabled }} | ||
| initCluster() { | ||
| while true; do | ||
|
Comment on lines
-113
to
-114
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this loop can cause issues, what if the init was not successful in first attempt. Job will fail and cockroachdb will not come up.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| local output=$( | ||
| set -x; | ||
|
|
||
| /cockroach/cockroach init \ | ||
| {{- if .Values.tls.enabled }} | ||
| --certs-dir=/cockroach-certs/ \ | ||
| {{- else }} | ||
| --insecure \ | ||
| {{- end }} | ||
| {{- with index .Values.conf "cluster-name" }} | ||
| --cluster-name={{.}} \ | ||
| {{- end }} | ||
| --host={{ template "cockroachdb.fullname" . }}-0.{{ template "cockroachdb.fullname" . -}} | ||
| :{{ .Values.service.ports.grpc.internal.port | int64 }} \ | ||
| {{- if .Values.init.pcr.enabled -}} | ||
| {{- if .Values.init.pcr.isPrimary }} | ||
| --virtualized \ | ||
| {{- else }} | ||
| --virtualized-empty \ | ||
| {{- end }} | ||
| {{- end }} | ||
| 2>&1); | ||
|
|
||
| local exitCode="$?"; | ||
| echo $output; | ||
|
|
||
| if [[ "$output" =~ .*"Cluster successfully initialized".* || "$output" =~ .*"cluster has already been initialized".* ]]; then | ||
| break; | ||
| fi | ||
|
|
||
| echo "Cluster is not ready to be initialized, retrying in 5 seconds" | ||
| sleep 5; | ||
| done | ||
| } | ||
|
|
||
| initCluster; | ||
| set -x; | ||
| /cockroach/cockroach init \ | ||
| {{- if .Values.tls.enabled }} | ||
| --certs-dir=/cockroach-certs/ | ||
| {{- else }} | ||
| --insecure | ||
| {{- end }} \ | ||
| {{- with index .Values.conf "cluster-name" }} | ||
| --cluster-name={{.}} \ | ||
| {{- end }} | ||
| --host={{ template "cockroachdb.fullname" . }}-0.{{ template "cockroachdb.fullname" . -}} | ||
| :{{ .Values.service.ports.grpc.internal.port | int64 }} | ||
| {{- if .Values.init.pcr.enabled -}} \ | ||
| {{- if .Values.init.pcr.isPrimary }} | ||
| --virtualized | ||
| {{- else }} | ||
| --virtualized-empty | ||
| {{- end }} | ||
| {{- end }} 2>&1 | tee /tmp/output.txt || grep "ERROR: cluster has already been initialized" /tmp/output.txt | ||
| {{- end }} | ||
|
|
||
| {{- if $isDatabaseProvisioningEnabled }} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main issue with this is the job will be left in the cluster and when you do an upgrade, the new image will be patched to this job which is not allowed as job is an immutable resource in kubernetes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the
hook-delete-policystill applies on Upgrade, it removes the old job before creating the one for the upgrade.Feel free to test it out.