Move establishing CRD logic to a helper template

pull/1203/head
Arvind Iyengar 2021-06-01 12:43:07 -07:00
parent 5f3bbe4a36
commit 02ff0c9df8
No known key found for this signature in database
GPG Key ID: A8DD9BFD6C811498
2 changed files with 24 additions and 36 deletions

View File

@ -27,3 +27,24 @@ beta.kubernetes.io/os: linux
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 -}}

View File

@ -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: