kubernetes-client icon indicating copy to clipboard operation
kubernetes-client copied to clipboard

crd-generator and annotations

Open maledoux opened this issue 4 years ago • 7 comments

Does the crd-generator have the ability to parse annotations in the Spec and Status classes to add description, enum, min/max values, required attributes etc... on the properties so the are generated in the yaml ?

In the usage, it is mentioned: Several annotations are available to override the default behavior if it doesn't fit your needs

Here are my objects:

@Group("storage.test.com")
@Version("v1")
public class Database extends CustomResource<DatabaseSpec, DatabaseStatus> implements Namespaced {

}
public class DatabaseSpec {

  private String engine;

  public String getEngine() {
    return engine;
  }

  public void setEngine(String engine) {
    this.engine = engine;
  }
}
public class DatabaseStatus {

  private String version;

  public String getVersion() {
    return version;
  }

  public void setVersion(String version) {
    this.version = version;
  }
}

and the resulting YAML:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: databases.storage.test.com
spec:
  group: storage.test.com
  names:
    kind: Database
    plural: databases
    singular: database
  scope: Namespaced
  versions:
  - name: v1
    schema:
      openAPIV3Schema:
        properties:
          status:
            properties:
              version:
                type: string
            type: object
          spec:
            properties:
              engine:
                type: string
            type: object
        type: object
    served: true
    storage: true
    subresources:
      status: {}

I would like the output to be something like this:

    schema:
      openAPIV3Schema:
        properties:
          status:
            properties:
              version:
                type: string
            type: object
          spec:
            description: DatabaseSpec represents the desired state of a Database.
            properties:
              engine:
                description: Engine is the underlying database engine hosting this database.
                enum:
                - mongodb
                - mysqldb
                type: string
            type: object
            required:
            - engine
        type: object

Are the annotations mentioned in the usage meant to generate this type of information in the YAML ?

maledoux avatar Apr 01 '21 16:04 maledoux

I'm not sure about this. I think @metacosm can provide some insights on whether it's supported or if it's a valid use case

rohanKanojia avatar Apr 05 '21 10:04 rohanKanojia

@rohanKanojia Just wondering if the crd generation will include annotation parsing for CRD validation, like the Operator SDK has with kubebuilder. https://book.kubebuilder.io/reference/markers/crd-validation.html

maledoux avatar Apr 07 '21 14:04 maledoux

So far it's not supported yet (unless I missed something).

In scope of #2670 and from a discussion in #2611, there was a proposal for something like this:

The implementation for this method is were we should be really creative in terms of inferring OpenAPIV3Schema from the POJO fields, annotations, JSR 303, etc.

manusa avatar Apr 07 '21 14:04 manusa

Enums are supported. We could add more annotations to support more descriptive CRDs, indeed.

metacosm avatar Apr 07 '21 18:04 metacosm

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

stale[bot] avatar Jul 06 '21 19:07 stale[bot]

I would also be happy about such a functionality. We have learned from the Spring framework that the documentation for so-called configuration properties is generated from the Java doc. I don't know how the generation is done here. The use of Java-Doc would of course be interesting. If the code is only generated on the compiled classes, this would of course not be possible.

xlf12 avatar Oct 01 '21 06:10 xlf12

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

stale[bot] avatar Dec 30 '21 07:12 stale[bot]

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

stale[bot] avatar Oct 16 '22 05:10 stale[bot]

Hi @andreaTP, Do you think we should reopen this one? AFAIR, this functionality was implemented already (needs link to PRs/issue).

manusa avatar Oct 24 '22 08:10 manusa

@manusa correct closed in #4348

andreaTP avatar Oct 26 '22 11:10 andreaTP