From 3e28b0ee2d9cbd47a7822dc212e5d0981d782002 Mon Sep 17 00:00:00 2001 From: Phil Sphicas Date: Mon, 9 Aug 2021 04:39:52 +0000 Subject: [PATCH] Fix kube-apiserver anchor script rendering This change corrects two rendering issues in the kube-apiserver anchor script. The details and impact are mentioned below. 1. The kube-apiserver anchor script fails to clean up some files from the host, because the path is incomplete. For example, the cleanup() function of the script includes: rm -f "/host/acconfig.yaml" instead of rm -f "/host/etc/kubernetes/apiserver/acconfig.yaml" 2. A recent change to allow fileless command options [0] caused some extraneous lines to end up in the script. For example, the rendered script includes: snapshot_files() { cp "/tmp/etc/" "${SNAPSHOT_DIR}/etc/kubernetes/apiserver/" } compare_copy_files() { SRC="${SNAPSHOT_DIR}/etc/kubernetes/apiserver/" DEST="/host/etc/kubernetes/apiserver/" if [ ! -e "${DEST}" ] || ! cmp -s "${SRC}" "${DEST}"; then mkdir -p $(dirname "${DEST}") cp "${SRC}" "${DEST}" chmod go-rwx "${DEST}" fi } cleanup() { rm -f "/host/" } Since the 'cp' and 'rm' commands don't include '-r', this is actually non-impacting, other than some log messages. 0: https://review.opendev.org/c/airship/promenade/+/788092 Change-Id: Id0a47727d56268d13ebb4718b8578d94272c2181 --- charts/apiserver/templates/bin/_anchor.tpl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/charts/apiserver/templates/bin/_anchor.tpl b/charts/apiserver/templates/bin/_anchor.tpl index 081b8604..c7fbb690 100644 --- a/charts/apiserver/templates/bin/_anchor.tpl +++ b/charts/apiserver/templates/bin/_anchor.tpl @@ -22,8 +22,10 @@ snapshot_files() { cp "{{ $source }}" "${SNAPSHOT_DIR}{{ $dest }}" {{- end }} {{ range $key, $val := .Values.conf }} + {{- if $val.file }} cp "/tmp/etc/{{ $val.file }}" "${SNAPSHOT_DIR}/etc/kubernetes/apiserver/{{ $val.file }}" {{- end }} + {{- end }} } compare_copy_files() { @@ -38,6 +40,7 @@ compare_copy_files() { fi {{- end}} {{ range $key, $val := .Values.conf }} + {{- if $val.file }} SRC="${SNAPSHOT_DIR}/etc/kubernetes/apiserver/{{ $val.file }}" DEST="/host/etc/kubernetes/apiserver/{{ $val.file }}" if [ ! -e "${DEST}" ] || ! cmp -s "${SRC}" "${DEST}"; then @@ -46,6 +49,7 @@ compare_copy_files() { chmod go-rwx "${DEST}" fi {{- end }} + {{- end }} } cleanup() { @@ -53,7 +57,9 @@ cleanup() { rm -f "/host{{ $dest }}" {{- end }} {{ range $key, $val := .Values.conf }} - rm -f "/host/{{ $val.file }}" + {{- if $val.file }} + rm -f "/host/etc/kubernetes/apiserver/{{ $val.file }}" + {{- end }} {{- end }} }