Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/v1.7] Migrate AzureDisk CSI Node CRB if subject is csi-azuredisk-node-sa #2984

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/addons/ensure.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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