From 4c429b58aa1b20659c5f7b64a85e2144cee20105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergen=20Yal=C3=A7=C4=B1n?= Date: Thu, 20 Jul 2023 14:17:16 +0200 Subject: [PATCH 1/4] Add description field to the migration plan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergen Yalçın --- pkg/migration/api_steps.go | 30 ++++++--- pkg/migration/configurationmetadata_steps.go | 63 ++++++++++++------- pkg/migration/plan_steps.go | 12 ++-- .../configurationv1_migration_plan.yaml | 6 ++ .../configurationv1_pkg_migration_plan.yaml | 23 +++++++ .../configurationv1alpha1_migration_plan.yaml | 6 ++ .../plan/generated/migration_plan.yaml | 10 +++ .../generated/providerv1_migration_plan.yaml | 11 ++++ pkg/migration/types.go | 2 + 9 files changed, 128 insertions(+), 35 deletions(-) diff --git a/pkg/migration/api_steps.go b/pkg/migration/api_steps.go index de622f61..1848ef62 100644 --- a/pkg/migration/api_steps.go +++ b/pkg/migration/api_steps.go @@ -278,34 +278,44 @@ func (pg *PlanGenerator) stepAPI(s step) *Step { // nolint:gocyclo // all steps pg.Plan.Spec.stepMap[stepKey] = &Step{} switch s { // nolint:exhaustive case stepPauseManaged: - setPatchStep("pause-managed", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("pause-managed", "Adding pause annotation to the Managed Resource so that the Managed Resource is not reconciled during migration", + pg.Plan.Spec.stepMap[stepKey]) case stepPauseComposites: - setPatchStep("pause-composites", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("pause-composites", "Adding pause annotation to the Composite Resource so that the Composite Resource is not reconciled during migration", + pg.Plan.Spec.stepMap[stepKey]) case stepCreateNewManaged: - setApplyStep("create-new-managed", pg.Plan.Spec.stepMap[stepKey]) + setApplyStep("create-new-managed", "Creating the Managed Resource that has the new API", + pg.Plan.Spec.stepMap[stepKey]) case stepNewCompositions: - setApplyStep("new-compositions", pg.Plan.Spec.stepMap[stepKey]) + setApplyStep("new-compositions", "Creating the Compositions that have the new API", + pg.Plan.Spec.stepMap[stepKey]) case stepEditComposites: - setPatchStep("edit-composites", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("edit-composites", "Editing the Composite Resources with the correct references", + pg.Plan.Spec.stepMap[stepKey]) case stepEditClaims: - setPatchStep("edit-claims", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("edit-claims", "Editing the Claims with the correct references", + pg.Plan.Spec.stepMap[stepKey]) case stepDeletionPolicyOrphan: - setPatchStep("deletion-policy-orphan", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("deletion-policy-orphan", "Setting Deletion Policy to Orphan before deleting old Managed Resource so that physical resource is not deleted", + pg.Plan.Spec.stepMap[stepKey]) case stepDeleteOldManaged: - setDeleteStep("delete-old-managed", pg.Plan.Spec.stepMap[stepKey]) + setDeleteStep("delete-old-managed", "Deleting the old Managed Resource", + pg.Plan.Spec.stepMap[stepKey]) case stepStartManaged: - setPatchStep("start-managed", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("start-managed", "Removing the pause annotation to start the reconciliation of the newly created Managed Resource", + pg.Plan.Spec.stepMap[stepKey]) case stepStartComposites: - setPatchStep("start-composites", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("start-composites", "Removing the pause annotation to start the reconciliation of the newly created Composite Resource", + pg.Plan.Spec.stepMap[stepKey]) default: panic(fmt.Sprintf(errInvalidStepFmt, s)) } diff --git a/pkg/migration/configurationmetadata_steps.go b/pkg/migration/configurationmetadata_steps.go index 3cb9b626..48c8adc5 100644 --- a/pkg/migration/configurationmetadata_steps.go +++ b/pkg/migration/configurationmetadata_steps.go @@ -125,47 +125,68 @@ func (pg *PlanGenerator) stepConfigurationWithSubStep(s step, newSubStep bool) * pg.Plan.Spec.stepMap[stepKey] = &Step{} switch s { // nolint:gocritic,exhaustive case stepOrphanMRs: - setPatchStep("deletion-policy-orphan", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("deletion-policy-orphan", "Setting the deletion policies of Managed Resources to Orphan as a precaution against any unexpected problems that may occur during migration", + pg.Plan.Spec.stepMap[stepKey]) case stepRevertOrphanMRs: - setPatchStep("deletion-policy-delete", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("deletion-policy-delete", "Setting the deletion policies of Managed Resources whose deletion policy is set to Orphan at the beginning of the migration, to Delete again", + pg.Plan.Spec.stepMap[stepKey]) case stepNewFamilyProvider: - setApplyStep("new-ssop", pg.Plan.Spec.stepMap[stepKey]) + setApplyStep("new-ssop", "Installing the new family provider", + pg.Plan.Spec.stepMap[stepKey]) case stepNewServiceScopedProvider: - setApplyStep("new-ssop", pg.Plan.Spec.stepMap[stepKey]) + setApplyStep("new-ssop", "Installing the new service scoped providers", + pg.Plan.Spec.stepMap[stepKey]) case stepConfigurationPackageDisableDepResolution: - setPatchStep("disable-dependency-resolution", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("disable-dependency-resolution", "Setting the value of skipDependencyResolution field to true so that dependencies in the configuration package are not resolved automatically", + pg.Plan.Spec.stepMap[stepKey]) case stepConfigurationPackageEnableDepResolution: - setPatchStep("enable-dependency-resolution", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("enable-dependency-resolution", "Setting the value of skipDependencyResolution field in the configuration package back to false", + pg.Plan.Spec.stepMap[stepKey]) case stepEditConfigurationPackage: - setPatchStep("edit-configuration-package", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("edit-configuration-package", "Setting the configuration package reference to new one", + pg.Plan.Spec.stepMap[stepKey]) case stepEditPackageLock: - setPatchStep("edit-package-lock", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("edit-package-lock", "Deleting configuration package dependency from Lock resource", + pg.Plan.Spec.stepMap[stepKey]) case stepDeleteMonolithicProvider: - setDeleteStep("delete-monolithic-provider", pg.Plan.Spec.stepMap[stepKey]) + setDeleteStep("delete-monolithic-provider", "Deleting monolithic provider", + pg.Plan.Spec.stepMap[stepKey]) case stepActivateFamilyProviderRevision: - setPatchStep("activate-ssop", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("activate-ssop", "Activating the new family provider after deletion monolithic one", + pg.Plan.Spec.stepMap[stepKey]) case stepActivateServiceScopedProviderRevision: - setPatchStep("activate-ssop", pg.Plan.Spec.stepMap[stepKey]) + setPatchStep("activate-ssop", "Activating the new service scoped providers", + pg.Plan.Spec.stepMap[stepKey]) case stepEditConfigurationMetadata: - setExecStep("edit-configuration-metadata", pg.Plan.Spec.stepMap[stepKey]) + setExecStep("edit-configuration-metadata", "Editing the Configuration Meta resource with new family provider references", + pg.Plan.Spec.stepMap[stepKey]) case stepBackupMRs: - setExecStep("backup-managed-resources", pg.Plan.Spec.stepMap[stepKey]) + setExecStep("backup-managed-resources", "Backing up Managed Resources", + pg.Plan.Spec.stepMap[stepKey]) case stepBackupComposites: - setExecStep("backup-composite-resources", pg.Plan.Spec.stepMap[stepKey]) + setExecStep("backup-composite-resources", "Backing up Composite Resources", + pg.Plan.Spec.stepMap[stepKey]) case stepBackupClaims: - setExecStep("backup-claim-resources", pg.Plan.Spec.stepMap[stepKey]) + setExecStep("backup-claim-resources", "Backing up Claims", + pg.Plan.Spec.stepMap[stepKey]) case stepCheckHealthFamilyProvider: - setExecStep("wait-for-healthy", pg.Plan.Spec.stepMap[stepKey]) + setExecStep("wait-for-healthy", "Checking health of new family provider", + pg.Plan.Spec.stepMap[stepKey]) case stepCheckHealthNewServiceScopedProvider: - setExecStep("wait-for-healthy", pg.Plan.Spec.stepMap[stepKey]) + setExecStep("wait-for-healthy", "Checking health of new service scoped provider", + pg.Plan.Spec.stepMap[stepKey]) case stepCheckInstallationFamilyProviderRevision: - setExecStep("wait-for-installed", pg.Plan.Spec.stepMap[stepKey]) + setExecStep("wait-for-installed", "Checking installation of new family provider", + pg.Plan.Spec.stepMap[stepKey]) case stepCheckInstallationServiceScopedProviderRevision: - setExecStep("wait-for-installed", pg.Plan.Spec.stepMap[stepKey]) + setExecStep("wait-for-installed", "Checking installation of new service scoped provider", + pg.Plan.Spec.stepMap[stepKey]) case stepBuildConfiguration: - setExecStep("build-configuration", pg.Plan.Spec.stepMap[stepKey]) + setExecStep("build-configuration", "Building the new configuration pkg", + pg.Plan.Spec.stepMap[stepKey]) case stepPushConfiguration: - setExecStep("push-configuration", pg.Plan.Spec.stepMap[stepKey]) + setExecStep("push-configuration", "Pushing the new configuration pkg", + pg.Plan.Spec.stepMap[stepKey]) default: panic(fmt.Sprintf(errInvalidStepFmt, s)) } diff --git a/pkg/migration/plan_steps.go b/pkg/migration/plan_steps.go index e6e0e460..fb78a213 100644 --- a/pkg/migration/plan_steps.go +++ b/pkg/migration/plan_steps.go @@ -36,20 +36,22 @@ const ( errInvalidStepFmt = "invalid step ID: %d" ) -func setApplyStep(name string, s *Step) { +func setApplyStep(name, description string, s *Step) { s.Name = name s.Type = StepTypeApply s.Apply = &ApplyStep{} + s.Description = description } -func setPatchStep(name string, s *Step) { +func setPatchStep(name, description string, s *Step) { s.Name = name s.Type = StepTypePatch s.Patch = &PatchStep{} s.Patch.Type = PatchTypeMerge + s.Description = description } -func setDeleteStep(name string, s *Step) { +func setDeleteStep(name, description string, s *Step) { s.Name = name s.Type = StepTypeDelete deletePolicy := FinalizerPolicyRemove @@ -58,14 +60,16 @@ func setDeleteStep(name string, s *Step) { FinalizerPolicy: &deletePolicy, }, } + s.Description = description } -func setExecStep(name string, s *Step) { +func setExecStep(name, description string, s *Step) { s.Name = name s.Type = StepTypeExec s.Exec = &ExecStep{ Command: "sh", } + s.Description = description } func (pg *PlanGenerator) commitSteps() { diff --git a/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml b/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml index e1dc326e..3a2cb9d4 100644 --- a/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml @@ -9,6 +9,7 @@ spec: manualExecution: - sh -c "kubectl get managed -o yaml > backup/managed-resources.yaml" type: Exec + description: "Backing up Managed Resources" - exec: command: sh @@ -19,6 +20,7 @@ spec: manualExecution: - sh -c "kubectl get composite -o yaml > backup/composite-resources.yaml" type: Exec + description: "Backing up Composite Resources" - exec: command: sh @@ -29,6 +31,7 @@ spec: manualExecution: - sh -c "kubectl get claim --all-namespaces -o yaml > backup/claim-resources.yaml" type: Exec + description: "Backing up Claims" - exec: command: sh @@ -39,6 +42,7 @@ spec: manualExecution: - sh -c "cp edit-configuration-metadata/platform-ref-aws.configurations.meta.pkg.crossplane.io_v1.yaml testdata/plan/configurationv1.yaml" type: Exec + description: "Editing the Configuration Meta resource with new family provider references" - exec: command: sh @@ -49,6 +53,7 @@ spec: manualExecution: - sh -c "up xpkg build --package-root={{PKG_ROOT}} --examples-root={{EXAMPLES_ROOT}} -o {{PKG_PATH}}" type: Exec + description: "Building the new configuration pkg" - exec: command: sh @@ -59,5 +64,6 @@ spec: manualExecution: - sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}" type: Exec + description: "Pushing the new configuration pkg" version: 0.1.0 diff --git a/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml b/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml index 22b05730..eeab78a5 100644 --- a/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml @@ -9,6 +9,7 @@ spec: manualExecution: - sh -c "kubectl get managed -o yaml > backup/managed-resources.yaml" type: Exec + description: "Backing up Managed Resources" - exec: command: sh @@ -19,6 +20,7 @@ spec: manualExecution: - sh -c "kubectl get composite -o yaml > backup/composite-resources.yaml" type: Exec + description: "Backing up Composite Resources" - exec: command: sh @@ -29,6 +31,7 @@ spec: manualExecution: - sh -c "kubectl get claim --all-namespaces -o yaml > backup/claim-resources.yaml" type: Exec + description: "Backing up Claims" - patch: type: merge @@ -38,6 +41,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f deletion-policy-orphan/sample-vpc.vpcs.fakesourceapi_v1alpha1.yaml --patch-file deletion-policy-orphan/sample-vpc.vpcs.fakesourceapi_v1alpha1.yaml" type: Patch + description: "Setting the deletion policies of Managed Resources to Orphan as a precaution against any unexpected problems that may occur during migration" - apply: files: @@ -46,6 +50,7 @@ spec: manualExecution: - "kubectl apply -f new-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml" type: Apply + description: "Installing the new family provider" - exec: command: sh @@ -56,6 +61,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-family-aws --for condition=Healthy" type: Exec + description: "Checking health of new family provider" - apply: files: @@ -66,6 +72,7 @@ spec: - "kubectl apply -f new-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml" - "kubectl apply -f new-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml" type: Apply + description: "Installing the new service scoped providers" - exec: command: sh @@ -76,6 +83,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-ec2 --for condition=Healthy" type: Exec + description: "Checking health of new service scoped provider" - exec: command: sh @@ -86,6 +94,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-eks --for condition=Healthy" type: Exec + description: "Checking health of new service scoped provider" - patch: type: merge @@ -95,6 +104,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f disable-dependency-resolution/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml --patch-file disable-dependency-resolution/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml" type: Patch + description: "Setting the value of skipDependencyResolution field to true so that dependencies in the configuration package are not resolved automatically" - patch: type: merge @@ -104,6 +114,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f edit-package-lock/lock.locks.pkg.crossplane.io_v1beta1.yaml --patch-file edit-package-lock/lock.locks.pkg.crossplane.io_v1beta1.yaml" type: Patch + description: "Deleting configuration package dependency from Lock resource" - delete: options: @@ -117,6 +128,7 @@ spec: manualExecution: - "kubectl delete Provider.pkg.crossplane.io provider-aws" type: Delete + description: "Deleting monolithic provider" - patch: type: merge @@ -126,6 +138,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f activate-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml" type: Patch + description: "Activating the new family provider after deletion monolithic one" - exec: command: sh @@ -136,6 +149,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-family-aws --for condition=Installed" type: Exec + description: "Checking installation of new family provider" - patch: type: merge @@ -147,6 +161,7 @@ spec: - "kubectl patch --type='merge' -f activate-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml" - "kubectl patch --type='merge' -f activate-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml" type: Patch + description: "Activating the new service scoped providers" - exec: command: sh @@ -157,6 +172,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-ec2 --for condition=Installed" type: Exec + description: "Checking installation of new service scoped provider" - exec: command: sh @@ -167,6 +183,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-eks --for condition=Installed" type: Exec + description: "Checking installation of new service scoped provider" - exec: command: sh @@ -177,6 +194,7 @@ spec: manualExecution: - sh -c "cp edit-configuration-metadata/platform-ref-aws.configurations.meta.pkg.crossplane.io_v1.yaml testdata/plan/configurationv1.yaml" type: Exec + description: "Editing the Configuration Meta resource with new family provider references" - exec: command: sh @@ -187,6 +205,7 @@ spec: manualExecution: - sh -c "up xpkg build --package-root={{PKG_ROOT}} --examples-root={{EXAMPLES_ROOT}} -o {{PKG_PATH}}" type: Exec + description: "Building the new configuration pkg" - exec: command: sh @@ -197,6 +216,7 @@ spec: manualExecution: - sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}" type: Exec + description: "Pushing the new configuration pkg" - patch: type: merge @@ -206,6 +226,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f edit-configuration-package/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml --patch-file edit-configuration-package/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml" type: Patch + description: "Setting the configuration package reference to new one" - patch: type: merge @@ -215,6 +236,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f enable-dependency-resolution/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml --patch-file enable-dependency-resolution/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml" type: Patch + description: "Setting the value of skipDependencyResolution field in the configuration package back to false" - patch: type: merge @@ -224,5 +246,6 @@ spec: manualExecution: - "kubectl patch --type='merge' -f deletion-policy-delete/sample-vpc.vpcs.fakesourceapi_v1alpha1.yaml --patch-file deletion-policy-delete/sample-vpc.vpcs.fakesourceapi_v1alpha1.yaml" type: Patch + description: "Setting the deletion policies of Managed Resources whose deletion policy is set to Orphan at the beginning of the migration, to Delete again" version: 0.1.0 diff --git a/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml b/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml index 2903ad87..e81ae923 100644 --- a/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml @@ -9,6 +9,7 @@ spec: manualExecution: - sh -c "kubectl get managed -o yaml > backup/managed-resources.yaml" type: Exec + description: "Backing up Managed Resources" - exec: command: sh @@ -19,6 +20,7 @@ spec: manualExecution: - sh -c "kubectl get composite -o yaml > backup/composite-resources.yaml" type: Exec + description: "Backing up Composite Resources" - exec: command: sh @@ -29,6 +31,7 @@ spec: manualExecution: - sh -c "kubectl get claim --all-namespaces -o yaml > backup/claim-resources.yaml" type: Exec + description: "Backing up Claims" - exec: command: sh @@ -39,6 +42,7 @@ spec: manualExecution: - sh -c "cp edit-configuration-metadata/platform-ref-aws.configurations.meta.pkg.crossplane.io_v1alpha1.yaml testdata/plan/configurationv1alpha1.yaml" type: Exec + description: "Editing the Configuration Meta resource with new family provider references" - exec: command: sh @@ -49,6 +53,7 @@ spec: manualExecution: - sh -c "up xpkg build --package-root={{PKG_ROOT}} --examples-root={{EXAMPLES_ROOT}} -o {{PKG_PATH}}" type: Exec + description: "Building the new configuration pkg" - exec: command: sh @@ -59,5 +64,6 @@ spec: manualExecution: - sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}" type: Exec + description: "Pushing the new configuration pkg" version: 0.1.0 diff --git a/pkg/migration/testdata/plan/generated/migration_plan.yaml b/pkg/migration/testdata/plan/generated/migration_plan.yaml index e55ca631..4ee72363 100644 --- a/pkg/migration/testdata/plan/generated/migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/migration_plan.yaml @@ -8,6 +8,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f pause-managed/sample-vpc.vpcs.fakesourceapi.yaml --patch-file pause-managed/sample-vpc.vpcs.fakesourceapi.yaml" type: Patch + description: "Adding pause annotation to the Managed Resource so that the Managed Resource is not reconciled during migration" - patch: type: merge @@ -17,6 +18,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f pause-composites/my-resource-dwjgh.xmyresources.test.com.yaml --patch-file pause-composites/my-resource-dwjgh.xmyresources.test.com.yaml" type: Patch + description: "Adding pause annotation to the Composite Resource so that the Composite Resource is not reconciled during migration" - apply: files: @@ -25,6 +27,7 @@ spec: manualExecution: - "kubectl apply -f create-new-managed/sample-vpc.vpcs.faketargetapi.yaml" type: Apply + description: "Creating the Managed Resource that has the new API" - apply: files: @@ -33,6 +36,7 @@ spec: manualExecution: - "kubectl apply -f new-compositions/example-migrated.compositions.apiextensions.crossplane.io.yaml" type: Apply + description: "Creating the Compositions that have the new API" - patch: type: merge @@ -42,6 +46,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f edit-composites/my-resource-dwjgh.xmyresources.test.com.yaml --patch-file edit-composites/my-resource-dwjgh.xmyresources.test.com.yaml" type: Patch + description: "Editing the Composite Resources with the correct references" - patch: type: merge @@ -51,6 +56,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f edit-claims/my-resource.myresources.test.com.yaml --patch-file edit-claims/my-resource.myresources.test.com.yaml" type: Patch + description: "Editing the Claims with the correct references" - patch: type: merge @@ -60,6 +66,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f deletion-policy-orphan/sample-vpc.vpcs.fakesourceapi.yaml --patch-file deletion-policy-orphan/sample-vpc.vpcs.fakesourceapi.yaml" type: Patch + description: "Setting Deletion Policy to Orphan before deleting old Managed Resource so that physical resource is not deleted" - delete: options: @@ -73,6 +80,7 @@ spec: manualExecution: - "kubectl delete VPC.fakesourceapi sample-vpc" type: Delete + description: "Deleting the old Managed Resource" - patch: type: merge @@ -82,6 +90,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f start-managed/sample-vpc.vpcs.faketargetapi.yaml --patch-file start-managed/sample-vpc.vpcs.faketargetapi.yaml" type: Patch + description: "Removing the pause annotation to start the reconciliation of the newly created Managed Resource" - patch: type: merge @@ -91,5 +100,6 @@ spec: manualExecution: - "kubectl patch --type='merge' -f start-composites/my-resource-dwjgh.xmyresources.test.com.yaml --patch-file start-composites/my-resource-dwjgh.xmyresources.test.com.yaml" type: Patch + description: "Removing the pause annotation to start the reconciliation of the newly created Composite Resource" version: 0.1.0 \ No newline at end of file diff --git a/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml b/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml index 7cfa9a85..00dc0efe 100644 --- a/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml @@ -7,6 +7,7 @@ spec: manualExecution: - "kubectl apply -f new-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml" type: Apply + description: "Installing the new family provider" - exec: command: sh @@ -17,6 +18,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-family-aws --for condition=Healthy" type: Exec + description: "Checking health of new family provider" - apply: files: @@ -27,6 +29,7 @@ spec: - "kubectl apply -f new-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml" - "kubectl apply -f new-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml" type: Apply + description: "Installing the new service scoped providers" - exec: command: sh @@ -37,6 +40,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-ec2 --for condition=Healthy" type: Exec + description: "Checking health of new service scoped provider" - exec: command: sh @@ -47,6 +51,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-eks --for condition=Healthy" type: Exec + description: "Checking health of new service scoped provider" - delete: options: @@ -60,6 +65,7 @@ spec: manualExecution: - "kubectl delete Provider.pkg.crossplane.io provider-aws" type: Delete + description: "Deleting monolithic provider" - patch: type: merge @@ -69,6 +75,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f activate-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml" type: Patch + description: "Activating the new family provider after deletion monolithic one" - exec: command: sh @@ -79,6 +86,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-family-aws --for condition=Installed" type: Exec + description: "Checking installation of new family provider" - patch: type: merge @@ -90,6 +98,7 @@ spec: - "kubectl patch --type='merge' -f activate-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml" - "kubectl patch --type='merge' -f activate-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml" type: Patch + description: "Activating the new service scoped providers" - exec: command: sh @@ -100,6 +109,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-ec2 --for condition=Installed" type: Exec + description: "Checking installation of new service scoped provider" - exec: command: sh @@ -110,5 +120,6 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-eks --for condition=Installed" type: Exec + description: "Checking installation of new service scoped provider" version: 0.1.0 diff --git a/pkg/migration/types.go b/pkg/migration/types.go index 40c4ad88..1d78e5a0 100644 --- a/pkg/migration/types.go +++ b/pkg/migration/types.go @@ -78,6 +78,8 @@ const ( type Step struct { // Name is the name of this Step Name string `json:"name"` + // Description is description of the Step. + Description string // Type is the type of this Step. // Can be one of Apply, Delete, etc. Type StepType `json:"type"` From aee87f752339016470757121c41e8e308b6e7358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergen=20Yal=C3=A7=C4=B1n?= Date: Fri, 21 Jul 2023 12:12:56 +0200 Subject: [PATCH 2/4] Support for executing plan from a specified step MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergen Yalçın --- pkg/migration/plan_executor.go | 18 ++++++++++++++---- pkg/migration/plan_generator_test.go | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/migration/plan_executor.go b/pkg/migration/plan_executor.go index fc720b23..17c53e90 100644 --- a/pkg/migration/plan_executor.go +++ b/pkg/migration/plan_executor.go @@ -26,9 +26,11 @@ const ( // PlanExecutor drives the execution of a plan's steps and // uses the configured `executors` to execute those steps. type PlanExecutor struct { - executors []Executor - plan Plan - callback ExecutorCallback + executors []Executor + plan Plan + callback ExecutorCallback + LastSuccessfulStep int + StartIndex int } // Action represents an action to be taken by the PlanExecutor. @@ -69,6 +71,12 @@ func WithExecutorCallback(cb ExecutorCallback) PlanExecutorOption { } } +func WithStartIndex(startIndex int) PlanExecutorOption { + return func(pe *PlanExecutor) { + pe.StartIndex = startIndex + } +} + // ExecutorCallback is the interface for the callback implementations // to be notified while executing each Step of a migration Plan. type ExecutorCallback interface { @@ -103,7 +111,7 @@ func NewPlanExecutor(plan Plan, executors []Executor, opts ...PlanExecutorOption func (pe *PlanExecutor) Execute() error { //nolint:gocyclo // easier to follow this way ctx := make(map[string]any) - for i := 0; i < len(pe.plan.Spec.Steps); i++ { + for i := pe.StartIndex; i < len(pe.plan.Spec.Steps); i++ { var r CallbackResult if pe.callback != nil { r = pe.callback.StepToExecute(pe.plan.Spec.Steps[i], i) @@ -111,6 +119,7 @@ func (pe *PlanExecutor) Execute() error { //nolint:gocyclo // easier to follow t case ActionCancel: return nil case ActionSkip: + pe.LastSuccessfulStep = i continue case ActionContinue, ActionRepeat: } @@ -124,6 +133,7 @@ func (pe *PlanExecutor) Execute() error { //nolint:gocyclo // easier to follow t } } else if pe.callback != nil { r = pe.callback.StepSucceeded(pe.plan.Spec.Steps[i], i, diag) + pe.LastSuccessfulStep = i } switch r.Action { diff --git a/pkg/migration/plan_generator_test.go b/pkg/migration/plan_generator_test.go index a63a2c2d..fdeae76d 100644 --- a/pkg/migration/plan_generator_test.go +++ b/pkg/migration/plan_generator_test.go @@ -293,7 +293,7 @@ func TestGeneratePlan(t *testing.T) { if err != nil { t.Fatalf("Failed to load plan file from path %s: %v", tt.want.migrationPlanPath, err) } - if diff := cmp.Diff(p, &pg.Plan, cmpopts.IgnoreUnexported(Spec{})); diff != "" { + if diff := cmp.Diff(p, &pg.Plan, cmpopts.IgnoreUnexported(Plan{}, Spec{})); diff != "" { t.Errorf("GeneratePlan(): -wantPlan, +gotPlan: %s", diff) } // compare generated migration files with the expected ones From 32ec7197777ece5dcb83003b187cf53eb1044936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergen=20Yal=C3=A7=C4=B1n?= Date: Mon, 24 Jul 2023 17:10:16 +0200 Subject: [PATCH 3/4] Change the descriptions as suggested MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergen Yalçın --- pkg/migration/configurationmetadata_steps.go | 34 +++++++++--------- pkg/migration/plan_executor.go | 2 ++ .../configurationv1_migration_plan.yaml | 8 ++--- .../configurationv1_pkg_migration_plan.yaml | 36 +++++++++---------- .../configurationv1alpha1_migration_plan.yaml | 8 ++--- .../generated/providerv1_migration_plan.yaml | 18 +++++----- 6 files changed, 54 insertions(+), 52 deletions(-) diff --git a/pkg/migration/configurationmetadata_steps.go b/pkg/migration/configurationmetadata_steps.go index 48c8adc5..a9bc8421 100644 --- a/pkg/migration/configurationmetadata_steps.go +++ b/pkg/migration/configurationmetadata_steps.go @@ -128,37 +128,37 @@ func (pg *PlanGenerator) stepConfigurationWithSubStep(s step, newSubStep bool) * setPatchStep("deletion-policy-orphan", "Setting the deletion policies of Managed Resources to Orphan as a precaution against any unexpected problems that may occur during migration", pg.Plan.Spec.stepMap[stepKey]) case stepRevertOrphanMRs: - setPatchStep("deletion-policy-delete", "Setting the deletion policies of Managed Resources whose deletion policy is set to Orphan at the beginning of the migration, to Delete again", + setPatchStep("deletion-policy-delete", "Setting the deletion policies of Managed Resources whose deletion policy had been set to Orphan at the beginning of the migration process, back to Delete", pg.Plan.Spec.stepMap[stepKey]) case stepNewFamilyProvider: - setApplyStep("new-ssop", "Installing the new family provider", + setApplyStep("new-ssop", "Installing the new family config provider", pg.Plan.Spec.stepMap[stepKey]) case stepNewServiceScopedProvider: - setApplyStep("new-ssop", "Installing the new service scoped providers", + setApplyStep("new-ssop", "Installing the new family resource providers", pg.Plan.Spec.stepMap[stepKey]) case stepConfigurationPackageDisableDepResolution: - setPatchStep("disable-dependency-resolution", "Setting the value of skipDependencyResolution field to true so that dependencies in the configuration package are not resolved automatically", + setPatchStep("disable-dependency-resolution", "Setting the value of spec.skipDependencyResolution field to true so that dependencies of the Crossplane Configuration package are not resolved automatically, in preparation of deleting the monolithic provider packages", pg.Plan.Spec.stepMap[stepKey]) case stepConfigurationPackageEnableDepResolution: - setPatchStep("enable-dependency-resolution", "Setting the value of skipDependencyResolution field in the configuration package back to false", + setPatchStep("enable-dependency-resolution", "Setting the value of spec.skipDependencyResolution field in the Configuration package back to false", pg.Plan.Spec.stepMap[stepKey]) case stepEditConfigurationPackage: - setPatchStep("edit-configuration-package", "Setting the configuration package reference to new one", + setPatchStep("edit-configuration-package", "Setting the Configuration package reference (spec.package) to the new one", pg.Plan.Spec.stepMap[stepKey]) case stepEditPackageLock: - setPatchStep("edit-package-lock", "Deleting configuration package dependency from Lock resource", + setPatchStep("edit-package-lock", "Deleting the Configuration package dependency from the Lock resource in preparation of deleting the monolithic provider packages", pg.Plan.Spec.stepMap[stepKey]) case stepDeleteMonolithicProvider: - setDeleteStep("delete-monolithic-provider", "Deleting monolithic provider", + setDeleteStep("delete-monolithic-provider", "Deleting the monolithic provider package", pg.Plan.Spec.stepMap[stepKey]) case stepActivateFamilyProviderRevision: - setPatchStep("activate-ssop", "Activating the new family provider after deletion monolithic one", + setPatchStep("activate-ssop", "Activating the new family config provider after the deletion of the monolithic one", pg.Plan.Spec.stepMap[stepKey]) case stepActivateServiceScopedProviderRevision: - setPatchStep("activate-ssop", "Activating the new service scoped providers", + setPatchStep("activate-ssop", "Activating the new family resource providers", pg.Plan.Spec.stepMap[stepKey]) case stepEditConfigurationMetadata: - setExecStep("edit-configuration-metadata", "Editing the Configuration Meta resource with new family provider references", + setExecStep("edit-configuration-metadata", "Replacing the monolithic provider dependencies in the Configuration metadata with references to the new family providers", pg.Plan.Spec.stepMap[stepKey]) case stepBackupMRs: setExecStep("backup-managed-resources", "Backing up Managed Resources", @@ -167,25 +167,25 @@ func (pg *PlanGenerator) stepConfigurationWithSubStep(s step, newSubStep bool) * setExecStep("backup-composite-resources", "Backing up Composite Resources", pg.Plan.Spec.stepMap[stepKey]) case stepBackupClaims: - setExecStep("backup-claim-resources", "Backing up Claims", + setExecStep("backup-claim-resources", "Backing up Claims from all namespaces", pg.Plan.Spec.stepMap[stepKey]) case stepCheckHealthFamilyProvider: - setExecStep("wait-for-healthy", "Checking health of new family provider", + setExecStep("wait-for-healthy", "Checking the health of new family config provider", pg.Plan.Spec.stepMap[stepKey]) case stepCheckHealthNewServiceScopedProvider: - setExecStep("wait-for-healthy", "Checking health of new service scoped provider", + setExecStep("wait-for-healthy", "Checking health of new family resource provider", pg.Plan.Spec.stepMap[stepKey]) case stepCheckInstallationFamilyProviderRevision: - setExecStep("wait-for-installed", "Checking installation of new family provider", + setExecStep("wait-for-installed", "Checking the installation of new family config provider", pg.Plan.Spec.stepMap[stepKey]) case stepCheckInstallationServiceScopedProviderRevision: setExecStep("wait-for-installed", "Checking installation of new service scoped provider", pg.Plan.Spec.stepMap[stepKey]) case stepBuildConfiguration: - setExecStep("build-configuration", "Building the new configuration pkg", + setExecStep("build-configuration", "Building the new Configuration package using up", pg.Plan.Spec.stepMap[stepKey]) case stepPushConfiguration: - setExecStep("push-configuration", "Pushing the new configuration pkg", + setExecStep("push-configuration", "Pushing the new Configuration package", pg.Plan.Spec.stepMap[stepKey]) default: panic(fmt.Sprintf(errInvalidStepFmt, s)) diff --git a/pkg/migration/plan_executor.go b/pkg/migration/plan_executor.go index 17c53e90..5be2f4aa 100644 --- a/pkg/migration/plan_executor.go +++ b/pkg/migration/plan_executor.go @@ -71,6 +71,8 @@ func WithExecutorCallback(cb ExecutorCallback) PlanExecutorOption { } } +// WithStartIndex configures a StartIndex for a PlanExecutor +// to modify the starting index of the execution func WithStartIndex(startIndex int) PlanExecutorOption { return func(pe *PlanExecutor) { pe.StartIndex = startIndex diff --git a/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml b/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml index 3a2cb9d4..72af750a 100644 --- a/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml @@ -31,7 +31,7 @@ spec: manualExecution: - sh -c "kubectl get claim --all-namespaces -o yaml > backup/claim-resources.yaml" type: Exec - description: "Backing up Claims" + description: "Backing up Claims from all namespaces" - exec: command: sh @@ -42,7 +42,7 @@ spec: manualExecution: - sh -c "cp edit-configuration-metadata/platform-ref-aws.configurations.meta.pkg.crossplane.io_v1.yaml testdata/plan/configurationv1.yaml" type: Exec - description: "Editing the Configuration Meta resource with new family provider references" + description: "Replacing the monolithic provider dependencies in the Configuration metadata with references to the new family providers" - exec: command: sh @@ -53,7 +53,7 @@ spec: manualExecution: - sh -c "up xpkg build --package-root={{PKG_ROOT}} --examples-root={{EXAMPLES_ROOT}} -o {{PKG_PATH}}" type: Exec - description: "Building the new configuration pkg" + description: "Building the new Configuration package using up" - exec: command: sh @@ -64,6 +64,6 @@ spec: manualExecution: - sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}" type: Exec - description: "Pushing the new configuration pkg" + description: "Pushing the new Configuration package" version: 0.1.0 diff --git a/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml b/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml index eeab78a5..ecd364a2 100644 --- a/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml @@ -31,7 +31,7 @@ spec: manualExecution: - sh -c "kubectl get claim --all-namespaces -o yaml > backup/claim-resources.yaml" type: Exec - description: "Backing up Claims" + description: "Backing up Claims from all namespaces" - patch: type: merge @@ -50,7 +50,7 @@ spec: manualExecution: - "kubectl apply -f new-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml" type: Apply - description: "Installing the new family provider" + description: "Installing the new family config provider" - exec: command: sh @@ -61,7 +61,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-family-aws --for condition=Healthy" type: Exec - description: "Checking health of new family provider" + description: "Checking the health of new family config provider" - apply: files: @@ -72,7 +72,7 @@ spec: - "kubectl apply -f new-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml" - "kubectl apply -f new-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml" type: Apply - description: "Installing the new service scoped providers" + description: "Installing the new family resource providers" - exec: command: sh @@ -83,7 +83,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-ec2 --for condition=Healthy" type: Exec - description: "Checking health of new service scoped provider" + description: "Checking health of new family resource provider" - exec: command: sh @@ -94,7 +94,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-eks --for condition=Healthy" type: Exec - description: "Checking health of new service scoped provider" + description: "Checking health of new family resource provider" - patch: type: merge @@ -104,7 +104,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f disable-dependency-resolution/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml --patch-file disable-dependency-resolution/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml" type: Patch - description: "Setting the value of skipDependencyResolution field to true so that dependencies in the configuration package are not resolved automatically" + description: "Setting the value of spec.skipDependencyResolution field to true so that dependencies of the Crossplane Configuration package are not resolved automatically, in preparation of deleting the monolithic provider packages" - patch: type: merge @@ -114,7 +114,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f edit-package-lock/lock.locks.pkg.crossplane.io_v1beta1.yaml --patch-file edit-package-lock/lock.locks.pkg.crossplane.io_v1beta1.yaml" type: Patch - description: "Deleting configuration package dependency from Lock resource" + description: "Deleting the Configuration package dependency from the Lock resource in preparation of deleting the monolithic provider packages" - delete: options: @@ -128,7 +128,7 @@ spec: manualExecution: - "kubectl delete Provider.pkg.crossplane.io provider-aws" type: Delete - description: "Deleting monolithic provider" + description: "Deleting the monolithic provider package" - patch: type: merge @@ -138,7 +138,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f activate-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml" type: Patch - description: "Activating the new family provider after deletion monolithic one" + description: "Activating the new family config provider after the deletion of the monolithic one" - exec: command: sh @@ -149,7 +149,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-family-aws --for condition=Installed" type: Exec - description: "Checking installation of new family provider" + description: "Checking the installation of new family config provider" - patch: type: merge @@ -161,7 +161,7 @@ spec: - "kubectl patch --type='merge' -f activate-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml" - "kubectl patch --type='merge' -f activate-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml" type: Patch - description: "Activating the new service scoped providers" + description: "Activating the new family resource providers" - exec: command: sh @@ -194,7 +194,7 @@ spec: manualExecution: - sh -c "cp edit-configuration-metadata/platform-ref-aws.configurations.meta.pkg.crossplane.io_v1.yaml testdata/plan/configurationv1.yaml" type: Exec - description: "Editing the Configuration Meta resource with new family provider references" + description: "Replacing the monolithic provider dependencies in the Configuration metadata with references to the new family providers" - exec: command: sh @@ -205,7 +205,7 @@ spec: manualExecution: - sh -c "up xpkg build --package-root={{PKG_ROOT}} --examples-root={{EXAMPLES_ROOT}} -o {{PKG_PATH}}" type: Exec - description: "Building the new configuration pkg" + description: "Building the new Configuration package using up" - exec: command: sh @@ -216,7 +216,7 @@ spec: manualExecution: - sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}" type: Exec - description: "Pushing the new configuration pkg" + description: "Pushing the new Configuration package" - patch: type: merge @@ -226,7 +226,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f edit-configuration-package/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml --patch-file edit-configuration-package/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml" type: Patch - description: "Setting the configuration package reference to new one" + description: "Setting the Configuration package reference (spec.package) to the new one" - patch: type: merge @@ -236,7 +236,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f enable-dependency-resolution/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml --patch-file enable-dependency-resolution/platform-ref-aws.configurations.pkg.crossplane.io_v1.yaml" type: Patch - description: "Setting the value of skipDependencyResolution field in the configuration package back to false" + description: "Setting the value of spec.skipDependencyResolution field in the Configuration package back to false" - patch: type: merge @@ -246,6 +246,6 @@ spec: manualExecution: - "kubectl patch --type='merge' -f deletion-policy-delete/sample-vpc.vpcs.fakesourceapi_v1alpha1.yaml --patch-file deletion-policy-delete/sample-vpc.vpcs.fakesourceapi_v1alpha1.yaml" type: Patch - description: "Setting the deletion policies of Managed Resources whose deletion policy is set to Orphan at the beginning of the migration, to Delete again" + description: "Setting the deletion policies of Managed Resources whose deletion policy had been set to Orphan at the beginning of the migration process, back to Delete" version: 0.1.0 diff --git a/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml b/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml index e81ae923..91d3d153 100644 --- a/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml @@ -31,7 +31,7 @@ spec: manualExecution: - sh -c "kubectl get claim --all-namespaces -o yaml > backup/claim-resources.yaml" type: Exec - description: "Backing up Claims" + description: "Backing up Claims from all namespaces" - exec: command: sh @@ -42,7 +42,7 @@ spec: manualExecution: - sh -c "cp edit-configuration-metadata/platform-ref-aws.configurations.meta.pkg.crossplane.io_v1alpha1.yaml testdata/plan/configurationv1alpha1.yaml" type: Exec - description: "Editing the Configuration Meta resource with new family provider references" + description: "Replacing the monolithic provider dependencies in the Configuration metadata with references to the new family providers" - exec: command: sh @@ -53,7 +53,7 @@ spec: manualExecution: - sh -c "up xpkg build --package-root={{PKG_ROOT}} --examples-root={{EXAMPLES_ROOT}} -o {{PKG_PATH}}" type: Exec - description: "Building the new configuration pkg" + description: "Building the new Configuration package using up" - exec: command: sh @@ -64,6 +64,6 @@ spec: manualExecution: - sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}" type: Exec - description: "Pushing the new configuration pkg" + description: "Pushing the new Configuration package" version: 0.1.0 diff --git a/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml b/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml index 00dc0efe..d56cd477 100644 --- a/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml @@ -7,7 +7,7 @@ spec: manualExecution: - "kubectl apply -f new-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml" type: Apply - description: "Installing the new family provider" + description: "Installing the new family config provider" - exec: command: sh @@ -18,7 +18,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-family-aws --for condition=Healthy" type: Exec - description: "Checking health of new family provider" + description: "Checking the health of new family config provider" - apply: files: @@ -29,7 +29,7 @@ spec: - "kubectl apply -f new-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml" - "kubectl apply -f new-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml" type: Apply - description: "Installing the new service scoped providers" + description: "Installing the new family resource providers" - exec: command: sh @@ -40,7 +40,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-ec2 --for condition=Healthy" type: Exec - description: "Checking health of new service scoped provider" + description: "Checking health of new family resource provider" - exec: command: sh @@ -51,7 +51,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-aws-eks --for condition=Healthy" type: Exec - description: "Checking health of new service scoped provider" + description: "Checking health of new family resource provider" - delete: options: @@ -65,7 +65,7 @@ spec: manualExecution: - "kubectl delete Provider.pkg.crossplane.io provider-aws" type: Delete - description: "Deleting monolithic provider" + description: "Deleting the monolithic provider package" - patch: type: merge @@ -75,7 +75,7 @@ spec: manualExecution: - "kubectl patch --type='merge' -f activate-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-family-aws.providers.pkg.crossplane.io_v1.yaml" type: Patch - description: "Activating the new family provider after deletion monolithic one" + description: "Activating the new family config provider after the deletion of the monolithic one" - exec: command: sh @@ -86,7 +86,7 @@ spec: manualExecution: - sh -c "kubectl wait provider.pkg provider-family-aws --for condition=Installed" type: Exec - description: "Checking installation of new family provider" + description: "Checking the installation of new family config provider" - patch: type: merge @@ -98,7 +98,7 @@ spec: - "kubectl patch --type='merge' -f activate-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-aws-ec2.providers.pkg.crossplane.io_v1.yaml" - "kubectl patch --type='merge' -f activate-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml --patch-file activate-ssop/provider-aws-eks.providers.pkg.crossplane.io_v1.yaml" type: Patch - description: "Activating the new service scoped providers" + description: "Activating the new family resource providers" - exec: command: sh From 4a021e521615782788ea75e8c1473930cb0bdc3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergen=20Yal=C3=A7=C4=B1n?= Date: Mon, 24 Jul 2023 17:43:13 +0200 Subject: [PATCH 4/4] Protect the original value of skipDependencyResolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Sergen Yalçın --- pkg/migration/configurationpackage_steps.go | 81 ++++++++++--------- pkg/migration/exec_steps.go | 1 + pkg/migration/provider_package_steps.go | 1 + .../configurationv1_migration_plan.yaml | 2 +- .../configurationv1_pkg_migration_plan.yaml | 4 +- .../configurationv1alpha1_migration_plan.yaml | 2 +- .../generated/providerv1_migration_plan.yaml | 2 +- 7 files changed, 51 insertions(+), 42 deletions(-) diff --git a/pkg/migration/configurationpackage_steps.go b/pkg/migration/configurationpackage_steps.go index a8231a1c..47a7f3e1 100644 --- a/pkg/migration/configurationpackage_steps.go +++ b/pkg/migration/configurationpackage_steps.go @@ -30,50 +30,57 @@ const ( errEditConfigurationPackageFmt = `failed to put the edited Configuration package: %s` ) -func (pg *PlanGenerator) convertConfigurationPackage(o UnstructuredWithMetadata) error { +func (pg *PlanGenerator) convertConfigurationPackage(o UnstructuredWithMetadata) error { //nolint:gocyclo pkg, err := toConfigurationPackageV1(o.Object) if err != nil { return err } - // add step for disabling the dependency resolution - // for the configuration package - s := pg.stepConfiguration(stepConfigurationPackageDisableDepResolution) - p := fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(o.Object)) - s.Patch.Files = append(s.Patch.Files, p) - if err := pg.target.Put(UnstructuredWithMetadata{ - Object: unstructured.Unstructured{ - Object: addNameGVK(o.Object, map[string]any{ - "spec": map[string]any{ - "skipDependencyResolution": true, - }, - }), - }, - Metadata: Metadata{ - Path: p, - }, - }); err != nil { - return err + pv := fieldpath.Pave(o.Object.Object) + p, err := pv.GetBool("spec.skipDependencyResolution") + if err != nil && !fieldpath.IsNotFound(err) { + return errors.Wrapf(err, "failed to get the current skipping dependency resolution behavior from Configuration Package: %s", o.Object.GetName()) } + if !p { + // add step for disabling the dependency resolution + // for the configuration package + s := pg.stepConfiguration(stepConfigurationPackageDisableDepResolution) + p := fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(o.Object)) + s.Patch.Files = append(s.Patch.Files, p) + if err := pg.target.Put(UnstructuredWithMetadata{ + Object: unstructured.Unstructured{ + Object: addNameGVK(o.Object, map[string]any{ + "spec": map[string]any{ + "skipDependencyResolution": true, + }, + }), + }, + Metadata: Metadata{ + Path: p, + }, + }); err != nil { + return err + } - // add step for enabling the dependency resolution - // for the configuration package - s = pg.stepConfiguration(stepConfigurationPackageEnableDepResolution) - p = fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(o.Object)) - s.Patch.Files = append(s.Patch.Files, p) - if err := pg.target.Put(UnstructuredWithMetadata{ - Object: unstructured.Unstructured{ - Object: addNameGVK(o.Object, map[string]any{ - "spec": map[string]any{ - "skipDependencyResolution": false, - }, - }), - }, - Metadata: Metadata{ - Path: p, - }, - }); err != nil { - return err + // add step for enabling the dependency resolution + // for the configuration package + s = pg.stepConfiguration(stepConfigurationPackageEnableDepResolution) + p = fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(o.Object)) + s.Patch.Files = append(s.Patch.Files, p) + if err := pg.target.Put(UnstructuredWithMetadata{ + Object: unstructured.Unstructured{ + Object: addNameGVK(o.Object, map[string]any{ + "spec": map[string]any{ + "skipDependencyResolution": false, + }, + }), + }, + Metadata: Metadata{ + Path: p, + }, + }); err != nil { + return err + } } // add the step for editing the configuration package diff --git a/pkg/migration/exec_steps.go b/pkg/migration/exec_steps.go index ee414a31..c5ccc5ea 100644 --- a/pkg/migration/exec_steps.go +++ b/pkg/migration/exec_steps.go @@ -86,5 +86,6 @@ func (pg *PlanGenerator) stepBuildConfiguration() { func (pg *PlanGenerator) stepPushConfiguration() { s := pg.stepConfiguration(stepPushConfiguration) + s.Description = fmt.Sprintf("%s to {{TARGET_CONFIGURATION_PACKAGE}}", s.Description) s.Exec.Args = []string{"-c", "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}"} } diff --git a/pkg/migration/provider_package_steps.go b/pkg/migration/provider_package_steps.go index 9b75f673..7ce1f3be 100644 --- a/pkg/migration/provider_package_steps.go +++ b/pkg/migration/provider_package_steps.go @@ -78,6 +78,7 @@ func (pg *PlanGenerator) stepDeleteMonolith(source UnstructuredWithMetadata) err // delete the monolithic provider package s := pg.stepConfigurationWithSubStep(stepDeleteMonolithicProvider, true) source.Metadata.Path = fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(source.Object)) + s.Description = fmt.Sprintf("%s: %s", s.Description, source.Object.GetName()) s.Delete.Resources = []Resource{ { GroupVersionKind: FromGroupVersionKind(source.Object.GroupVersionKind()), diff --git a/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml b/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml index 72af750a..024c769e 100644 --- a/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml @@ -64,6 +64,6 @@ spec: manualExecution: - sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}" type: Exec - description: "Pushing the new Configuration package" + description: "Pushing the new Configuration package to {{TARGET_CONFIGURATION_PACKAGE}}" version: 0.1.0 diff --git a/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml b/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml index ecd364a2..656904e7 100644 --- a/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml @@ -128,7 +128,7 @@ spec: manualExecution: - "kubectl delete Provider.pkg.crossplane.io provider-aws" type: Delete - description: "Deleting the monolithic provider package" + description: "Deleting the monolithic provider package: provider-aws" - patch: type: merge @@ -216,7 +216,7 @@ spec: manualExecution: - sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}" type: Exec - description: "Pushing the new Configuration package" + description: "Pushing the new Configuration package to {{TARGET_CONFIGURATION_PACKAGE}}" - patch: type: merge diff --git a/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml b/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml index 91d3d153..5edf4367 100644 --- a/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml @@ -64,6 +64,6 @@ spec: manualExecution: - sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}" type: Exec - description: "Pushing the new Configuration package" + description: "Pushing the new Configuration package to {{TARGET_CONFIGURATION_PACKAGE}}" version: 0.1.0 diff --git a/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml b/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml index d56cd477..9d60c6e0 100644 --- a/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml +++ b/pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml @@ -65,7 +65,7 @@ spec: manualExecution: - "kubectl delete Provider.pkg.crossplane.io provider-aws" type: Delete - description: "Deleting the monolithic provider package" + description: "Deleting the monolithic provider package: provider-aws" - patch: type: merge