Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix controller can't restart in helm for dependent secret not found #5305

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions charts/karmada/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -586,40 +586,31 @@ Return the proper Docker Image Registry Secret Names
{{- end }}
{{- end -}}

{{- define "karmada.init-sa-secret.volume" -}}
{{- $name := include "karmada.name" . -}}
- name: init-sa-secret
secret:
secretName: {{ $name }}-hook-job
{{- end -}}

{{- define "karmada.init-sa-secret.volumeMount" -}}
- name: init-sa-secret
mountPath: /opt/mount
{{- end -}}

{{- define "karmada.initContainer.build-kubeconfig" -}}
TOKEN=$(cat /opt/mount/token)
kubectl config set-cluster karmada-host --server=https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT} --certificate-authority=/opt/mount/ca.crt
kubectl config set-credentials default --token=$TOKEN
kubectl config set-context karmada-host-context --cluster=karmada-host --user=default --namespace=default
kubectl config use-context karmada-host-context
{{- end -}}

{{- define "karmada.initContainer.waitEtcd" -}}
- name: wait
image: {{ include "karmada.kubectl.image" . }}
image: {{ include "karmada.cfssl.image" . }}
imagePullPolicy: {{ .Values.kubectl.image.pullPolicy }}
command:
- /bin/sh
- -c
- |
bash <<'EOF'
{{- include "karmada.initContainer.build-kubeconfig" . | nindent 6 }}
kubectl rollout status statefulset etcd -n {{ include "karmada.namespace" . }}
set -ex
while true; do
ETCD_ENDPOINT=${ETCD_CLIENT_SERVICE_HOST}":"${ETCD_CLIENT_SERVICE_PORT}

# check etcd connectivity by executing curl.
# if etcd is ready, the response of curl would be `curl: (52) Empty reply from server`, with return code 52.
# if not, the response of curl would be like `curl: (7) Failed to connect to .....`, with other return code.
if curl --connect-timeout 2 ${ETCD_ENDPOINT} || [ $? -eq 52 ]; then
break
fi

echo "failed to connect to "${ETCD_ENDPOINT}
sleep 2
done
echo "successfully connect to "${ETCD_ENDPOINT}
EOF
volumeMounts:
{{- include "karmada.init-sa-secret.volumeMount" .| nindent 4 }}
{{- end -}}

{{- define "karmada.initContainer.waitStaticResource" -}}
Expand All @@ -631,9 +622,18 @@ kubectl config use-context karmada-host-context
- -c
- |
bash <<'EOF'
{{- include "karmada.initContainer.build-kubeconfig" . | nindent 6 }}
kubectl wait --for=condition=complete job {{ include "karmada.name" . }}-static-resource -n {{ include "karmada.namespace" . }}
set -ex

# here are three cases:
# case first installation: no `cm/karmada-version` at first, so when you get it, it means `karmada-static-resource-job` finished.
# case restart: already has `cm/karmada-version`, which means `karmada-static-resource-job` already finished.
# case upgrading: already has `cm/karmada-version`, but it may be old version, we should wait until `.data.karmadaVersion` equal to current `.Values.karmadaImageVersion`.
while [[ $(kubectl --kubeconfig /etc/kubeconfig get configmap karmada-version -n {{ .Values.systemNamespace }} -o jsonpath='{.data.karmadaVersion}') != {{ .Values.karmadaImageVersion }} ]]; do
echo "wait for karmada-static-resource-job finished"; sleep 2
done

echo "karmada-static-resource-job successfully completed since expected configmap value was found"
EOF
volumeMounts:
{{- include "karmada.init-sa-secret.volumeMount" .| nindent 4 }}
{{- include "karmada.kubeconfig.volumeMount" .| nindent 4 }}
{{- end -}}
1 change: 0 additions & 1 deletion charts/karmada/templates/karmada-aggregated-apiserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{- include "karmada.init-sa-secret.volume" . | nindent 8 }}
{{- include "karmada.kubeconfig.volume" . | nindent 8 }}
- name: apiserver-cert
secret:
Expand Down
1 change: 0 additions & 1 deletion charts/karmada/templates/karmada-apiserver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{- include "karmada.init-sa-secret.volume" . | nindent 8 }}
- name: apiserver-cert
secret:
secretName: {{ $name }}-cert
Expand Down
1 change: 0 additions & 1 deletion charts/karmada/templates/karmada-controller-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{- include "karmada.init-sa-secret.volume" . | nindent 8 }}
{{- include "karmada.kubeconfig.volume" . | nindent 8 }}
initContainers:
{{- include "karmada.initContainer.waitStaticResource" . | nindent 8 }}
Expand Down
1 change: 0 additions & 1 deletion charts/karmada/templates/karmada-descheduler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ spec:
resources:
{{- toYaml .Values.descheduler.resources | nindent 12 }}
volumes:
{{- include "karmada.init-sa-secret.volume" . | nindent 8 }}
{{- include "karmada.descheduler.kubeconfig.volume" . | nindent 8 }}
{{- include "karmada.scheduler.cert.volume" . | nindent 8 }}

