forked from fluid-cloudnative/fluid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support crd auto upgrader with helm hook (fluid-cloudnative#2062)
* Support crd auto upgrader with helm hook Signed-off-by: dongyun.xzh <[email protected]> * Add empty line Signed-off-by: dongyun.xzh <[email protected]> * Add upgrade crd scirpts into docker image Signed-off-by: dongyun.xzh <[email protected]> * Add empty line to end of script Signed-off-by: dongyun.xzh <[email protected]> * Rename template folder to "upgrade" Signed-off-by: dongyun.xzh <[email protected]> * Enable helm chart hook when upgrading only Signed-off-by: dongyun.xzh <[email protected]> Signed-off-by: dongyun.xzh <[email protected]>
- Loading branch information
1 parent
ffdd935
commit d2bc81a
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
apiVersion: batch/v1 | ||
kind: Job | ||
metadata: | ||
namespace: {{ .Release.Namespace }} | ||
name: fluid-crds-upgrade-{{ .Chart.AppVersion }} | ||
annotations: | ||
"helm.sh/hook": pre-upgrade | ||
"helm.sh/hook-weight": "-4" | ||
"helm.sh/hook-delete-policy": before-hook-creation | ||
spec: | ||
template: | ||
spec: | ||
serviceAccountName: fluid-crds-upgrade | ||
containers: | ||
- name: fluid-crds-upgrade | ||
image: {{ .Values.crdUpgrade.image }} | ||
command: ["bash", "/fluid/upgrade-crds.sh"] | ||
restartPolicy: OnFailure | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: fluid-crds-upgrade | ||
annotations: | ||
"helm.sh/hook": pre-upgrade | ||
"helm.sh/hook-weight": "-5" | ||
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation | ||
rules: | ||
- apiGroups: ["apiextensions.k8s.io"] | ||
resources: ["customresourcedefinitions"] | ||
verbs: ["create", "get", "update"] | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: fluid-crds-upgrade | ||
annotations: | ||
"helm.sh/hook": pre-upgrade | ||
"helm.sh/hook-weight": "-5" | ||
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: fluid-crds-upgrade | ||
subjects: | ||
- kind: ServiceAccount | ||
name: fluid-crds-upgrade | ||
namespace: {{ .Release.Namespace }} | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: fluid-crds-upgrade | ||
namespace: {{ .Release.Namespace }} | ||
annotations: | ||
"helm.sh/hook": pre-upgrade | ||
"helm.sh/hook-weight": "-5" | ||
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM alpine:3.10 | ||
|
||
COPY ./charts/fluid/fluid/crds /fluid/crds | ||
COPY ./tools/crd-upgrade/upgrade-crds.sh /fluid/upgrade-crds.sh | ||
|
||
RUN apk add --update curl tzdata iproute2 bash libc6-compat vim && \ | ||
rm -rf /var/cache/apk/* && \ | ||
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ | ||
echo "Asia/Shanghai" > /etc/timezone | ||
|
||
ENV K8S_VERSION v1.14.8 | ||
ARG TARGETARCH | ||
RUN curl -o /usr/local/bin/kubectl https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/${TARGETARCH}/kubectl && chmod +x /usr/local/bin/kubectl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
for crdfile in $(find /fluid/crds/*.yaml); | ||
do | ||
crdshort=${crdfile#*_} | ||
if [[ $(kubectl get --ignore-not-found -f $crdfile | wc -l) -gt 0 ]]; then | ||
echo "$crdshort founded, replacing its crd..." | ||
kubectl replace -f $crdfile | ||
else | ||
echo "$crdshort not founded, applying its crd..." | ||
kubectl apply -f $crdfile | ||
fi | ||
done |