make sure to delete image pull secrets on gcp auth addon disable

pull/12473/head
Sharif Elgamal 2021-09-14 13:12:07 -07:00
parent 28770a3848
commit 6acb65ca71
1 changed files with 20 additions and 1 deletions

View File

@ -99,7 +99,7 @@ func enableAddonGCPAuth(cfg *config.ClusterConfig) error {
} }
if creds.JSON == nil { if creds.JSON == nil {
out.WarningT("You have authenicated with a service account that does not have an associated JSON. The GCP Auth requires credentials with a JSON file to in order to continue. The image pull secret has been imported.") out.WarningT("You have authenticated with a service account that does not have an associated JSON. The GCP Auth requires credentials with a JSON file to in order to continue. The image pull secret has been imported.")
return nil return nil
} }
@ -333,6 +333,25 @@ func disableAddonGCPAuth(cfg *config.ClusterConfig) error {
if err != nil { if err != nil {
klog.Infof("error deleting secret: %v", err) klog.Infof("error deleting secret: %v", err)
} }
serviceaccounts := client.ServiceAccounts(n.Name)
salist, err := serviceaccounts.List(context.TODO(), metav1.ListOptions{})
if err != nil {
klog.Infof("error getting service accounts: %v", err)
return err
}
for _, sa := range salist.Items {
for i, ps := range sa.ImagePullSecrets {
if ps.Name == secretName {
sa.ImagePullSecrets = append(sa.ImagePullSecrets[:i], sa.ImagePullSecrets[i+1:]...)
_, err := serviceaccounts.Update(context.TODO(), &sa, metav1.UpdateOptions{})
if err != nil {
return err
}
break
}
}
}
} }
return nil return nil