Skip to content

Commit

Permalink
updating shouldgeneratevap
Browse files Browse the repository at this point in the history
Signed-off-by: Jaydip Gabani <[email protected]>
  • Loading branch information
JaydipGabani committed Nov 20, 2024
1 parent 5dff00d commit 1afa5ac
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 43 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/constraint/constraint_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func (r *ReconcileConstraint) getOrCreatePodStatus(ctx context.Context, constrai
func ShouldGenerateVAP(ct *templates.ConstraintTemplate) (bool, error) {
source, err := celSchema.GetSourceFromTemplate(ct)
if err != nil {
return *DefaultGenerateVAP, err
return false, err
}
if source.GenerateVAP == nil {
return *DefaultGenerateVAP, nil
Expand Down
16 changes: 2 additions & 14 deletions pkg/controller/constraint/constraint_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,14 @@ func TestShouldGenerateVAP(t *testing.T) {
},
},
vapDefault: true,
expected: true,
expected: false,
wantErr: true,
},
{
name: "template with only Rego engine",
template: makeTemplateWithRegoEngine(),
vapDefault: true,
expected: true,
expected: false,
wantErr: true,
},
{
Expand Down Expand Up @@ -511,18 +511,6 @@ func TestShouldGenerateVAP(t *testing.T) {
expected: false,
wantErr: false,
},
{
name: "missing, default 'yes'",
template: makeTemplateWithCELEngine(nil),
vapDefault: true,
expected: true,
},
{
name: "missing, default 'no'",
template: makeTemplateWithCELEngine(nil),
vapDefault: false,
expected: false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,9 @@ func (r *ReconcileConstraintTemplate) handleUpdate(
t.Observe(unversionedCT)

generateVap, err := constraint.ShouldGenerateVAP(unversionedCT)
if err != nil {
if err != nil && !errors.Is(err, celSchema.ErrCELEngineMissing) {
logger.Error(err, "generateVap error")
if generateVap {
generateVap = false
status.Status.VAPGenerationStatus = &statusv1beta1.VAPGenerationStatus{State: ErrGenerateVAPState, ObservedGeneration: ct.GetGeneration(), Warning: fmt.Sprintf("ValidatingAdmissionPolicy is not generated: %s", err.Error())}
}
status.Status.VAPGenerationStatus = &statusv1beta1.VAPGenerationStatus{State: ErrGenerateVAPState, ObservedGeneration: ct.GetGeneration(), Warning: fmt.Sprintf("ValidatingAdmissionPolicy is not generated: %s", err.Error())}
}

if err := r.generateCRD(ctx, ct, proposedCRD, currentCRD, status, logger, generateVap); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,29 +399,6 @@ func TestReconcile(t *testing.T) {
t.Fatal(err)
}

logger.Info("Running test: Warning should be present on constrainttemplate for not able to generate VAP")
err = retry.OnError(testutils.ConstantRetry, func(_ error) bool {
return true
}, func() error {
statusObj := &statusv1beta1.ConstraintTemplatePodStatus{}
sName, err := statusv1beta1.KeyForConstraintTemplate(util.GetPodName(), constraintTemplate.GetName())
if err != nil {
return err
}
key := types.NamespacedName{Name: sName, Namespace: util.GetNamespace()}
if err := c.Get(ctx, key, statusObj); err != nil {
return err
}

if statusObj.Status.VAPGenerationStatus == nil || statusObj.Status.VAPGenerationStatus.Warning == "" {
return fmt.Errorf("expected warning message")
}
return nil
})
if err != nil {
t.Fatal(err)
}

logger.Info("Running test: EnforcementPointStatus should indicate missing CEL engine for constraint using VAP enforcementPoint with rego templates")
cstr := newDenyAllCstrWithScopedEA(suffix, util.VAPEnforcementPoint)
err = retry.OnError(testutils.ConstantRetry, func(_ error) bool {
Expand Down

0 comments on commit 1afa5ac

Please sign in to comment.