From f618717f755c81509d2535f0f8fd00ac59320f9f Mon Sep 17 00:00:00 2001 From: Ammar Yasser Date: Fri, 26 Jul 2024 13:49:51 +0300 Subject: [PATCH] fix: Check for the client being nil before applying a mutation (#10726) Signed-off-by: aerosouund Co-authored-by: shuting --- pkg/engine/mutation.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/engine/mutation.go b/pkg/engine/mutation.go index d84e2a50ed..c4d70769f3 100644 --- a/pkg/engine/mutation.go +++ b/pkg/engine/mutation.go @@ -2,6 +2,7 @@ package engine import ( "context" + "fmt" "time" "github.com/go-logr/logr" @@ -36,6 +37,9 @@ func (e *engine) mutate( return nil, nil } if !policyContext.AdmissionOperation() && rule.HasMutateExisting() { + if e.client == nil { + return nil, fmt.Errorf("Handler factory requires a client but a nil client was passed, likely due to a bug or unsupported operation.") + } return mutation.NewMutateExistingHandler(e.client) } return mutation.NewMutateResourceHandler()