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
This commit is contained in:
Sidney Shiba 2021-01-07 13:13:31 -06:00
parent 3ad2f936c4
commit a13dbd0dd1

View File

@ -136,11 +136,14 @@ func prepareAKSCluster(azConfig *AzureConfig, isCreate bool) error {
kubeconfig := dstMount + "/" + kubeconfigFile kubeconfig := dstMount + "/" + kubeconfigFile
// Delete existing Kubeconfig file, if any // Delete existing Kubeconfig file, if any
_, err = os.Stat(kubeconfig)
if err == nil {
err = os.Remove(kubeconfig) err = os.Remove(kubeconfig)
if err != nil { if err != nil {
log.Printf("Failed to remove existing kubeconfig file %s.\n", kubeconfig) log.Printf("Failed to remove existing kubeconfig file %s.\n", kubeconfig)
return err return err
} }
}
// Retrieving the Kubeconfig file for the cluster // Retrieving the Kubeconfig file for the cluster
err = execute(az, aks, getCredentials, err = execute(az, aks, getCredentials,