From 90211803a700df72bc30976d07b91515b8165599 Mon Sep 17 00:00:00 2001 From: co-jo Date: Mon, 20 Jul 2020 16:04:43 -0700 Subject: [PATCH 1/3] Add hooks for pravega-operator chart. Signed-off-by: co-jo --- .../templates/post-install-upgrade-hooks.yaml | 116 ++++++++++++++++++ charts/pravega-operator/values.yaml | 6 + 2 files changed, 122 insertions(+) create mode 100644 charts/pravega-operator/templates/post-install-upgrade-hooks.yaml diff --git a/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml b/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml new file mode 100644 index 000000000..e6022267c --- /dev/null +++ b/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml @@ -0,0 +1,116 @@ +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ template "pravega-operator.fullname" . }}-post-install-upgrade + namespace: {{ .Release.Namespace }} + annotations: + "helm.sh/hook": post-install, post-upgrade + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed +rules: +- apiGroups: + - pravega.pravega.io + resources: + - "*" + verbs: + - get +- apiGroups: + - extensions + resources: + - "deployments" + verbs: + - get +--- + +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ template "pravega-operator.fullname" . }}-post-install-upgrade + namespace: {{ .Release.Namespace }} + annotations: + "helm.sh/hook": post-install, post-upgrade + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed +subjects: +- kind: ServiceAccount + name: {{ template "pravega-operator.fullname" . }}-post-install-upgrade + namespace: {{.Release.Namespace}} +roleRef: + kind: Role + name: {{ template "pravega-operator.fullname" . }}-post-install-upgrade + apiGroup: rbac.authorization.k8s.io + +--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "pravega-operator.fullname" . }}-post-install-upgrade + namespace: {{ .Release.Namespace }} + annotations: + "helm.sh/hook": post-install, post-upgrade + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed + +--- + +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "pravega-operator.fullname" . }}-post-install-upgrade + namespace: {{ .Release.Namespace }} + annotations: + "helm.sh/hook": post-install, post-upgrade + "helm.sh/hook-weight": "1" + "helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed +data: + validations.sh: | + #!/bin/sh + set -e + sleep 30 + + if [ -z "$(kubectl api-resources | grep PravegaCluster)" ]; then + exit 1 + fi + + readyReplicas=`kubectl get deployment {{ template "pravega-operator.fullname" . }} \ + -n {{ .Release.Namespace }} \ + -o jsonpath='{.status.readyReplicas}'` + echo "PravegaCluster readyReplicas: $readyReplicas" + + if [ -z $readyReplicas ] || [ $readyReplicas -le 0 ]; then + exit 1 + fi +--- + +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ template "pravega-operator.fullname" . }}-post-install-upgrade + namespace: {{ .Release.Namespace }} + annotations: + "helm.sh/hook": post-install, post-upgrade + "helm.sh/hook-weight": "2" + "helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed +spec: + backoffLimit: 3 + template: + metadata: + name: {{ template "pravega-operator.fullname" . }}-post-install-upgrade + spec: + serviceAccountName: {{ template "pravega-operator.fullname" . }}-post-install-upgrade + restartPolicy: Never + containers: + - name: post-install-upgrade-job + image: "{{ .Values.hooks.image.repository }}:{{ .Values.hooks.image.tag }}" + command: + - /scripts/validations.sh + volumeMounts: + - name: sh + mountPath: /scripts + readOnly: true + volumes: + - name: sh + configMap: + name: {{ template "pravega-operator.fullname" . }}-post-install-upgrade + defaultMode: 0555 diff --git a/charts/pravega-operator/values.yaml b/charts/pravega-operator/values.yaml index 8f750cb32..d8f2134ae 100644 --- a/charts/pravega-operator/values.yaml +++ b/charts/pravega-operator/values.yaml @@ -40,3 +40,9 @@ webhookCert: ## Specifies which namespace the Operator should watch over. ## An empty string means all namespaces. watchNamespace: "" + +hooks: + image: + repository: lachlanevenson/k8s-kubectl + tag: v1.16.10 + backoffLimit: 10 From 1fbe71fc378e9ee1e2d391046ccace70b2db3770 Mon Sep 17 00:00:00 2001 From: co-jo Date: Wed, 22 Jul 2020 10:01:11 -0700 Subject: [PATCH 2/3] Remove redundant replica checks. Signed-off-by: co-jo --- .../templates/post-install-upgrade-hooks.yaml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml b/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml index e6022267c..26eff4d1b 100644 --- a/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml +++ b/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml @@ -72,15 +72,6 @@ data: if [ -z "$(kubectl api-resources | grep PravegaCluster)" ]; then exit 1 fi - - readyReplicas=`kubectl get deployment {{ template "pravega-operator.fullname" . }} \ - -n {{ .Release.Namespace }} \ - -o jsonpath='{.status.readyReplicas}'` - echo "PravegaCluster readyReplicas: $readyReplicas" - - if [ -z $readyReplicas ] || [ $readyReplicas -le 0 ]; then - exit 1 - fi --- apiVersion: batch/v1 From 441d02913a7cf4c30e736aee89f54dccf4ecc371 Mon Sep 17 00:00:00 2001 From: co-jo Date: Thu, 23 Jul 2020 12:03:33 -0700 Subject: [PATCH 3/3] Parameterize backoffLimit. Signed-off-by: co-jo --- .../pravega-operator/templates/post-install-upgrade-hooks.yaml | 2 +- charts/pravega-operator/values.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml b/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml index 26eff4d1b..32fa167a0 100644 --- a/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml +++ b/charts/pravega-operator/templates/post-install-upgrade-hooks.yaml @@ -84,7 +84,7 @@ metadata: "helm.sh/hook-weight": "2" "helm.sh/hook-delete-policy": hook-succeeded, before-hook-creation, hook-failed spec: - backoffLimit: 3 + backoffLimit: {{ .Values.hooks.backoffLimit }} template: metadata: name: {{ template "pravega-operator.fullname" . }}-post-install-upgrade diff --git a/charts/pravega-operator/values.yaml b/charts/pravega-operator/values.yaml index d8f2134ae..b07e64b81 100644 --- a/charts/pravega-operator/values.yaml +++ b/charts/pravega-operator/values.yaml @@ -42,7 +42,7 @@ webhookCert: watchNamespace: "" hooks: + backoffLimit: 10 image: repository: lachlanevenson/k8s-kubectl tag: v1.16.10 - backoffLimit: 10