-
Notifications
You must be signed in to change notification settings - Fork 56
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
DRPolicy: Add CEL and remove webhook #1175
Conversation
@@ -150,6 +150,9 @@ spec: | |||
required: | |||
- drClusters | |||
type: object | |||
x-kubernetes-validations: | |||
- message: Value is immutable | |||
rule: self == oldSelf |
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.
Looks like we add the same information twice - once in the kubebuilder comment, and once here. Can we have this only once? What happens if the rule and message are different in both places?
Also this looks really magical - can you link to the docs describing this special syntax?
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.
we only add the comment in the API file and operator-sdk generates/updates this YAML when we run make
. This is the general practice as far as I know.
check the link here: CEL Immutability
setupLog.Error(err, "unable to create webhook", "webhook", "DRPolicy") | ||
os.Exit(1) | ||
} | ||
|
||
// setup webhook for drpc |
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.
Can we do the same for drpc?
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.
yes, that is the plan. I am planning to send different PRs for each CR, it's just that removal of webhook code is more than adding CEL so, I plan to take one CR at a time so that we don't break ramen. :)
e2011af
to
77d6fd6
Compare
d9f2d72
to
698ca2c
Compare
@@ -12,5 +12,3 @@ spec: | |||
namespace: system | |||
name: webhook-service | |||
path: /convert | |||
conversionReviewVersions: |
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.
Do we even need this file now? Can this be removed?
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 think we need to keep it as it is part of the scaffolding.
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.
Is this and config/crd/patches/cainjection_in_drpolicies.yaml needed though, I am not seeing the scaffolding requirement here?
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.
so, this file was created when the ramen operator was scaffolded initially. I was just trying to revert the changes that we did when adding webhooks and this line was the only change. I tested now by deleting the file. It does not matter. we can safely delete the file I believe.
@@ -12,5 +12,3 @@ spec: | |||
namespace: system | |||
name: webhook-service | |||
path: /convert | |||
conversionReviewVersions: |
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 think we need to keep it as it is part of the scaffolding.
api/v1alpha1/drpolicy_types.go
Outdated
// DRPolicySpec defines the desired state of DRPolicy | ||
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.schedulingInterval) || has(self.schedulingInterval)", message="schedulingInterval is required once set" |
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 think the pattern we need to use is Immutability upon object creation
For example with the current scheme a user would be allowed to set an empty value to begin with and then be allowed to modify it to a valid value, the immutability starts here and prevents further modification.
What we want is immutable post creation, so if the policy started with an empty value it should remain so.
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.
updated the code with Immutability upon object creation pattern for schedulingInterval
and drclusters
only.
88de718
to
f6f82d2
Compare
Tested the DRPolicy PR out and here is what I see... Initial DRPolicy created on a kind cluster extended with the CRD from the PR:
Look at Now changed the DRPolicy YAML to add a replicationClassSelector and applied it, and it was successful, and here is the get after that:
IOW, if we start wit a YAML that has no replicationClassSelector, and then add it later then it is allowed, which we should not allow. Another test I did was to create a policy with empty list of DRClusters (as below) and it passed. This is a new test case though as older code also allowed this to pass through:
Overall I think the CEL rules should be amended as below, such that we do not allow the above modifications:
For the tests, unfortunately as it uses a go struct for the DRPolicy, it is able to write out initial configuration with empty values, and so when we use YAML this is working differently. I am not sure yet how to test with YAML and envtest, so that is unfortunate. We could test it in a kind cluster though and ensure that CEL rules are adhered to. I just used hack/setup-kind-cluster.sh to get a kind cluster, extended the CRD for DRPolicy and then tested with various YAMLs as above. |
Thanks for the detail input. I have pushed the changes. |
Signed-off-by: rakeshgm <[email protected]>
excluding lll on long comments helps in kubebuilder validation rules to not be linted Signed-off-by: rakeshgm <[email protected]>
Signed-off-by: rakeshgm <[email protected]>
Remove DRPolicy Webhook and add CEL immutability validation for DRPolicy