-
Notifications
You must be signed in to change notification settings - Fork 60
🌱 Protected annotation-to-condition pattern #1278
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
Conversation
e12154d to
1094519
Compare
| return apierrorsutil.NewAggregate(errs) | ||
| } | ||
|
|
||
| var anno2ConditionRegex = regexp.MustCompile(`^condition.vmoperator.vmware.com.protected/(.+)?$`) |
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.
more of a nit: but do we not have a standard about the ordering of items in a file: consts, vars, types, funcs?
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.
should it also be in the constant file with the other annotations?
| allErrs = append(allErrs, field.Forbidden(annotationPath.Key(vmopv1.ImportedVMAnnotation), modifyAnnotationNotAllowedForNonAdmin)) | ||
| } | ||
|
|
||
| if vm.Annotations[pkgconst.SkipDeletePlatformResourceKey] != oldVM.Annotations[pkgconst.SkipDeletePlatformResourceKey] { |
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.
should we remove the annotations from the constant file since they are only used in the tests now?
| } | ||
|
|
||
| func unitTestsValidateUpdate() { | ||
| func unitTestsValidateUpdate() { //nolint:gocyclo |
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 it not better to refactor and split our tests rather than ignoring it?
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, but not as part of this PR.
| return table | ||
| } | ||
|
|
||
| DescribeTable("disallow update of protected annotations by non-privileged user", |
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 define the methods outside of the describe instead of inside?
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.
Because it's not a describe, it's a DescribeTable.
| _ ReconcileStatusData) []error { //nolint:unparam | ||
|
|
||
| for k, v := range vmCtx.VM.Annotations { | ||
| if anno2ConditionRegex.MatchString(k) { |
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 the regex with the capture group when not using that, vs strings.HasPrefix()?
| if t != "" { | ||
| switch s { | ||
| case metav1.ConditionFalse: | ||
| conditions.MarkFalse(vmCtx.VM, t, r, m+"%s", "") |
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.
..., "%s", m) didn't work?
This patch introduces a feature that allows integration with VM
conditions by external actors. Privileged users may set annotations
on a VM that match the following pattern:
condition.vmoperator.vmware.com.protected/UNIQUE_ID: TYPE[;STATUS][;REASON][;MESSAGE]
Any annotations that match the above pattern are added/updated to a
VM's conditions.
Please note that STATUS must be either True, False, or Unknown. Any
other value will be reported as Unknown.
Also, there is currently no way to remove a condition via this method,
only add/update them.
d936f14 to
053bffb
Compare
Minimum allowed line rate is |
🌱 Protected annotation-to-condition pattern
What does this PR do, and why is it needed?
This patch introduces a feature that allows integration with VM conditions by external actors. Privileged users may set annotations on a VM that match the following pattern:
Any annotations that match the above pattern are added/updated to a VM's conditions.
Please note that STATUS must be either True, False, or Unknown. Any other value will be reported as Unknown.
Also, there is currently no way to remove a condition via this method, only add/update them.
Which issue(s) is/are addressed by this PR? (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #
Are there any special notes for your reviewer:
Please add a release note if necessary: