From 47fdb5130938b162986b14f342ccd0cf5636ce25 Mon Sep 17 00:00:00 2001 From: Colin Hryniowski Date: Thu, 23 Jul 2020 21:19:28 -0700 Subject: [PATCH] ZooKeeper Operator API Resource Hook. (#221) * Add api-resource Helm hook. Signed-off-by: co-jo * Add api-resource Helm hook. Signed-off-by: co-jo * Add checks in hook for available pods. Signed-off-by: co-jo * Add role to get deployment status. Signed-off-by: co-jo * Fix test command. Signed-off-by: co-jo * Remove redundant replica checks. Signed-off-by: co-jo * Parameterize backoffLimit. Signed-off-by: co-jo --- .../templates/post-install-upgrade-hooks.yaml | 107 ++++++++++++++++++ charts/zookeeper-operator/values.yaml | 7 ++ 2 files changed, 114 insertions(+) create mode 100644 charts/zookeeper-operator/templates/post-install-upgrade-hooks.yaml diff --git a/charts/zookeeper-operator/templates/post-install-upgrade-hooks.yaml b/charts/zookeeper-operator/templates/post-install-upgrade-hooks.yaml new file mode 100644 index 000000000..13a39c0c5 --- /dev/null +++ b/charts/zookeeper-operator/templates/post-install-upgrade-hooks.yaml @@ -0,0 +1,107 @@ +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ template "zookeeper-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: + - zookeeper.pravega.io + resources: + - "*" + verbs: + - get +- apiGroups: + - extensions + resources: + - "deployments" + verbs: + - get +--- + +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: {{ template "zookeeper-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 "zookeeper-operator.fullname" . }}-post-install-upgrade + namespace: {{.Release.Namespace}} +roleRef: + kind: Role + name: {{ template "zookeeper-operator.fullname" . }}-post-install-upgrade + apiGroup: rbac.authorization.k8s.io + +--- + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ template "zookeeper-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 "zookeeper-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 ZookeeperCluster)" ]; then + exit 1 + fi +--- + +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ template "zookeeper-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: {{ .Values.hooks.backoffLimit }} + template: + metadata: + name: {{ template "zookeeper-operator.fullname" . }}-post-install-upgrade + spec: + serviceAccountName: {{ template "zookeeper-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 "zookeeper-operator.fullname" . }}-post-install-upgrade + defaultMode: 0555 diff --git a/charts/zookeeper-operator/values.yaml b/charts/zookeeper-operator/values.yaml index 7f3989ba3..7474ca7ce 100644 --- a/charts/zookeeper-operator/values.yaml +++ b/charts/zookeeper-operator/values.yaml @@ -39,3 +39,10 @@ resources: {} # requests: # cpu: 1 # memory: 128Mi + +hooks: + backoffLimit: 10 + image: + repository: lachlanevenson/k8s-kubectl + tag: v1.16.10 +