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

Properly annotate OpenStack PVs on CCM/CSI migration #1482

Merged
merged 1 commit into from
Aug 31, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pkg/tasks/ccm_csi_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
provisionedByAnnotation = "pv.kubernetes.io/provisioned-by"
provisionedByOpenStackInTreeCinder = "kubernetes.io/cinder"
provisionedByOpenStackCSICinder = "cinder.csi.openstack.org"
)

func validateExternalCloudProviderConfig(s *state.State) error {
if !s.Cluster.CloudProvider.External {
return errors.New(".cloudProvider.external must be enabled to start the migration")
Expand Down Expand Up @@ -210,3 +216,33 @@ func waitForStaticPodReady(s *state.State, timeout time.Duration, staticPodName,
return true, nil
})
}

func migrateOpenStackPVs(s *state.State) error {
if s.DynamicClient == nil {
return errors.New("dynamic client is not initialized")
}

s.Logger.Infof("Patching OpenStack PersistentVolumes with annotation \"%s=%s\"...", provisionedByAnnotation, provisionedByOpenStackCSICinder)

pvList := corev1.PersistentVolumeList{}
if err := s.DynamicClient.List(s.Context, &pvList, &client.ListOptions{}); err != nil {
return errors.Wrap(err, "failed to list persistentvolumes")
}

for i, pv := range pvList.Items {
if pv.Annotations[provisionedByAnnotation] == provisionedByOpenStackInTreeCinder {
if s.Verbose {
s.Logger.Debugf("Patching PersistentVolume \"%s/%s\"...", pv.Namespace, pv.Name)
}

oldPv := pv.DeepCopy()
pv.Annotations[provisionedByAnnotation] = provisionedByOpenStackCSICinder

if err := s.DynamicClient.Patch(s.Context, &pvList.Items[i], client.MergeFrom(oldPv)); err != nil {
return errors.Wrapf(err, "failed to patch persistnetvolume %q with annotation \"%s=%s\"", pv.Name, provisionedByAnnotation, provisionedByOpenStackCSICinder)
}
}
}

return nil
}
27 changes: 17 additions & 10 deletions pkg/tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,14 +474,21 @@ func WithCCMCSIMigration(t Tasks) Tasks {
Task{Fn: updateKubeletConfig, ErrMsg: "failed to update kubelet config"},
).
append(WithResources(nil)...).
append(Task{
Fn: func(s *state.State) error {
s.Logger.Warn("Now please rolling restart your machineDeployments to migrate to ccm/csi")
s.Logger.Warn("see more at: https://docs.kubermatic.com/kubeone/v1.3/cheat_sheets/rollout_machinedeployment/")
s.Logger.Warn("Once you're done, please run this command again with the '--complete' flag to finish migration")
return nil
},
ErrMsg: "failed to show next steps",
Predicate: func(s *state.State) bool { return s.Cluster.MachineController.Deploy && !s.CCMMigrationComplete },
})
append(
Task{
Fn: migrateOpenStackPVs,
ErrMsg: "failed to migrate openstack persistentvolumes",
Predicate: func(s *state.State) bool { return s.Cluster.CloudProvider.Openstack != nil },
},
Task{
Fn: func(s *state.State) error {
s.Logger.Warn("Now please rolling restart your machineDeployments to migrate to ccm/csi")
s.Logger.Warn("see more at: https://docs.kubermatic.com/kubeone/v1.3/cheat_sheets/rollout_machinedeployment/")
s.Logger.Warn("Once you're done, please run this command again with the '--complete' flag to finish migration")
return nil
},
ErrMsg: "failed to show next steps",
Predicate: func(s *state.State) bool { return s.Cluster.MachineController.Deploy && !s.CCMMigrationComplete },
},
)
}