-
Notifications
You must be signed in to change notification settings - Fork 185
Prevent quota reduction via CEL validation in StorageConsumer CRD #3185
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
base: main
Are you sure you want to change the base?
Prevent quota reduction via CEL validation in StorageConsumer CRD #3185
Conversation
c50497d
to
aa0b959
Compare
@@ -104,6 +104,7 @@ type StorageConsumerStatus struct { | |||
} | |||
|
|||
// ClientStatus is the information pushed from connected storage client | |||
// +kubebuilder:validation:XValidation:rule="!(has(oldSelf.storageQuotaUtilizationRatio) && self.storageQuotaUtilizationRatio < oldSelf.storageQuotaUtilizationRatio)",message="storageQuotaUtilizationRatio cannot be decreased on update" |
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.
Lets keep the message and rule in different line if possible to have a better readibility.
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.
controller-gen v0.16.1 does not support splitting rule and message across two XValidation: lines. It treats them as two separate markers, which is invalid.
$ ./bin/controller-gen --version
Version: v0.16.1
oviner~/DEV_REPOS/ocs-operator(cel_validate_quota_reduction)$ make gen-latest-csv
Ensuring operator-sdk
hack/ensure-operator-sdk.sh
Using operator-sdk CLI present at /home/oviner/DEV_REPOS/ocs-operator/bin/operator-sdk-v1.25.4
Using existing [email protected] at /home/oviner/DEV_REPOS/ocs-operator/bin/controller-gen
Updating generated manifests
/home/oviner/DEV_REPOS/ocs-operator/bin/controller-gen rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true,allowDangerousTypes=true paths=./api/... webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/home/oviner/DEV_REPOS/ocs-operator/api/v1alpha1/storageconsumer_types.go:108:1: missing argument "rule" (at <input>:1:69)
/home/oviner/DEV_REPOS/ocs-operator/api/v1alpha1/storageconsumer_types.go:108:1: missing argument "rule" (at <input>:1:69)
/home/oviner/DEV_REPOS/ocs-operator/api/v1alpha1/storageconsumer_types.go:108:1: missing argument "rule" (at <input>:1:69)
/home/oviner/DEV_REPOS/ocs-operator/api/v1alpha1/storageconsumer_types.go:108:1: missing argument "rule" (at <input>:1:69)
Error: not all generators ran successfully
run `controller-gen rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true,allowDangerousTypes=true paths=./api/... webhook paths=./... output:crd:artifacts:config=config/crd/bases -w` to see all available markers, or `controller-gen rbac:roleName=manager-role crd:generateEmbeddedObjectMeta=true,allowDangerousTypes=true paths=./api/... webhook paths=./... output:crd:artifacts:config=config/crd/bases -h` for usage
make: *** [Makefile:139: manifests] Error 1
aa0b959
to
7067ecd
Compare
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: OdedViner The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
9d8b330
to
56913a6
Compare
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.
Why do you need a not condition, instead you can use the >
3711373
to
734f0c7
Compare
@OdedViner Have you tested this new rule? Is it working as expected? |
yes, I changed the PR description with new test #3185 (comment) |
I saw the latest results in the description. Can you also test to delete it or move it to 0 and adjust the rule accordingly? |
734f0c7
to
8ae909b
Compare
Hi @iamniting , I updated the rule to: Thanks for the review! |
Signed-off-by: Oded Viner <[email protected]>
8ae909b
to
a650d4b
Compare
Can you also check if this allows you to delete the field? |
@iamniting Is this the expected behavior?
|
@iamniting Is this a temp issue? |
Can you try doing the same thing with oc edit? |
/test ocs-operator-bundle-e2e-aws |
@OdedViner: The following test failed, say
Full PR test history. Your PR dashboard. 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. |
Added CEL validation to ensure StorageQuotaInGiB cannot be decreased via CR updates.
Tested manually:
1.Delete the old CRD, apply the new CRD, and verify that the CRD was created.
2.Create a StorageConsumer Custom Resource
3.Test: Decrease the storageQuotaInGiB from 100 → 50 (Expect Rejection)
5.Test: Decrease the storageQuotaInGiB from 100 → 0 (Expect Success)
When
StorageQuotaInGiB=0
, aClusterResourceQuota
is not created because the function checks ifconsumer.Spec.StorageQuotaInGiB > 0
before adding a quota resource.ocs-operator/services/provider/server/server.go
Line 2060 in 91f2ec4
6.Test: Increase the storageQuotaInGiB from 0 → 34 (Expect Success)