diff --git a/cmd/cli/kubectl-kyverno/utils/common/kyverno_policies_types.go b/cmd/cli/kubectl-kyverno/utils/common/kyverno_policies_types.go index 192b15a915..36d8167490 100644 --- a/cmd/cli/kubectl-kyverno/utils/common/kyverno_policies_types.go +++ b/cmd/cli/kubectl-kyverno/utils/common/kyverno_policies_types.go @@ -113,12 +113,16 @@ OuterLoop: } } } + var client engineapi.Client + if c.Client != nil { + client = adapters.Client(c.Client) + } rclient := registryclient.NewOrDie() eng := engine.NewEngine( cfg, config.NewDefaultMetricsConfiguration(), jmespath.New(cfg), - adapters.Client(c.Client), + client, factories.DefaultRegistryClientFactory(adapters.RegistryClient(rclient), nil), imageverifycache.DisabledImageVerifyCache(), store.ContextLoaderFactory(nil), diff --git a/pkg/engine/handlers/validation/validate_cel.go b/pkg/engine/handlers/validation/validate_cel.go index d15a9edaa6..bcf7e1f13e 100644 --- a/pkg/engine/handlers/validation/validate_cel.go +++ b/pkg/engine/handlers/validation/validate_cel.go @@ -77,7 +77,7 @@ func (h validateCELHandler) Process( auditExpressions := convertAuditAnnotations(auditAnnotations) // get the parameter resource if exists - if hasParam { + if hasParam && h.client != nil { paramKind := rule.Validation.CEL.GetParamKind() paramRef := rule.Validation.CEL.GetParamRef() @@ -122,7 +122,7 @@ func (h validateCELHandler) Process( if gvk.Kind == "Namespace" && gvk.Version == "v1" && gvk.Group == "" { namespaceName = "" } - if namespaceName != "" { + if namespaceName != "" && h.client != nil { namespace, err = h.client.GetNamespace(ctx, namespaceName, metav1.GetOptions{}) if err != nil { return resource, handlers.WithResponses(