Skip to content

Define behavior of retention policy in multi-namespace plans.#45

Open
awels wants to merge 2 commits intokubevirt:mainfrom
awels:define_retention_policy
Open

Define behavior of retention policy in multi-namespace plans.#45
awels wants to merge 2 commits intokubevirt:mainfrom
awels:define_retention_policy

Conversation

@awels
Copy link
Copy Markdown
Member

@awels awels commented Mar 26, 2026

What this PR does / why we need it:
Before it was undefined what would happen if the user provided both the retention policy on the
multi-namespace plan and on the namespace plan. Now the namespace plan inherits from the multi-namespace plan if not set.

CEL validation is still used to validate the retention policy. In particular it should prevent
the user from removing the retention policy once it is set.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes https://redhat.atlassian.net/browse/CNV-82386

Special notes for your reviewer:

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

Release note:

NONE

Before it was undefined what would happen if the
user provided both the retention policy on the
multi-namespace plan and on the namespace plan.
Now the namespace plan inherits from the multi-namespace
plan if not set.

CEL validation is still used to validate the
retention policy. In particular it should prevent
the user from removing the retention policy once
it is set.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Alexander Wels <awels@redhat.com>
@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Mar 26, 2026
@kubevirt-bot kubevirt-bot requested a review from akalenyu March 26, 2026 12:42
@kubevirt-bot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign awels for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

)

// VirtualMachineStorageMigrationPlanSpec defines the desired state of VirtualMachineStorageMigrationPlan
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.retentionPolicy) || has(self.retentionPolicy)", message="retentionPolicy cannot be removed once set"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure self == oldSelf doesn't cover this case? logically I would assume it does

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some weirdness that happens when going from nil to something or vice versa. Especially with a default defined. I believe this is to ensure that if we have nil and select the default, it actually 'works'.

Expect(err).To(HaveOccurred())
// Verify the specific CEL error message from your marker
Expect(err.Error()).To(ContainSubstring("retentionPolicy is immutable"))
Expect(err.Error()).To(ContainSubstring("retentionPolicy"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this assertion is a little weird, i think you know the exact error message string you're going to get?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let me double check and make a more specific error message.

Comment on lines +198 to +204
if plan.Spec.RetentionPolicy != nil && *plan.Spec.RetentionPolicy != migrations.RetentionPolicyKeepSource {
// Parent has non-default value
if spec.RetentionPolicy == nil || *spec.RetentionPolicy == migrations.RetentionPolicyKeepSource {
// Namespace has default or nil - inherit from parent
spec.RetentionPolicy = plan.Spec.RetentionPolicy
}
// else: namespace has explicit non-default value, use it (priority 1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to unit test the priority? doesn't have to involve etcd, could extract to small util and test that

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure give me a bit to update this.

Signed-off-by: Alexander Wels <awels@redhat.com>
@kubevirt-bot kubevirt-bot added size/L and removed size/M labels Apr 6, 2026
@kubevirt-bot
Copy link
Copy Markdown

@awels: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubevirt-migration-controller-lint db80dbd link true /test pull-kubevirt-migration-controller-lint
Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@akalenyu
Copy link
Copy Markdown
Contributor

akalenyu commented Apr 9, 2026

@awels FYI linter issue is real

Comment on lines +50 to +52
if client == nil {
return
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this really happen?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it can, if you manually run a particular test from the IDE, it forgot to set the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. release-note-none Denotes a PR that doesn't merit a release note. size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants