Make sure namespaces exists before starting migration
Also don't check for volume migration status if none are being migrated
@@ -112,6 +112,27 @@ func (m *MigrationController) Handle(ctx context.Context, event sdk.Event) error
case storkv1.MigrationStageInitial,
storkv1.MigrationStageVolumes:
+ // Make sure the namespaces exist
+ for _, ns := range migration.Spec.Namespaces {
+ _, err := k8s.Instance().GetNamespace(ns)
+ if err != nil {
+ migration.Status.Status = storkv1.MigrationStatusFailed
+ migration.Status.Stage = storkv1.MigrationStageFinal
+ err = fmt.Errorf("Error getting namespace %v: %v", ns, err)
+ logrus.Errorf(err.Error())
+ m.Recorder.Event(migration,
+ v1.EventTypeWarning,
+ string(storkv1.MigrationStatusFailed),
+ err.Error())
+ err = sdk.Update(migration)
+ if err != nil {
+ return err
+ }
+ return nil
+
+ }
+ }
+
err := m.migrateVolumes(migration)
if err != nil {
message := fmt.Sprintf("Error migrating volumes: %v", err)
@@ -172,6 +193,8 @@ func (m *MigrationController) migrateVolumes(migration *storkv1.Migration) error
}
}
+ // Skip checking status if no volumes are being migrated
+ if len(migration.Status.Volumes) != 0 {
// Now check the status
volumeInfos, err := m.Driver.GetMigrationStatus(migration)
if err != nil {
@@ -208,6 +231,7 @@ func (m *MigrationController) migrateVolumes(migration *storkv1.Migration) error
fmt.Sprintf("Volume %v migrated successfully", vInfo.Volume))
}
}
+ }
// If the migration hasn't failed move on to the next stage.
if migration.Status.Status != storkv1.MigrationStatusFailed {
