Skip to content

Flaky behaviour using custom slice types and listType marker #435

@avorima

Description

@avorima

controller-gen will sometimes fail to create the CRD manifests when using a custom slice type, e.g. type Foos []Foo and the listType and listMapKey markers.

To reproduce this create a sample project with kubebuilder v2.3.1:

kubebuilder init --repo temp
kubebuilder create api --group ship --version v1beta1 --kind Frigate

and then add the following to the api/v1beta1/frigate_types.go file:

// FrigateStatus defines the observed state of Frigate
type FrigateStatus struct {
        // +kubebuilder:validation:Type=array
        // +optional
        // +listType=map
        // +listMapKey=type
        Conditions Conditions `json:"conditions,omitempty"`
}

type Conditions []Condition

type Condition struct {
        Type   string `json:"type,omitemtpy"`
        Status string `json:"status,omitempty"`
}

Running make manifests will then on occasion yield the following errors:

/tmp/test/api/v1beta1/frigate_types.go:35:2: must apply listType to an array
/tmp/test/api/v1beta1/frigate_types.go:35:2: must apply listMapKey to an associative-list

If the +kubebuilder:validation:Type=array marker is above the type definition it fails consistently.

I have verified that this occurs with both v0.2.5 and v0.3.0.

The issue seem to come the fact that both listType and kubebuilder:validation:Type markers implement ApplyFirst to ensure they get applied before all other markers. But since applyMarkers loops over a map, the order is random.

Metadata

Metadata

Assignees

No one assigned

    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