Skip to content

Commit 4a021e5

Browse files
committed
Protect the original value of skipDependencyResolution
Signed-off-by: Sergen Yalçın <[email protected]>
1 parent 32ec719 commit 4a021e5

7 files changed

+51
-42
lines changed

pkg/migration/configurationpackage_steps.go

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,57 @@ const (
3030
errEditConfigurationPackageFmt = `failed to put the edited Configuration package: %s`
3131
)
3232

33-
func (pg *PlanGenerator) convertConfigurationPackage(o UnstructuredWithMetadata) error {
33+
func (pg *PlanGenerator) convertConfigurationPackage(o UnstructuredWithMetadata) error { //nolint:gocyclo
3434
pkg, err := toConfigurationPackageV1(o.Object)
3535
if err != nil {
3636
return err
3737
}
3838

39-
// add step for disabling the dependency resolution
40-
// for the configuration package
41-
s := pg.stepConfiguration(stepConfigurationPackageDisableDepResolution)
42-
p := fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(o.Object))
43-
s.Patch.Files = append(s.Patch.Files, p)
44-
if err := pg.target.Put(UnstructuredWithMetadata{
45-
Object: unstructured.Unstructured{
46-
Object: addNameGVK(o.Object, map[string]any{
47-
"spec": map[string]any{
48-
"skipDependencyResolution": true,
49-
},
50-
}),
51-
},
52-
Metadata: Metadata{
53-
Path: p,
54-
},
55-
}); err != nil {
56-
return err
39+
pv := fieldpath.Pave(o.Object.Object)
40+
p, err := pv.GetBool("spec.skipDependencyResolution")
41+
if err != nil && !fieldpath.IsNotFound(err) {
42+
return errors.Wrapf(err, "failed to get the current skipping dependency resolution behavior from Configuration Package: %s", o.Object.GetName())
5743
}
44+
if !p {
45+
// add step for disabling the dependency resolution
46+
// for the configuration package
47+
s := pg.stepConfiguration(stepConfigurationPackageDisableDepResolution)
48+
p := fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(o.Object))
49+
s.Patch.Files = append(s.Patch.Files, p)
50+
if err := pg.target.Put(UnstructuredWithMetadata{
51+
Object: unstructured.Unstructured{
52+
Object: addNameGVK(o.Object, map[string]any{
53+
"spec": map[string]any{
54+
"skipDependencyResolution": true,
55+
},
56+
}),
57+
},
58+
Metadata: Metadata{
59+
Path: p,
60+
},
61+
}); err != nil {
62+
return err
63+
}
5864

59-
// add step for enabling the dependency resolution
60-
// for the configuration package
61-
s = pg.stepConfiguration(stepConfigurationPackageEnableDepResolution)
62-
p = fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(o.Object))
63-
s.Patch.Files = append(s.Patch.Files, p)
64-
if err := pg.target.Put(UnstructuredWithMetadata{
65-
Object: unstructured.Unstructured{
66-
Object: addNameGVK(o.Object, map[string]any{
67-
"spec": map[string]any{
68-
"skipDependencyResolution": false,
69-
},
70-
}),
71-
},
72-
Metadata: Metadata{
73-
Path: p,
74-
},
75-
}); err != nil {
76-
return err
65+
// add step for enabling the dependency resolution
66+
// for the configuration package
67+
s = pg.stepConfiguration(stepConfigurationPackageEnableDepResolution)
68+
p = fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(o.Object))
69+
s.Patch.Files = append(s.Patch.Files, p)
70+
if err := pg.target.Put(UnstructuredWithMetadata{
71+
Object: unstructured.Unstructured{
72+
Object: addNameGVK(o.Object, map[string]any{
73+
"spec": map[string]any{
74+
"skipDependencyResolution": false,
75+
},
76+
}),
77+
},
78+
Metadata: Metadata{
79+
Path: p,
80+
},
81+
}); err != nil {
82+
return err
83+
}
7784
}
7885

7986
// add the step for editing the configuration package

pkg/migration/exec_steps.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@ func (pg *PlanGenerator) stepBuildConfiguration() {
8686

8787
func (pg *PlanGenerator) stepPushConfiguration() {
8888
s := pg.stepConfiguration(stepPushConfiguration)
89+
s.Description = fmt.Sprintf("%s to {{TARGET_CONFIGURATION_PACKAGE}}", s.Description)
8990
s.Exec.Args = []string{"-c", "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}"}
9091
}

pkg/migration/provider_package_steps.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ func (pg *PlanGenerator) stepDeleteMonolith(source UnstructuredWithMetadata) err
7878
// delete the monolithic provider package
7979
s := pg.stepConfigurationWithSubStep(stepDeleteMonolithicProvider, true)
8080
source.Metadata.Path = fmt.Sprintf("%s/%s.yaml", s.Name, getVersionedName(source.Object))
81+
s.Description = fmt.Sprintf("%s: %s", s.Description, source.Object.GetName())
8182
s.Delete.Resources = []Resource{
8283
{
8384
GroupVersionKind: FromGroupVersionKind(source.Object.GroupVersionKind()),

pkg/migration/testdata/plan/generated/configurationv1_migration_plan.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ spec:
6464
manualExecution:
6565
- sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}"
6666
type: Exec
67-
description: "Pushing the new Configuration package"
67+
description: "Pushing the new Configuration package to {{TARGET_CONFIGURATION_PACKAGE}}"
6868

6969
version: 0.1.0

pkg/migration/testdata/plan/generated/configurationv1_pkg_migration_plan.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ spec:
128128
manualExecution:
129129
- "kubectl delete Provider.pkg.crossplane.io provider-aws"
130130
type: Delete
131-
description: "Deleting the monolithic provider package"
131+
description: "Deleting the monolithic provider package: provider-aws"
132132

133133
- patch:
134134
type: merge
@@ -216,7 +216,7 @@ spec:
216216
manualExecution:
217217
- sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}"
218218
type: Exec
219-
description: "Pushing the new Configuration package"
219+
description: "Pushing the new Configuration package to {{TARGET_CONFIGURATION_PACKAGE}}"
220220

221221
- patch:
222222
type: merge

pkg/migration/testdata/plan/generated/configurationv1alpha1_migration_plan.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ spec:
6464
manualExecution:
6565
- sh -c "up xpkg push {{TARGET_CONFIGURATION_PACKAGE}} -f {{PKG_PATH}}"
6666
type: Exec
67-
description: "Pushing the new Configuration package"
67+
description: "Pushing the new Configuration package to {{TARGET_CONFIGURATION_PACKAGE}}"
6868

6969
version: 0.1.0

pkg/migration/testdata/plan/generated/providerv1_migration_plan.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ spec:
6565
manualExecution:
6666
- "kubectl delete Provider.pkg.crossplane.io provider-aws"
6767
type: Delete
68-
description: "Deleting the monolithic provider package"
68+
description: "Deleting the monolithic provider package: provider-aws"
6969

7070
- patch:
7171
type: merge

0 commit comments

Comments
 (0)