Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crd-generator and annotations #2959

Closed
maledoux opened this issue Apr 1, 2021 · 10 comments · Fixed by #4348
Closed

crd-generator and annotations #2959

maledoux opened this issue Apr 1, 2021 · 10 comments · Fixed by #4348
Labels
component/crd-generator Related to the CRD generator enhancement

Comments

@maledoux
Copy link

maledoux commented Apr 1, 2021

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 ?

@rohanKanojia
Copy link
Member

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

@maledoux
Copy link
Author

maledoux commented Apr 7, 2021

@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

@manusa
Copy link
Member

manusa commented Apr 7, 2021

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.

@metacosm
Copy link
Collaborator

metacosm commented Apr 7, 2021

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

@stale
Copy link

stale bot commented Jul 6, 2021

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!

@xlf12
Copy link

xlf12 commented Oct 1, 2021

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.

@stale
Copy link

stale bot commented Dec 30, 2021

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
Copy link

stale bot commented Oct 16, 2022

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 stale bot added the status/stale label Oct 16, 2022
@stale stale bot closed this as completed Oct 23, 2022
@manusa
Copy link
Member

manusa commented Oct 24, 2022

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

@andreaTP
Copy link
Member

@manusa correct closed in #4348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/crd-generator Related to the CRD generator enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants