Skip to content

Commit

Permalink
Protect the original value of skipDependencyResolution
Browse files Browse the repository at this point in the history
Signed-off-by: Sergen Yalçın <[email protected]>
  • Loading branch information
sergenyalcin committed Jul 24, 2023
1 parent 32ec719 commit 4a021e5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 42 deletions.
81 changes: 44 additions & 37 deletions pkg/migration/configurationpackage_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/migration/exec_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"}
}
1 change: 1 addition & 0 deletions pkg/migration/provider_package_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4a021e5

Please sign in to comment.