-
Notifications
You must be signed in to change notification settings - Fork 101
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
Add validation to ensure no duplicate TargetRefs in policies #2986
Add validation to ensure no duplicate TargetRefs in policies #2986
Conversation
Is there any specific testing I should do when bumping the version of the ObservabilityPolicy? I verified applying the v1alpha1 version policy still works, and shows this warning:
In addition the CEL validation is not present in the |
For visibility, here is the commit which @salonichf5 wrote which bumped the version in the past but was reverted. I based my work off of that. Should I reopen this task to fully remove v1alpha1 in 2.3.0? |
There are 4 cases you should test
Let me know if this assumption is correct @sjberman
|
Yes we need a story to track deprecation of the old version. |
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.
Doc changes LGTM!
Works, displays Warning message, and when using
Works, CEL validation is enabled.
I tested this by simply changing the apiVersion on the policy to
This lines up with my results. Can't really downgrade because the apiversion shown on a policy created with |
Re-opened #2767 to track the removal of the |
Looks right ! |
You might need to open this PR against main branch instead of your fork for the Plus Build fails |
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.
Just had a small question otherwise looks good to me
@bjee19 since this is a breaking change, I added the |
apis/v1alpha2/shared_types.go
Outdated
// Examples: 120s, 50ms, 5m, 1h. | ||
// | ||
// +kubebuilder:validation:Pattern=`^[0-9]{1,4}(ms|s|m|h)?$` | ||
type Duration string |
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.
I feel like ObservabilityPolicy could just import these from v1alpha1, no?
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.
Yep, we can leave this file in v1alpha1
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.
I like the idea of keeping the package shared types different and since I also saw that there were distinct shared_types.go
files in the gateway api repo https://github.com/kubernetes-sigs/gateway-api/tree/main/apis , I think it would be good to do.
However I do see how the alpha packages (only 2 of them) share the same shared_types.go
while the beta and v1 packages have their own shared_types.go
files (even though there is a lot of overlap).
So I would also be fine with sharing the types within the larger version (alpha,beta,v1) and creating a new file perhaps if a type changes within (like alpha1->alpha2) with only the specific changes necessary. While creating different shared_types.go
files for the larger version/stage changes (not sure what this is called).
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.
My opinion is that we shouldn't create a new shared_types
file until there's a reason to (e.g. a new shared type is added to v1alpha2 or a field changes).
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.
Sounds good yea I'll change it
@bjee19 even though there are no spec/status field changes to ObservabilityPolicy, now that we moved the API to v1alpha2, we need to update the controller code to process v1alpha2 ObservabilityPolicies instead of v1alpha1. |
Following doing this, I tested applying a |
Does anyone know if there is a better way to update the controller code to use the new version of a CRD? I manually did it and there isn't really any verification that I caught all the places besides me just double checking and running the tests. |
Don't think there's a quicker way. You can double check that you caught everything by looking at the code references of the v1alpha1 ObservabilityPolicy types. There shouldn't be any in the |
Yep, thanks for pointing that out, I already did that on my double check so we're good i guess 🤞 |
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.
LGTM
62a2ab6
to
79ab627
Compare
Closing in favor of new PR #2998 from branch. |
Proposed changes
Validate that there are no duplicate TargetRefs in the UpstreamSettingsPolicy and ObservabilityPolicy. Additionally, since this change strengthens the validation rules on the ObservabilityPolicy API, we are bumping the ObservabilityPolicy API version from
v1alpha1
tov1alpha2
.Problem: It's possible to create an ObservabilityPolicy or UpstreamSettingsPolicy with duplicate targetRefs. This is not a valid configuration and should be prevented.
Solution: Add CEL validation to prevent this.
Testing: Manually deployed both the UpstreamSettingsPolicy and ObservabilityPolicy and verified that duplicate targetRefs are invalid.
Closes #2923
Checklist
Before creating a PR, run through this checklist and mark each as complete.
Release notes
If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.