From 425553d390635816a942144f67c758b5d8526485 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Thu, 9 Nov 2017 11:02:12 +0000 Subject: [PATCH] kubernetes: better tolerate bad contents of /etc/kubeadm/kube-system.init/ Specifically ignore present-but-empty files entirely and ignore (but log) failure to apply any one file. Ignoring an empty file is useful because it means you can clobber a file which might be referenced from an images binds without needing to override those binds (since that generally means duplicating the whole lot which is annoying). Ignoring any failures to apply means the rest gets applied and the rest of the script (including untaint and the stamp file creation) still happen, resulting in a system where the admin just has to address the failures rather than the remaining updates. We touch a file to indicate failure generally plus one to indicate the specific yaml which failed to apply. Signed-off-by: Ian Campbell --- projects/kubernetes/kubernetes/kubeadm-init.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/projects/kubernetes/kubernetes/kubeadm-init.sh b/projects/kubernetes/kubernetes/kubeadm-init.sh index 87feee6f6..61530c671 100755 --- a/projects/kubernetes/kubernetes/kubeadm-init.sh +++ b/projects/kubernetes/kubernetes/kubeadm-init.sh @@ -11,9 +11,19 @@ else kubeadm init --skip-preflight-checks --kubernetes-version @KUBERNETES_VERSION@ $@ fi for i in /etc/kubeadm/kube-system.init/*.yaml ; do + n=$(basename "$i") if [ -e "$i" ] ; then - echo "Applying "$(basename "$i") - kubectl create -n kube-system -f "$i" + if [ ! -s "$i" ] ; then # ignore zero sized files + echo "Ignoring zero size file $n" + continue + fi + echo "Applying $n" + if ! kubectl create -n kube-system -f "$i" ; then + touch /var/lib/kubeadm/.kubeadm-init.sh-kube-system.init-failed + touch /var/lib/kubeadm/.kubeadm-init.sh-kube-system.init-"$n"-failed + echo "Failed to apply $n" + continue + fi fi done if [ -f /var/config/kubeadm/untaint-master ] ; then