chore: adding enforcement point status, vapgeneratestatus#3686
Conversation
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
| Operations []string `json:"operations,omitempty"` | ||
| ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||
| Errors []*templatesv1beta1.CreateCRDError `json:"errors,omitempty"` | ||
| VAPGenerationStatus VAPGenerationStatus `json:"vapGenerationStatus,omitempty"` |
There was a problem hiding this comment.
I can remove this if we do not want status on CT for generation updates. Lmk your thoughts.
There was a problem hiding this comment.
I think it makes sense to report status for CT objects... they do map directly to a VAP object.
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3686 +/- ##
==========================================
- Coverage 54.49% 47.56% -6.94%
==========================================
Files 134 236 +102
Lines 12329 19896 +7567
==========================================
+ Hits 6719 9464 +2745
- Misses 5116 9539 +4423
- Partials 494 893 +399
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
| // EnforcementPointStatus represents the status of a single enforcement point. | ||
| type EnforcementPointStatus struct { | ||
| EnforcementPoint string `json:"enforcementPoint"` | ||
| Enforced bool `json:"enforced"` |
There was a problem hiding this comment.
I think it was a mistake to have an enforced boolean state with constraints. And with VAP, we cannot make guarantees as to whether they are enforced b/c there is no status reporting, so we cannot know if the VAP object has been ingested or whether there are any errors. Maybe we want something like a string field called Status?
There we can put a string like "GENERATED", "ERROR", etc.
Of course, if we call it "status", we should rename the parent field to avoid stutter.
There was a problem hiding this comment.
how about code - generated/error/...?
There was a problem hiding this comment.
"code" seems a bit ambiguous given we are also dealing with "code" in the sense of CEL code.
"state"?
There was a problem hiding this comment.
I like state, updated the name to state.
| Operations []string `json:"operations,omitempty"` | ||
| ObservedGeneration int64 `json:"observedGeneration,omitempty"` | ||
| Errors []*templatesv1beta1.CreateCRDError `json:"errors,omitempty"` | ||
| VAPGenerationStatus VAPGenerationStatus `json:"vapGenerationStatus,omitempty"` |
There was a problem hiding this comment.
I think it makes sense to report status for CT objects... they do map directly to a VAP object.
| err := util.ValidateEnforcementAction(enforcementAction, instance.Object) | ||
| if err != nil { | ||
| return reconcile.Result{}, r.reportErrorOnConstraintStatus(ctx, status, err, "could not validate enforcement actions") | ||
| return reconcile.Result{}, r.reportErrorOnConstraintStatus(ctx, status, constraintstatusv1beta1.EnforcementPointStatus{}, err, "could not validate enforcement actions") |
There was a problem hiding this comment.
Will this have the effect of wiping out previously reported status? Should we preserve the original VAP status unless there is a failure related to VAP generation?
Of course, if we do that, VAP status should probably have it's own observedGeneration field, since it's possible that VAP status corresponds to an older object than the rest of the status.
The other option is to keep the current behavior, which wipes status on every update.
There was a problem hiding this comment.
Added obeservedGeneration for each enforcement point status.
|
|
||
| // VAPGenerationStatus represents the status of VAP generation. | ||
| type VAPGenerationStatus struct { | ||
| Generated bool `json:"generated,omitempty"` |
There was a problem hiding this comment.
Same comment about bool field vs. string field.
There was a problem hiding this comment.
Updated to string field.
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
| status.Status.TemplateUID = ct.GetUID() | ||
| status.Status.ObservedGeneration = ct.GetGeneration() | ||
| status.Status.Errors = nil | ||
| status.Status.VAPGenerationStatus = statusv1beta1.VAPGenerationStatus{} |
There was a problem hiding this comment.
This appears to have the same problem of wiping the generation status that constraints had.
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
| if err != nil && !errors.Is(err, celSchema.ErrCodeNotDefined) { | ||
| if err != nil { | ||
| logger.Error(err, "generateVap error") | ||
| if generateVap { |
There was a problem hiding this comment.
by Golang convention, generateVap would be false if ShouldGenerateVAP returns an error. We should probably report the error regardless.
There was a problem hiding this comment.
This would mean all rego templates will have this status message regarldess of if there is intention of VAP generation or not. When should we report this error?
- all the time, regardless of indication of VAP generation for CT?
- Or only when VAP is supposed to be generated but is not being generated?
I agree that we will be reporting this error for all rego CT when we go to beta.
There was a problem hiding this comment.
It sounds like ShouldGenerateVAP should be implemented differently then?
If we are struggling to implement the behaviors we want, that's a sign we should rethink primitives, not double-down on pre-existing shapes as if they were carved in stone, adding edge cases and complexity along the way.
It seems like ShouldGenerateVAP() should return (false, nil) if we get ErrCodeNotDefined:
There was a problem hiding this comment.
That would handle templates where VAP generation is not expected, like for Rego.
| err := r.reportErrorOnCTStatus(ctx, ErrUpdateCode, "Could not delete VAP object", status, err) | ||
| return err | ||
| } | ||
| status.Status.VAPGenerationStatus.State = DeletedVAPState |
There was a problem hiding this comment.
We probably shouldn't have a "deleted" state, since that's more imperative than declarative. We could have a "NotGenerated" state, or similar. But if we do that, we should use it consistently (i.e. any time VAP objects are not generated)
There was a problem hiding this comment.
Removed "delete" state
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
maxsmythe
left a comment
There was a problem hiding this comment.
LGTM once we fix the edge case of CTs without CEL code
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
| ErrGenerateVAPState = "error" | ||
| // GeneratedVAPState indicates a VAP was generated. | ||
| GeneratedVAPState = "generated" | ||
| // DeletedVAPState indicates a VAP was deleted. |
There was a problem hiding this comment.
Nope! Good catch, removed it.
| vapEnforcementPointStatus := constraintstatusv1beta1.EnforcementPointStatus{EnforcementPoint: enforcementPoint, State: state, ObservedGeneration: observedGeneration, Message: message} | ||
| for i, ep := range status.Status.EnforcementPointsStatus { | ||
| if ep.EnforcementPoint == enforcementPoint { | ||
| status.Status.EnforcementPointsStatus[i] = vapEnforcementPointStatus |
There was a problem hiding this comment.
enforcementPoint can be more than just vap enforcement point right? this var name vapEnforcementPointStatus makes it look like its just for the vap EP.
There was a problem hiding this comment.
updated the variable to make it generic.
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
What this PR does / why we need it:
Which issue(s) this PR fixes (optional, using
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when the PR gets merged):Fixes #3682
Special notes for your reviewer: