1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-15 12:17:56 +00:00

fix: check if client is set in CEL validations (#8099)

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
This commit is contained in:
Mariam Fahmy 2023-08-23 18:22:37 +03:00 committed by GitHub
parent e1783e7375
commit 333845677a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View file

@ -113,12 +113,16 @@ OuterLoop:
} }
} }
} }
var client engineapi.Client
if c.Client != nil {
client = adapters.Client(c.Client)
}
rclient := registryclient.NewOrDie() rclient := registryclient.NewOrDie()
eng := engine.NewEngine( eng := engine.NewEngine(
cfg, cfg,
config.NewDefaultMetricsConfiguration(), config.NewDefaultMetricsConfiguration(),
jmespath.New(cfg), jmespath.New(cfg),
adapters.Client(c.Client), client,
factories.DefaultRegistryClientFactory(adapters.RegistryClient(rclient), nil), factories.DefaultRegistryClientFactory(adapters.RegistryClient(rclient), nil),
imageverifycache.DisabledImageVerifyCache(), imageverifycache.DisabledImageVerifyCache(),
store.ContextLoaderFactory(nil), store.ContextLoaderFactory(nil),

View file

@ -77,7 +77,7 @@ func (h validateCELHandler) Process(
auditExpressions := convertAuditAnnotations(auditAnnotations) auditExpressions := convertAuditAnnotations(auditAnnotations)
// get the parameter resource if exists // get the parameter resource if exists
if hasParam { if hasParam && h.client != nil {
paramKind := rule.Validation.CEL.GetParamKind() paramKind := rule.Validation.CEL.GetParamKind()
paramRef := rule.Validation.CEL.GetParamRef() paramRef := rule.Validation.CEL.GetParamRef()
@ -122,7 +122,7 @@ func (h validateCELHandler) Process(
if gvk.Kind == "Namespace" && gvk.Version == "v1" && gvk.Group == "" { if gvk.Kind == "Namespace" && gvk.Version == "v1" && gvk.Group == "" {
namespaceName = "" namespaceName = ""
} }
if namespaceName != "" { if namespaceName != "" && h.client != nil {
namespace, err = h.client.GetNamespace(ctx, namespaceName, metav1.GetOptions{}) namespace, err = h.client.GetNamespace(ctx, namespaceName, metav1.GetOptions{})
if err != nil { if err != nil {
return resource, handlers.WithResponses( return resource, handlers.WithResponses(