Skip to content

Bug: optionalfields incorrectly requires pointer for enum-like string field with default #128

@camilamacedo86

Description

@camilamacedo86

Bug: optionalfields incorrectly requires pointer for enum-like field with default

The optionalfields rule in kube-api-linter is flagging a field that should be valid:

// +optional
// +kubebuilder:default:=Allow
ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"`

Error:

optionalfields: field ConcurrencyPolicy is optional and should be a pointer

However:

  • The field has a default (Allow)
  • It's not semantically optional (default is always injected)
  • It's an enum-style string alias (not a struct or slice)

Upstream Kubernetes APIs (e.g. batch/v1) define similar fields without pointers.

Suggestion

The rule should not require a pointer if:

  • The field is a basic or alias type (e.g. string)
  • It has +optional and +kubebuilder:default
  • The tag includes omitempty

This avoids unnecessary boilerplate and aligns with upstream standards.

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