From 50dcfd79051fdcea983057f2343d51ca7a832b1d Mon Sep 17 00:00:00 2001 From: Moritz Sanft <58110325+msanft@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:51:23 +0200 Subject: [PATCH] bootstrapper: remove unnecessary stat (#3202) --- .../internal/kubernetes/k8sapi/k8sutil.go | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go b/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go index 2925cc44fd..19713e00eb 100644 --- a/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go +++ b/bootstrapper/internal/kubernetes/k8sapi/k8sutil.go @@ -137,14 +137,11 @@ func (k *KubernetesUtil) InitCluster( } // Create static pods directory for all nodes (the Kubelets on the worker nodes also expect the path to exist) - if _, err := os.Stat("/etc/kubernetes/manifests"); err == nil { - // If the node rebooted after the static pod directory was created, - // the existing directory needs to be removed before we can - // try to init the cluster again. - log.Info("Removing existing static Pod directory /etc/kubernetes/manifests") - if err := os.RemoveAll("/etc/kubernetes/manifests"); err != nil { - return nil, fmt.Errorf("removing static pods directory: %w", err) - } + // If the node rebooted after the static pod directory was created, + // the existing directory needs to be removed before we can + // try to init the cluster again. + if err := os.RemoveAll("/etc/kubernetes/manifests"); err != nil { + return nil, fmt.Errorf("removing static pods directory: %w", err) } log.Info("Creating static Pod directory /etc/kubernetes/manifests") if err := os.MkdirAll("/etc/kubernetes/manifests", os.ModePerm); err != nil { @@ -209,14 +206,11 @@ func (k *KubernetesUtil) JoinCluster(ctx context.Context, joinConfig []byte, log } // Create static pods directory for all nodes (the Kubelets on the worker nodes also expect the path to exist) - if _, err := os.Stat("/etc/kubernetes/manifests"); err == nil { - // If the node rebooted after the static pod directory was created, for example - // if a failure during an upgrade occurred, the existing directory needs to be - // removed before we can try to join the cluster again. - log.Info("Removing existing static Pod directory /etc/kubernetes/manifests") - if err := os.RemoveAll("/etc/kubernetes/manifests"); err != nil { - return fmt.Errorf("removing static pods directory: %w", err) - } + // If the node rebooted after the static pod directory was created, for example + // if a failure during an upgrade occurred, the existing directory needs to be + // removed before we can try to join the cluster again. + if err := os.RemoveAll("/etc/kubernetes/manifests"); err != nil { + return fmt.Errorf("removing static pods directory: %w", err) } log.Info("Creating static Pod directory /etc/kubernetes/manifests") if err := os.MkdirAll("/etc/kubernetes/manifests", os.ModePerm); err != nil {