Skip to content

Commit

Permalink
Migrate AzureDisk CSI Node CRB if RoleRef is csi-azuredisk-node-sa (#…
Browse files Browse the repository at this point in the history
…2984)

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>
Co-authored-by: Marko Mudrinić <mudrinic.mare@gmail.com>
  • Loading branch information
kubermatic-bot and xmudrii committed Dec 18, 2023
1 parent 8c26cbb commit 5866144
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/addons/ensure.go
Expand Up @@ -354,7 +354,7 @@ func ensureCSIAddons(s *state.State, addonsToDeploy []addonAction) []addonAction
addonAction{
name: resources.AddonCSIAzureDisk,
supportFn: func() error {
return migrateAzureDiskCSIDriver(s)
return migrateAzureDiskCSI(s)
},
},
addonAction{
Expand Down
27 changes: 26 additions & 1 deletion pkg/addons/helpers.go
Expand Up @@ -29,6 +29,7 @@ import (

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
storagev1 "k8s.io/api/storage/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -152,10 +153,34 @@ func gceStandardStorageClass() *storagev1.StorageClass {
}
}

func migrateAzureDiskCSIDriver(s *state.State) error {
func migrateAzureDiskCSI(s *state.State) error {
if err := migrateAzureDiskNodeCRBIfLegacy(s); err != nil {
return err
}

return clientutil.DeleteIfExists(s.Context, s.DynamicClient, azureDiskCSIDriver())
}

func migrateAzureDiskNodeCRBIfLegacy(s *state.State) error {
crb := &rbacv1.ClusterRoleBinding{}
key := client.ObjectKey{
Name: "csi-azuredisk-node-secret-binding",
}
if err := s.DynamicClient.Get(s.Context, key, crb); err != nil {
if k8serrors.IsNotFound(err) {
return nil
}

return err
}

if crb.RoleRef.Name == "csi-azuredisk-node-secret-role" {
return clientutil.DeleteIfExists(s.Context, s.DynamicClient, crb)
}

return nil
}

func azureDiskCSIDriver() *storagev1.CSIDriver {
return &storagev1.CSIDriver{
ObjectMeta: metav1.ObjectMeta{
Expand Down

0 comments on commit 5866144

Please sign in to comment.