Expand Down
1 change: 0 additions & 1 deletion charts/karmada/templates/karmada-metrics-adapter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
{{- include "karmada.init-sa-secret.volume" . | nindent 8 }}
{{- include "karmada.kubeconfig.volume" . | nindent 8 }}
- name: apiserver-cert
secret:
Expand Down
1 change: 0 additions & 1 deletion charts/karmada/templates/karmada-scheduler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ spec:
resources:
{{- toYaml .Values.scheduler.resources | nindent 12 }}
volumes:
{{- include "karmada.init-sa-secret.volume" . | nindent 8 }}
{{- include "karmada.kubeconfig.volume" . | nindent 8 }}
{{- include "karmada.scheduler.cert.volume" . | nindent 8 }}

Expand Down
1 change: 0 additions & 1 deletion charts/karmada/templates/karmada-search.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ spec:
resources:
{{- toYaml .Values.apiServer.resources | nindent 12 }}
volumes:
{{- include "karmada.init-sa-secret.volume" . | nindent 8 }}
{{- include "karmada.search.kubeconfig.volume" . | nindent 8 }}
{{- include "karmada.search.etcd.cert.volume" . | nindent 8 }}
---
Expand Down
11 changes: 11 additions & 0 deletions charts/karmada/templates/karmada-static-resource-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ spec:
kubectl apply -k /crds --kubeconfig /etc/kubeconfig
kubectl apply -f /static-resources/system-namespace.yaml --kubeconfig /etc/kubeconfig
kubectl apply -f /static-resources/ --kubeconfig /etc/kubeconfig

kubectl --kubeconfig /etc/kubeconfig apply -f - <<InnerEOF
apiVersion: v1
kind: ConfigMap
metadata:
name: karmada-version
namespace: {{ .Values.systemNamespace }}
data:
karmadaVersion: {{ .Values.karmadaImageVersion }}
InnerEOF

EOF
volumeMounts:
- name: {{ $name }}-crds-kustomization
Expand Down
1 change: 0 additions & 1 deletion charts/karmada/templates/karmada-webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ spec:
resources:
{{- toYaml .Values.webhook.resources | nindent 12 }}
volumes:
{{- include "karmada.init-sa-secret.volume" . | nindent 8 }}
{{- include "karmada.kubeconfig.volume" . | nindent 8 }}
- name: {{ $name }}-webhook-cert-secret
secret:
Expand Down
1 change: 0 additions & 1 deletion charts/karmada/templates/kube-controller-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ spec:
- name: apisever-cert
secret:
secretName: {{ $name }}-cert
{{- include "karmada.init-sa-secret.volume" . | nindent 8 }}
{{- include "karmada.kubeconfig.volume" . | nindent 8 }}

{{ if .Values.kubeControllerManager.podDisruptionBudget }}
Expand Down
1 change: 0 additions & 1 deletion charts/karmada/templates/post-install-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,5 @@ spec:
done
kubectl delete job {{ $name }}-static-resource -n {{ $namespace }}
kubectl delete secret {{ $name }}-hook-job -n {{ $namespace }}
EOF
{{- end }}
15 changes: 0 additions & 15 deletions charts/karmada/templates/pre-install-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -459,21 +459,6 @@ metadata:
{{- include "karmada.preInstallJob.labels" . | nindent 4 }}
{{- end }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ $name }}-hook-job
namespace: {{ $namespace }}
annotations:
"kubernetes.io/service-account.name": {{ $name }}-hook-job
"helm.sh/hook": pre-install
"helm.sh/hook-weight": "1"
{{- if "karmada.preInstallJob.labels" }}
labels:
{{- include "karmada.preInstallJob.labels" . | nindent 4 }}
{{- end }}
type: kubernetes.io/service-account-token
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand Down