Skip to content

Default annotation not working as expected #5501

@raminqaf

Description

@raminqaf

Describe the bug

I am using the new Default annotation to generate my CRDs with defaults. My spec class looks like this:

@Data
@Jacksonized
@Builder
public class MyAppSpec {
        @Required
        private String name;
        @Default("1")
        private int replicaCount;
        @Required
        private String image;
        @Required
        private String imageTag;
        @Default("Always")
        private String imagePullPolicy;
        @Default("false")
        private boolean deployment;
}

And the generated CRD is missing the default values. The output looks like this:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: myapps.com.organisation.tree
spec:
  group: com.organisation.tree
  names:
    kind: MyApp
    plural: myapps
    singular: myapp
  scope: Namespaced
  versions:
  - name: v1
    schema:
      openAPIV3Schema:
        properties:
          spec:
            properties:
              deployment:
                type: boolean
              image:
                type: string
              imagePullPolicy:
                type: string
              imageTag:
                type: string
              name:
                type: string
              replicaCount:
                type: integer
            required:
            - name
            - image
            - imageTag
            type: object
          status:
            properties:
              ready:
                type: boolean
            type: object
        type: object
    served: true
    storage: true
    subresources:
      status: {}

Fabric8 Kubernetes Client version

6.9.0

Steps to reproduce

  1. Create a spec POJO
  2. Annotate fields with @Default
  3. Generate the CRD

Expected behavior

To have default field in the generated CRD

Runtime

Kubernetes (vanilla)

Kubernetes API Server version

1.25.3@latest

Environment

macOS

Fabric8 Kubernetes Client Logs

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions