kubernetes-client
kubernetes-client copied to clipboard
crd-generator and annotations
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 ?
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 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
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.
Enums are supported. We could add more annotations to support more descriptive CRDs, indeed.
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!
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.
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!
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!
Hi @andreaTP, Do you think we should reopen this one? AFAIR, this functionality was implemented already (needs link to PRs/issue).
@manusa correct closed in #4348