-
Notifications
You must be signed in to change notification settings - Fork 85
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
Handle empty converts #181
Conversation
Signed-off-by: lsviben <[email protected]>
Signed-off-by: lsviben <[email protected]>
Signed-off-by: lsviben <[email protected]>
apis/object/v1alpha1/conversion.go
Outdated
@@ -101,7 +101,7 @@ func (src *Object) ConvertTo(dstRaw conversion.Hub) error { // nolint:golint // | |||
case Observe: | |||
dst.Spec.ManagementPolicies = xpv1.ManagementPolicies{xpv1.ManagementActionObserve} | |||
default: | |||
return errors.New("unknown management policy") | |||
return fmt.Errorf("unknown management policy: %v", src.Spec.ManagementPolicy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could we use errors.Errorf instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure we can!
Signed-off-by: lsviben <[email protected]>
Backport failed for Please cherry-pick the changes locally. git fetch origin release-0.11.0
git worktree add -d .worktree/backport-181-to-release-0.11.0 origin/release-0.11.0
cd .worktree/backport-181-to-release-0.11.0
git checkout -b backport-181-to-release-0.11.0
ancref=$(git merge-base cc10a8c08e0e16109fb5d34ef4f4aee84f89d58b b4543db477847d99b1f6da91d18a177bf90894ea)
git cherry-pick -x $ancref..b4543db477847d99b1f6da91d18a177bf90894ea |
Handle empty converts
Handle empty converts Signed-off-by: lsviben <[email protected]>
Description of your changes
Fix for #179 . Handles the conversion case from
v1alpha2
tov1alpha1
when thespec.managementPolicies
are unset which was causing the issue.This was happening when:
v1alpha1
versionv1alpha2
)v1alpha2
spec.managementPolices
set (relies on defaulting)So what happened was that the
v1alpha2
Object, without thespec.managementPolicies
was being converted tov1alpha1
during the Composition reconciliation. This could be because it is updating the existing resource which is still stored inv1alpha1
version, although after the first update, the resource should be stored inv1alpha2
version as its the storage version, based on docs.As the defaulting happens after conversion, the conversion fails. Now this is handled so that if the resource does not have a
spec.managementPolicies
set or a CreationTimestamp (this is to differentiate between converting resources paused through management policies and resources from Compositions), thespec.managementPolicy
is set toDefault
.Additionally, to avoid conversion errors, if the policy we are converting from
v1alpha2
tov1alpha1
is unsupported, thespec.managementPolicy
field is left empty. I was thinking either to leave it empty, which will default to Default if the resource is created, or set it to Observe to be safe, but decided on Default as it seems like the most fitting based on the other checks. If its not being created, it will be empty and users will need to manual set it. This was needed so thatv1alpha2
policies likespec.managementPolicies: ["Observe", "Update"]
can be used in the above case as well.Fixes #179
I have:
make reviewable test
to ensure this PR is ready for review.How has this code been tested
Was testing using the reproduction setup for the #179 bug from @haarchri (thanks again for setting it up, really helpful!).
The example from issue, using the setup.sh now passes. The resulting Object has
spec.managementPolicies: ["*"]
Also tried with setting an unsupported policy in the Composition like
spec.managementPolicies: ["Observe", "Update"]
and that works as well. The resulting Object hasspec.managementPolicies: ["Observe", "Update"]