Skip to content

Commit 5fa7b80

Browse files
shanshanyingwusai80JashBook
committed
chore: add namespace to namespace scoped crs in helm chart (#9885)
Co-authored-by: wusai80 <wusai80@gmail.com> Co-authored-by: huangzhangshu <huangzhangshu@apecloud.com> (cherry picked from commit 8e31218)
1 parent a3f6f39 commit 5fa7b80

14 files changed

+139
-1
lines changed

.github/workflows/release-crds.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
fi
7676
make bump-chart-ver VERSION="${BUMP_VERSION}"
7777
touch ${{ matrix.yaml }}
78-
helm template kubeblocks deploy/helm --dependency-update > ${{ matrix.yaml }}
78+
helm template kubeblocks deploy/helm --namespace kb-system --dependency-update > ${{ matrix.yaml }}
7979
8080
- name: merge KubeBlocks crds
8181
if: ${{ matrix.yaml == 'kubeblocks_crds.yaml' }}

deploy/helm/templates/configmap.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: v1
22
kind: ConfigMap
33
metadata:
44
name: {{ include "kubeblocks.fullname" . }}-manager-config
5+
namespace: {{ .Release.Namespace }}
56
labels:
67
{{- include "kubeblocks.labels" . | nindent 4 }}
78
data:
@@ -22,6 +23,7 @@ apiVersion: v1
2223
kind: ConfigMap
2324
metadata:
2425
name: {{ include "kubeblocks.fullname" . }}-host-ports
26+
namespace: {{ .Release.Namespace }}
2527
labels:
2628
{{- include "kubeblocks.labels" . | nindent 4 }}
2729
data: {}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{{- if .Values.webhooks.conversionEnabled }}
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: {{ .Release.Name }}-crd-patch
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
{{- include "kubeblocks.labels" . | nindent 4 }}
9+
annotations:
10+
"helm.sh/hook": post-install
11+
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
12+
spec:
13+
ttlSecondsAfterFinished: 0
14+
backoffLimit: 2
15+
template:
16+
metadata:
17+
name: {{ .Release.Name }}-crd-patch
18+
labels:
19+
{{- include "kubeblocks.labels" . | nindent 8 }}
20+
spec:
21+
{{- with .Values.image.imagePullSecrets }}
22+
imagePullSecrets:
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
25+
serviceAccountName: {{ include "kubeblocks.serviceAccountName" . }}
26+
securityContext:
27+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
28+
restartPolicy: Never
29+
containers:
30+
- name: post-install-job
31+
image: "{{ .Values.image.registry | default "docker.io" }}/{{ .Values.image.tools.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
32+
imagePullPolicy: {{ .Values.image.pullPolicy }}
33+
command:
34+
- sh
35+
- -c
36+
- |
37+
set -e
38+
# 1. check the already installed KubeBlocks
39+
deployments=$(kubectl get deployments -A -l app.kubernetes.io/name=kubeblocks --no-headers)
40+
OLD_IFS=$IFS
41+
IFS=$'\n'
42+
for line in $deployments; do
43+
namespace=$(echo "$line" | awk '{print $1}')
44+
name=$(echo "$line" | awk '{print $2}')
45+
old_kb_json=$(kubectl get deployment ${name} -n ${namespace} -o json)
46+
version=$(echo ${old_kb_json} | jq '.metadata.labels["app.kubernetes.io/version"]' | tr -d '"')
47+
replicas=$(echo ${old_kb_json} | jq '.spec.replicas')
48+
statusReplicas=$(echo ${old_kb_json} | jq '.status.replicas')
49+
if echo "$version" | grep -q '^0\.9'; then
50+
echo "TODO: add it when released 0.9.2"
51+
# patch_num=$(echo $version | awk -F. '{print $3}' | awk -F- '{print $1}')
52+
# if [ "$version" != "0.9.2" ] && [ $patch_num -le 2 ]; then
53+
# echo "ERROR: the installed KubeBlocks version must greater and equal to 0.9.2"
54+
# exit 1
55+
# fi
56+
elif echo "$version" | grep -q '^0\.'; then
57+
echo "ERROR: can not upgrade KubeBlocks from $version to {{ .Chart.AppVersion }}"
58+
exit 1
59+
fi
60+
if [ $replicas -ne 0 ]; then
61+
echo "ERROR: You must stop the existing ${namespace}/${name} version (${version}) before installing version 1.0."
62+
exit 1
63+
fi
64+
echo "status: $statusReplicas"
65+
if [ "$statusReplicas" != "null" ] || [ $statusReplicas -ne 0 ]; then
66+
echo "ERROR: You must stop the existing ${namespace}/${name} version (${version}) before installing version 1.0."
67+
exit 1
68+
fi
69+
done
70+
IFS=$OLD_IFS
71+
# 2. patch crds
72+
patch_crd_cmd="kubectl patch crd --patch-file=/opt/conversion_webhook_patch.json"
73+
${patch_crd_cmd} "clusterdefinitions.apps.kubeblocks.io"
74+
${patch_crd_cmd} "clusters.apps.kubeblocks.io"
75+
${patch_crd_cmd} "componentdefinitions.apps.kubeblocks.io"
76+
${patch_crd_cmd} "components.apps.kubeblocks.io"
77+
${patch_crd_cmd} "componentversions.apps.kubeblocks.io"
78+
${patch_crd_cmd} "instancesets.workloads.kubeblocks.io"
79+
${patch_crd_cmd} "servicedescriptors.apps.kubeblocks.io"
80+
81+
# 3. start KubeBlocks
82+
kubectl patch deployment {{ include "kubeblocks.fullname" . }} -n {{ .Release.Namespace }} -p '{"spec":{"replicas":{{ .Values.replicaCount }}}}'
83+
{{- if .Values.dataProtection.enabled }}
84+
kubectl patch deployment {{ include "kubeblocks.fullname" . }}-dataprotection -n {{ .Release.Namespace }} -p '{"spec":{"replicas":{{ .Values.replicaCount }}}}'
85+
{{- end }}
86+
volumeMounts:
87+
- mountPath: /opt
88+
name: crd-multi-version-conversion
89+
{{- with .Values.topologySpreadConstraints }}
90+
topologySpreadConstraints:
91+
{{- toYaml . | nindent 8 }}
92+
{{- end }}
93+
{{- with .Values.affinity }}
94+
affinity:
95+
{{- toYaml . | nindent 8 }}
96+
{{- end }}
97+
{{- with .Values.nodeSelector }}
98+
nodeSelector:
99+
{{- toYaml . | nindent 8 }}
100+
{{- end }}
101+
{{- with .Values.tolerations }}
102+
tolerations:
103+
{{- toYaml . | nindent 8 }}
104+
{{- end }}
105+
volumes:
106+
- name: crd-multi-version-conversion
107+
configMap:
108+
name: {{ include "kubeblocks.fullname" . }}.{{ .Release.Namespace }}.crd.conversion.webhook
109+
{{- end }}

deploy/helm/templates/dataprotection.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ apiVersion: apps/v1
44
kind: Deployment
55
metadata:
66
name: {{ include "kubeblocks.fullname" . }}-dataprotection
7+
namespace: {{ .Release.Namespace }}
78
{{- with .Values.dataProtection.deployAnnotations }}
89
annotations:
910
{{- toYaml . | nindent 4 }}

deploy/helm/templates/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
name: {{ include "kubeblocks.fullname" . }}
5+
namespace: {{ .Release.Namespace }}
56
{{- with .Values.deployAnnotations }}
67
annotations:
78
{{- toYaml . | nindent 4 }}

deploy/helm/templates/hpa.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: autoscaling/v2beta1
33
kind: HorizontalPodAutoscaler
44
metadata:
55
name: {{ include "kubeblocks.fullname" . }}
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "kubeblocks.labels" . | nindent 4 }}
89
spec:
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "kubeblocks.i18nResourcesName" . }}
5+
namespace: {{ .Release.Namespace }}
6+
labels:
7+
{{- include "kubeblocks.labels" . | nindent 4 }}
8+
data:
9+
en: |
10+
v1/ConfigMap/Creation=configuration file %s/%s is created.
11+
v1/Pod/Creation=Pod %s/%s is created.
12+
v1/Pod/Update=Pod %s/%s is updated.
13+
zh_CN: |
14+
v1/ConfigMap/Creation=配置文件 %s/%s 创建成功。
15+
v1/Pod/Creation=Pod %s/%s 创建成功。
16+
v1/Pod/Update=Pod %s/%s 更新成功。

deploy/helm/templates/kubeblocks-upgrade-hook.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: batch/v1
33
kind: Job
44
metadata:
55
name: {{ .Release.Name }}-upgrade-hook-job
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "kubeblocks.labels" . | nindent 4 }}
89
annotations:

deploy/helm/templates/poddisruptionbudget.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ apiVersion: policy/v1beta1
77
kind: PodDisruptionBudget
88
metadata:
99
name: {{ template "kubeblocks.fullname" . }}
10+
namespace: {{ .Release.Namespace }}
1011
labels: {{ include "kubeblocks.labels" . | nindent 4 }}
1112
spec:
1213
{{- include "podDisruptionBudget.spec" . | indent 2 }}

deploy/helm/templates/pre-delete-addon-job.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ apiVersion: batch/v1
33
kind: Job
44
metadata:
55
name: {{ .Release.Name }}-addon-removal
6+
namespace: {{ .Release.Namespace }}
67
labels:
78
{{- include "kubeblocks.labels" . | nindent 4 }}
89
annotations:

0 commit comments

Comments
 (0)