@@ -11,6 +11,7 @@ import (
1111
1212 "helm.sh/helm/v3/pkg/chartutil"
1313
14+ apiconstraints "github.com/open-policy-agent/frameworks/constraint/pkg/apis/constraints"
1415 constraintclient "github.com/open-policy-agent/frameworks/constraint/pkg/client"
1516 "github.com/open-policy-agent/frameworks/constraint/pkg/client/drivers/rego"
1617 "github.com/open-policy-agent/frameworks/constraint/pkg/core/templates"
@@ -112,7 +113,11 @@ func getConstraintClient() (*constraintclient.Client, error) {
112113 return nil , fmt .Errorf ("could not create rego driver: %w" , err )
113114 }
114115
115- c , err := constraintclient .NewClient (constraintclient .Targets (& target.K8sValidationTarget {}), constraintclient .Driver (driver ))
116+ c , err := constraintclient .NewClient (
117+ constraintclient .Targets (& target.K8sValidationTarget {}),
118+ constraintclient .Driver (driver ),
119+ constraintclient .EnforcementPoints (apiconstraints .WebhookEnforcementPoint ),
120+ )
116121 if err != nil {
117122 return nil , fmt .Errorf ("could not create constraint client: %w" , err )
118123 }
@@ -140,6 +145,10 @@ func AddSafeguardCRIP() {
140145
141146// loads constraint templates, constraints into constraint client
142147func loadConstraintTemplates (ctx context.Context , c * constraintclient.Client , constraintTemplates []* templates.ConstraintTemplate ) error {
148+ if c == nil {
149+ return fmt .Errorf ("constraint client is nil" )
150+ }
151+
143152 // AddTemplate adds the template source code to OPA and registers the CRD with the client for
144153 // schema validation on calls to AddConstraint. On error, the responses return value
145154 // will still be populated so that partial results can be analyzed.
@@ -154,6 +163,10 @@ func loadConstraintTemplates(ctx context.Context, c *constraintclient.Client, co
154163}
155164
156165func loadConstraints (ctx context.Context , c * constraintclient.Client , constraints []* unstructured.Unstructured ) error {
166+ if c == nil {
167+ return fmt .Errorf ("constraint client is nil" )
168+ }
169+
157170 // AddConstraint validates the constraint and, if valid, inserts it into OPA.
158171 // On error, the responses return value will still be populated so that
159172 // partial results can be analyzed.
@@ -168,6 +181,10 @@ func loadConstraints(ctx context.Context, c *constraintclient.Client, constraint
168181}
169182
170183func loadManifestObjects (ctx context.Context , c * constraintclient.Client , objects []* unstructured.Unstructured ) error {
184+ if c == nil {
185+ return fmt .Errorf ("constraint client is nil" )
186+ }
187+
171188 // AddData inserts the provided data into OPA for every target that can handle the data.
172189 // On error, the responses return value will still be populated so that
173190 // partial results can be analyzed.
@@ -198,6 +215,10 @@ func IsYAML(path string) bool {
198215
199216// getObjectViolations executes validation on manifests based on loaded constraint templates and returns a map of manifest name to list of objectViolations
200217func getObjectViolations (ctx context.Context , c * constraintclient.Client , objects []* unstructured.Unstructured ) (map [string ][]string , error ) {
218+ if c == nil {
219+ return nil , fmt .Errorf ("constraint client is nil" )
220+ }
221+
201222 // Review makes sure the provided object satisfies all stored constraints.
202223 // On error, the responses return value will still be populated so that
203224 // partial results can be analyzed.
0 commit comments