Skip to content

KAL recommends markers on Schemaless fields #120

@sbueringer

Description

@sbueringer

Finding

api/core/v1beta2/clusterclass_types.go:792:2: maxlength: field AllOf must have a maximum items, add kubebuilder:validation:MaxItems marker (kubeapilinter)
        AllOf []JSONSchemaProps `json:"allOf,omitempty"`
        ^

api/core/v1beta2/clusterclass_types.go:792:2: ssatags: AllOf should have a listType marker for proper Server-Side Apply behavior (atomic, set, or map) (kubeapilinter)
        AllOf []JSONSchemaProps `json:"allOf,omitempty"`
        ^

Types

	// allOf specifies that the variable must validate against all of the subschemas in the array.
	// NOTE: This field uses PreserveUnknownFields and Schemaless,
	// because recursive validation is not possible.
	// +optional
	// +kubebuilder:pruning:PreserveUnknownFields
	// +kubebuilder:validation:Schemaless
	AllOf []JSONSchemaProps `json:"allOf,omitempty"`

Field in CRD YAML:

                                  allOf:
                                    description: |-
                                      allOf specifies that the variable must validate against all of the subschemas in the array.
                                      NOTE: This field uses PreserveUnknownFields and Schemaless,
                                      because recursive validation is not possible.
                                    x-kubernetes-preserve-unknown-fields: true

If I add the markers to the field I get this error from controller-gen

api/core/v1beta2/clusterclass_types.go:793:2: must apply maxitem to an array
/api/core/v1beta2/clusterclass_types.go:794:2: must apply listType to an array, found

I think controller-gen is right that if a field is Schemaless we shouldn't add markers to extend the schema

(We have to use Schemaless in this case because otherwise we would end up with a recursive schema)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions