Skip to content
Open
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
2 changes: 1 addition & 1 deletion charts/apisix/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 3.1.0
version: 3.1.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
15 changes: 14 additions & 1 deletion charts/apisix/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ true
{{- end -}}
{{- end -}}

{{/*
Return the address of the bundled etcd Service. The name comes from the etcd
chart's own helpers, so nameOverride, fullnameOverride, namespaceOverride and
release names that already contain "etcd" resolve to the Service it creates.
*/}}
{{- define "apisix.etcd.host" -}}
{{- if and .Values.etcd.fullnameOverride (not .Values.etcd.namespaceOverride) -}}
{{- include "common.names.fullname" .Subcharts.etcd -}}
{{- else -}}
{{- printf "%s.%s.svc.%s" (include "common.names.fullname" .Subcharts.etcd) (include "common.names.namespace" .Subcharts.etcd) .Values.etcd.clusterDomain -}}
{{- end -}}
{{- end -}}

{{/*
Return the name of etcd password secret
*/}}
Expand Down Expand Up @@ -194,7 +207,7 @@ its NetworkPolicy cannot handle.
{{- end -}}
{{- $label := printf "%s-client" (include "common.names.fullname" .Subcharts.etcd) -}}
{{- if gt (len $label) 63 -}}
{{- fail (printf "The NetworkPolicy of the bundled etcd admits pods labelled %s, but a label key has at most 63 characters. For a new release, use a shorter release name or etcd.fullnameOverride (APISIX does not find etcd under an etcd.nameOverride); otherwise set etcd.networkPolicy.allowExternal: true" $label) -}}
{{- fail (printf "The NetworkPolicy of the bundled etcd admits pods labelled %s, but a label key has at most 63 characters. For a new release, use a shorter release name, etcd.nameOverride or etcd.fullnameOverride; otherwise set etcd.networkPolicy.allowExternal: true" $label) -}}
{{- end -}}
{{- if and $etcd.metrics.enabled (not $etcd.metrics.useSeparateEndpoint) -}}
{{- fail "etcd.metrics.enabled serves the metrics on the etcd client port, and the etcd chart then opens that port to every pod. Set etcd.metrics.useSeparateEndpoint: true to serve them on a port of their own, or etcd.networkPolicy.allowExternal: true" -}}
Expand Down
6 changes: 1 addition & 5 deletions charts/apisix/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,7 @@ data:
etcd:
{{- if .Values.etcd.enabled }}
host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster.
{{- if .Values.etcd.fullnameOverride }}
- "{{ include "apisix.etcd.auth.scheme" . }}://{{ .Values.etcd.fullnameOverride }}:{{ .Values.etcd.service.port }}"
{{- else }}
- "{{ include "apisix.etcd.auth.scheme" . }}://{{ .Release.Name }}-etcd.{{ .Release.Namespace }}.svc.{{ .Values.etcd.clusterDomain }}:{{ .Values.etcd.service.port }}"
{{- end}}
- "{{ include "apisix.etcd.auth.scheme" . }}://{{ include "apisix.etcd.host" . }}:{{ .Values.etcd.service.port }}"
{{- else }}
host: # it's possible to define multiple etcd hosts addresses of the same etcd cluster.
{{- range $value := .Values.externalEtcd.host }}
Expand Down
6 changes: 1 addition & 5 deletions charts/apisix/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,7 @@ spec:
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.etcd.fullnameOverride }}
command: ['sh', '-c', "until nc -z {{ .Values.etcd.fullnameOverride }} {{ .Values.etcd.service.port }}; do echo waiting for etcd `date`; sleep 2; done;"]
{{ else }}
command: ['sh', '-c', "until nc -z {{ .Release.Name }}-etcd.{{ .Release.Namespace }}.svc.{{ .Values.etcd.clusterDomain }} {{ .Values.etcd.service.port }}; do echo waiting for etcd `date`; sleep 2; done;"]
{{- end }}
command: ['sh', '-c', "until nc -z {{ include "apisix.etcd.host" . }} {{ .Values.etcd.service.port }}; do echo waiting for etcd `date`; sleep 2; done;"]
{{- end }}
{{- if .Values.extraInitContainers }}
{{- toYaml .Values.extraInitContainers | nindent 8 }}
Expand Down
31 changes: 29 additions & 2 deletions test/render/etcd-access.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ with_values() { # with_values <yq expression> <command...>: run the command on a
rm -rf "$dir"
return $rc
}
etcd_service() { # the name of the client Service that the etcd subchart renders
yq 'select(.kind == "Service" and .spec.ports[0].port == 2379 and (.metadata.name | test("headless") | not)) | .metadata.name' <<<"$OUT"
}
config_etcd_host() { # the Service name in the etcd host of the APISIX ConfigMap, without scheme, namespace and port
local h; h=$(etcd_config '.deployment.etcd.host[0]'); h=${h#*://}; h=${h%:*}; echo "${h%%.*}"
}
wait_etcd_target() { # the Service name that the wait-etcd init container waits for
local h; h=$(yq 'select(.kind == "Deployment") | .spec.template.spec.initContainers[] | select(.name == "wait-etcd") | .command[2]' <<<"$OUT" |
sed -n 's/^until nc -z \([^ ]*\) .*/\1/p'); echo "${h%%.*}"
}
secret_exists() { [ -n "$(yq "select(.kind == \"Secret\" and .metadata.name == \"$1\") | .metadata.name" <<<"$OUT")" ]; }
no_secret() { ! secret_exists "$1"; }

Expand Down Expand Up @@ -132,8 +142,8 @@ check "a long release name: fails, the client label would be too long" fails_wit
"$LONG_RELEASE"
check "a long etcd.fullnameOverride: fails as well" fails_with "but a label key has at most 63 characters" \
apisix --set etcd.fullnameOverride="etcd-$(printf '%052d' 0 | tr 0 b)"
check "a long etcd.nameOverride: fails, and the message does not suggest one" \
fails_with "use a shorter release name or etcd.fullnameOverride (APISIX does not find etcd under an etcd.nameOverride)" \
check "a long etcd.nameOverride: fails, and the message suggests a shorter one" \
fails_with "use a shorter release name, etcd.nameOverride or etcd.fullnameOverride" \
apisix --set etcd.nameOverride="etcd-$(printf '%052d' 0 | tr 0 c)"
check "a long release name with allowExternal: renders" render "$LONG_RELEASE" --set etcd.networkPolicy.allowExternal=true
check "a long release name with allowExternal: every label key is valid" bash -c '[ "$1" -le 63 ]' _ "$(longest_label)"
Expand Down Expand Up @@ -231,6 +241,23 @@ check "hostNetwork with external etcd: renders" render apisix --set hostNetwork=
check "DaemonSet: renders" render apisix --set useDaemonSet=true
check "DaemonSet: the pods carry the etcd client label" is "$(pod_label apisix-etcd-client)" true

# --- the Service name that APISIX and wait-etcd use ---------------------------------

check "etcd host, default: renders" render demo
check "etcd host, default: the ConfigMap uses the etcd Service" is "$(config_etcd_host)" "$(etcd_service)"
check "etcd host, default: wait-etcd waits for the etcd Service" is "$(wait_etcd_target)" "$(etcd_service)"
check "etcd host, nameOverride: renders" render demo --set etcd.nameOverride=store
check "etcd host, nameOverride: the Service is named after it" is "$(etcd_service)" demo-store
check "etcd host, nameOverride: the ConfigMap uses the etcd Service" is "$(config_etcd_host)" "$(etcd_service)"
check "etcd host, nameOverride: wait-etcd waits for the etcd Service" is "$(wait_etcd_target)" "$(etcd_service)"
check "etcd host, release name with etcd in it: renders" render demo-etcd
check "etcd host, release name with etcd in it: the Service is demo-etcd" is "$(etcd_service)" demo-etcd
check "etcd host, release name with etcd in it: the ConfigMap uses the etcd Service" is "$(config_etcd_host)" "$(etcd_service)"
check "etcd host, release name with etcd in it: wait-etcd waits for the etcd Service" is "$(wait_etcd_target)" "$(etcd_service)"
check "etcd host, fullnameOverride: renders" render demo --set etcd.fullnameOverride=kv
check "etcd host, fullnameOverride: the ConfigMap uses the etcd Service" is "$(config_etcd_host)" "$(etcd_service)"
check "etcd host, fullnameOverride: wait-etcd waits for the etcd Service" is "$(wait_etcd_target)" "$(etcd_service)"

# --- the root password ---------------------------------------------------------------

check "default again: renders" render apisix
Expand Down
Loading