From fc1e66a38a35a5b303ebc11f89b5c82301154706 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Thu, 16 Jan 2025 20:18:49 +0100 Subject: [PATCH] apis/apis: clarify that binding.spec.reference.export is never nil b/c validation Signed-off-by: Dr. Stefan Schimanski --- pkg/admission/apibinding/apibinding_admission.go | 1 + pkg/admission/apibinding/validation.go | 3 +-- pkg/reconciler/apis/apibinding/conflict_checker.go | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pkg/admission/apibinding/apibinding_admission.go b/pkg/admission/apibinding/apibinding_admission.go index 304b7b69df3..8dfddfa8c70 100644 --- a/pkg/admission/apibinding/apibinding_admission.go +++ b/pkg/admission/apibinding/apibinding_admission.go @@ -106,6 +106,7 @@ func (o *apiBindingAdmission) Admit(ctx context.Context, a admission.Attributes, } if apiBinding.Spec.Reference.Export == nil { + // should not happen due to validation. return nil } diff --git a/pkg/admission/apibinding/validation.go b/pkg/admission/apibinding/validation.go index 66bb9c00f6a..f5f59b30e6b 100644 --- a/pkg/admission/apibinding/validation.go +++ b/pkg/admission/apibinding/validation.go @@ -54,8 +54,7 @@ func ValidateAPIBindingUpdate(oldBinding, newBinding *apisv1alpha1.APIBinding) f // ValidateAPIBindingReference validates an APIBinding's BindingReference. func ValidateAPIBindingReference(reference apisv1alpha1.BindingReference, path *field.Path) field.ErrorList { allErrs := field.ErrorList{} - - // For now, field "export" is required via OpenAPI. But just in case... + if reference.Export == nil { allErrs = append(allErrs, field.Required(path.Child("export"), "")) } else if reference.Export.Name == "" { diff --git a/pkg/reconciler/apis/apibinding/conflict_checker.go b/pkg/reconciler/apis/apibinding/conflict_checker.go index 5fd3f8826f3..76f9df82e7d 100644 --- a/pkg/reconciler/apis/apibinding/conflict_checker.go +++ b/pkg/reconciler/apis/apibinding/conflict_checker.go @@ -72,11 +72,7 @@ func newConflictChecker(clusterName logicalcluster.Name, } for _, b := range bindings { if b.Spec.Reference.Export == nil { - continue - } - - if b.Spec.Reference.Export == nil { - // this should not happen because of OpenAPI + // this should not happen because of validation. return nil, fmt.Errorf("APIBinding %s|%s has no cluster reference", logicalcluster.From(b), b.Name) } path := logicalcluster.NewPath(b.Spec.Reference.Export.Path)