Skip to content

Commit

Permalink
bootstrapper: remove unnecessary stat (#3202)
Browse files Browse the repository at this point in the history
  • Loading branch information
msanft authored Jun 25, 2024
1 parent dcb8cca commit 50dcfd7
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions bootstrapper/internal/kubernetes/k8sapi/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 50dcfd7

Please sign in to comment.