diff --git a/packages/rancher-monitoring/templates/crd-template/templates/_helpers.tpl b/packages/rancher-monitoring/templates/crd-template/templates/_helpers.tpl index 2da79e70f..edac2b315 100644 --- a/packages/rancher-monitoring/templates/crd-template/templates/_helpers.tpl +++ b/packages/rancher-monitoring/templates/crd-template/templates/_helpers.tpl @@ -26,4 +26,25 @@ beta.kubernetes.io/os: linux {{- else -}} kubernetes.io/os: linux {{- end -}} +{{- end -}} + +# CRD Installation + +{{- define "crd.established" -}} +{{- if not (regexMatch "^([a-zA-Z]+[.][a-zA-Z]*)+$" .) -}} +{{ required (printf "%s is not a valid CRD" .) "" }} +{{- else -}} +echo "beginning wait for {{ . }} to be established..."; +num_tries=1; +until kubectl get crd {{ . }} -o=jsonpath='{range .status.conditions[*]}{.type}={.status} {end}' | grep -qE 'Established=True'; do + if (( num_tries == 30 )); then + echo "timed out waiting for {{ . }}"; + exit 1; + fi; + num_tries=$(( num_tries + 1 )); + echo "{{ . }} is not established. Sleeping for 2 seconds and trying again..."; + sleep 2; +done; +echo "successfully established {{ . }}"; +{{- end -}} {{- end -}} \ No newline at end of file diff --git a/packages/rancher-monitoring/templates/crd-template/templates/jobs.yaml b/packages/rancher-monitoring/templates/crd-template/templates/jobs.yaml index 22287a27d..a668d2989 100644 --- a/packages/rancher-monitoring/templates/crd-template/templates/jobs.yaml +++ b/packages/rancher-monitoring/templates/crd-template/templates/jobs.yaml @@ -35,18 +35,7 @@ spec: patch="{\"spec\": {\"preserveUnknownFields\": false, \"versions\": [{\"name\": \"v1\", \"served\": false, \"storage\": true}]}}"; fi if kubectl patch crd {{ $crd }} -p "${patch}" --type="merge"; then - echo "beginning wait for {{ $crd }} to be established..."; - num_tries=1; - until kubectl get crd {{ $crd }} -o=jsonpath='{range .status.conditions[*]}{.type}={.status} {end}' | grep -qE 'Established=True'; do - if (( num_tries == 30 )); then - echo "timed out waiting for {{ $crd }}"; - exit 1; - fi; - num_tries=$(( num_tries + 1 )); - echo "{{ $crd }} is not established. Sleeping for 2 seconds and trying again..."; - sleep 2; - done; - echo "successfully established {{ $crd }}"; + {{- include "crd.established" $crd | nindent 18 }} fi; fi; {{- end }} @@ -70,18 +59,7 @@ spec: {{- range $path, $_ := (.Files.Glob "crd-manifest/**.yaml") }} {{- $crd := get (get ($.Files.Get $path | fromYaml) "metadata") "name" }} - echo "beginning wait for {{ $crd }} to be established..."; - num_tries=1; - until kubectl get crd {{ $crd }} -o=jsonpath='{range .status.conditions[*]}{.type}={.status} {end}' | grep -qE 'Established=True'; do - if (( num_tries == 30 )); then - echo "timed out waiting for {{ $crd }}"; - exit 1; - fi; - num_tries=$(( num_tries + 1 )); - echo "{{ $crd }} is not established. Sleeping for 2 seconds and trying again..."; - sleep 2; - done; - echo "successfully established {{ $crd }}"; + {{- include "crd.established" $crd | nindent 12 }} {{- end }} volumeMounts: - name: crd-manifest @@ -127,18 +105,7 @@ spec: {{- range $path, $_ := (.Files.Glob "crd-manifest/**.yaml") }} {{- $crd := get (get ($.Files.Get $path | fromYaml) "metadata") "name" }} if kubectl patch crd {{ $crd }} -p '{"metadata": {"finalizers": []}}'; then - echo "beginning wait for {{ $crd }} to be established..."; - num_tries=1; - until kubectl get crd {{ $crd }} -o=jsonpath='{range .status.conditions[*]}{.type}={.status} {end}' | grep -qE 'Established=True'; do - if (( num_tries == 30 )); then - echo "timed out waiting for {{ $crd }}"; - exit 1; - fi; - num_tries=$(( num_tries + 1 )); - echo "{{ $crd }} is not established. Sleeping for 2 seconds and trying again..."; - sleep 2; - done; - echo "successfully established {{ $crd }}"; + {{- include "crd.established" $crd | nindent 14 }} fi; {{- end }} volumeMounts: