From a69b1ea2d5a326fa5a868072b67e5e1c7e01f539 Mon Sep 17 00:00:00 2001 From: Kevin Conner Date: Mon, 21 Oct 2024 08:09:55 -0700 Subject: [PATCH] Fix error check Signed-off-by: Kevin Conner Kubernetes-commit: e7e1fb7234264b6f0785ad9fdd29e90c5da36002 --- pkg/admission/plugin/policy/mutating/dispatcher.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/admission/plugin/policy/mutating/dispatcher.go b/pkg/admission/plugin/policy/mutating/dispatcher.go index 81e8d3479..918a07d0f 100644 --- a/pkg/admission/plugin/policy/mutating/dispatcher.go +++ b/pkg/admission/plugin/policy/mutating/dispatcher.go @@ -162,6 +162,11 @@ func (d *dispatcher) dispatchInvocations( } invocationKey, invocationKeyErr := keyFor(invocation) + if invocationKeyErr != nil { + // This should never happen. It occurs if there is a programming + // error causing the Param not to be a valid object. + return nil, k8serrors.NewInternalError(invocationKeyErr) + } if reinvokeCtx.IsReinvoke() && !policyReinvokeCtx.ShouldReinvoke(invocationKey) { continue } @@ -170,12 +175,6 @@ func (d *dispatcher) dispatchInvocations( // Mutations for a single invocation of a MutatingAdmissionPolicy are evaluated // in order. for mutationIndex := range invocation.Policy.Spec.Mutations { - if invocationKeyErr != nil { - // This should never happen. It occurs if there is a programming - // error causing the Param not to be a valid object. - return nil, k8serrors.NewInternalError(invocationKeyErr) - } - lastVersionedAttr = versionedAttr if versionedAttr.VersionedObject == nil { // Do not call patchers if there is no object to patch. continue