From a13dbd0dd135a420969e73ed03faa6dbe0dad28a Mon Sep 17 00:00:00 2001 From: Sidney Shiba Date: Thu, 7 Jan 2021 13:13:31 -0600 Subject: [PATCH] Fixing AKS creation failure When the capz.kubeconfig file was missing, the creation of AKS cluster by the bootstrap container would fail when retrieving its kubeconfig file. The issue was that the container tries to delete an existing kubeconfig file and would fail if it didn't exist. The fix was to check if the kubeconfig file existed prior to deleting it. Change-Id: Ibf135a11ae1928fc69c35cacdf0e1339629027f2 --- bootstrap_capz/config/aks_cluster.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bootstrap_capz/config/aks_cluster.go b/bootstrap_capz/config/aks_cluster.go index 663316f..785c21a 100644 --- a/bootstrap_capz/config/aks_cluster.go +++ b/bootstrap_capz/config/aks_cluster.go @@ -136,10 +136,13 @@ func prepareAKSCluster(azConfig *AzureConfig, isCreate bool) error { kubeconfig := dstMount + "/" + kubeconfigFile // Delete existing Kubeconfig file, if any - err = os.Remove(kubeconfig) - if err != nil { - log.Printf("Failed to remove existing kubeconfig file %s.\n", kubeconfig) - return err + _, err = os.Stat(kubeconfig) + if err == nil { + err = os.Remove(kubeconfig) + if err != nil { + log.Printf("Failed to remove existing kubeconfig file %s.\n", kubeconfig) + return err + } } // Retrieving the Kubeconfig file for the cluster