Merge pull request #129434 from xigang/crd_handler

refactor: simplify boolean expressions in CRD handler
This commit is contained in:
Kubernetes Prow Robot 2025-01-07 17:12:30 -08:00 committed by GitHub
commit 14dafc30c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -660,13 +660,13 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
return nil, fmt.Errorf("failed converting CRD validation to internal version: %v", err)
}
s, err := structuralschema.NewStructural(internalValidation.OpenAPIV3Schema)
if crd.Spec.PreserveUnknownFields == false && err != nil {
if !crd.Spec.PreserveUnknownFields && err != nil {
// This should never happen. If it does, it is a programming error.
utilruntime.HandleError(fmt.Errorf("failed to convert schema to structural: %v", err))
return nil, fmt.Errorf("the server could not properly serve the CR schema") // validation should avoid this
}
if crd.Spec.PreserveUnknownFields == false {
if !crd.Spec.PreserveUnknownFields {
// we don't own s completely, e.g. defaults are not deep-copied. So better make a copy here.
s = s.DeepCopy()