refactor: simplify boolean expressions in CRD handler

Signed-off-by: xigang <wangxigang2014@gmail.com>
This commit is contained in:
xigang 2024-12-31 11:15:29 +08:00
parent 71f32f9930
commit deb234c9d5

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()