use of io.strimzi.crdgenerator.annotations.Crd in project strimzi-kafka-operator by strimzi.
the class CrdGenerator method buildSpec.
@SuppressWarnings("NPathComplexity")
private ObjectNode buildSpec(ApiVersion crdApiVersion, Crd.Spec crd, Class<? extends CustomResource> crdClass) {
checkKubeVersionsSupportCrdVersion(crdApiVersion);
ObjectNode result = nf.objectNode();
result.put("group", crd.group());
ArrayNode versions = nf.arrayNode();
// Kube apiserver with CRD v1beta1 is picky about only using per-version subresources, schemas and printercolumns
// if they actually differ across the versions. If they're the same, it insists these things are
// declared top level
// With CRD v1 they have to be per-version :face-with-rolling-eyes:
Map<ApiVersion, ObjectNode> subresources = buildSubresources(crd);
boolean perVersionSubResources = needsPerVersion("subresources", subresources);
Map<ApiVersion, ObjectNode> schemas = buildSchemas(crd, crdClass);
boolean perVersionSchemas = needsPerVersion("schemas", schemas);
Map<ApiVersion, ArrayNode> printerColumns = buildPrinterColumns(crd);
boolean perVersionPrinterColumns = needsPerVersion("additionalPrinterColumns", printerColumns);
result.set("names", buildNames(crd.names()));
result.put("scope", crd.scope());
if (!perVersionPrinterColumns) {
ArrayNode cols = printerColumns.values().iterator().next();
if (!cols.isEmpty()) {
result.set("additionalPrinterColumns", cols);
}
}
if (!perVersionSubResources) {
ObjectNode subresource = subresources.values().iterator().next();
if (!subresource.isEmpty()) {
result.set("subresources", subresource);
}
}
if (conversionStrategy instanceof WebhookConversionStrategy) {
// "Webhook": must be None if spec.preserveUnknownFields is true
result.put("preserveUnknownFields", false);
}
result.set("conversion", buildConversion(crdApiVersion));
for (Crd.Spec.Version version : crd.versions()) {
ApiVersion crApiVersion = ApiVersion.parse(version.name());
if (!shouldIncludeVersion(crApiVersion)) {
continue;
}
ObjectNode versionNode = versions.addObject();
versionNode.put("name", crApiVersion.toString());
versionNode.put("served", servedVersion != null ? servedVersion.contains(crApiVersion) : version.served());
versionNode.put("storage", storageVersion != null ? crApiVersion.equals(storageVersion) : version.storage());
if (perVersionSubResources) {
ObjectNode subresourcesForVersion = subresources.get(crApiVersion);
if (!subresourcesForVersion.isEmpty()) {
versionNode.set("subresources", subresourcesForVersion);
}
}
if (perVersionPrinterColumns) {
ArrayNode cols = printerColumns.get(crApiVersion);
if (!cols.isEmpty()) {
versionNode.set("additionalPrinterColumns", cols);
}
}
if (perVersionSchemas) {
versionNode.set("schema", schemas.get(crApiVersion));
}
}
result.set("versions", versions);
if (crdApiVersion.compareTo(V1) < 0 && targetKubeVersions.intersects(KubeVersion.parseRange("1.11-1.15"))) {
result.put("version", Arrays.stream(crd.versions()).map(v -> ApiVersion.parse(v.name())).filter(this::shouldIncludeVersion).findFirst().map(ApiVersion::toString).orElseThrow());
}
if (!perVersionSchemas) {
result.set("validation", schemas.values().iterator().next());
}
return result;
}
use of io.strimzi.crdgenerator.annotations.Crd in project strimzi-kafka-operator by strimzi.
the class CrdGenerator method buildStatus.
private ObjectNode buildStatus(Crd.Spec crd, ApiVersion crApiVersion) {
ObjectNode status;
long length = Arrays.stream(crd.subresources().status()).filter(st -> ApiVersion.parseRange(st.apiVersion()).contains(crApiVersion)).count();
if (length == 1) {
status = nf.objectNode();
} else if (length > 1) {
err("Each custom resource definition can have only one status sub-resource.");
status = null;
} else {
status = null;
}
return status;
}
use of io.strimzi.crdgenerator.annotations.Crd in project strimzi-kafka-operator by strimzi.
the class DocGenerator method generate.
public void generate(Class<? extends CustomResource> crdClass) throws IOException {
Crd crd = crdClass.getAnnotation(Crd.class);
appendAnchor(crd, crdClass);
appendHeading(crd, "`" + crd.spec().names().kind() + "`");
appendCommonTypeDoc(crd, crdClass);
}
use of io.strimzi.crdgenerator.annotations.Crd in project strimzi by strimzi.
the class CrdGenerator method buildSpec.
@SuppressWarnings("NPathComplexity")
private ObjectNode buildSpec(ApiVersion crdApiVersion, Crd.Spec crd, Class<? extends CustomResource> crdClass) {
checkKubeVersionsSupportCrdVersion(crdApiVersion);
ObjectNode result = nf.objectNode();
result.put("group", crd.group());
ArrayNode versions = nf.arrayNode();
// Kube apiserver with CRD v1beta1 is picky about only using per-version subresources, schemas and printercolumns
// if they actually differ across the versions. If they're the same, it insists these things are
// declared top level
// With CRD v1 they have to be per-version :face-with-rolling-eyes:
Map<ApiVersion, ObjectNode> subresources = buildSubresources(crd);
boolean perVersionSubResources = needsPerVersion("subresources", subresources);
Map<ApiVersion, ObjectNode> schemas = buildSchemas(crd, crdClass);
boolean perVersionSchemas = needsPerVersion("schemas", schemas);
Map<ApiVersion, ArrayNode> printerColumns = buildPrinterColumns(crd);
boolean perVersionPrinterColumns = needsPerVersion("additionalPrinterColumns", printerColumns);
result.set("names", buildNames(crd.names()));
result.put("scope", crd.scope());
if (!perVersionPrinterColumns) {
ArrayNode cols = printerColumns.values().iterator().next();
if (!cols.isEmpty()) {
result.set("additionalPrinterColumns", cols);
}
}
if (!perVersionSubResources) {
ObjectNode subresource = subresources.values().iterator().next();
if (!subresource.isEmpty()) {
result.set("subresources", subresource);
}
}
if (conversionStrategy instanceof WebhookConversionStrategy) {
// "Webhook": must be None if spec.preserveUnknownFields is true
result.put("preserveUnknownFields", false);
}
result.set("conversion", buildConversion(crdApiVersion));
for (Crd.Spec.Version version : crd.versions()) {
ApiVersion crApiVersion = ApiVersion.parse(version.name());
if (!shouldIncludeVersion(crApiVersion)) {
continue;
}
ObjectNode versionNode = versions.addObject();
versionNode.put("name", crApiVersion.toString());
versionNode.put("served", servedVersion != null ? servedVersion.contains(crApiVersion) : version.served());
versionNode.put("storage", storageVersion != null ? crApiVersion.equals(storageVersion) : version.storage());
if (perVersionSubResources) {
ObjectNode subresourcesForVersion = subresources.get(crApiVersion);
if (!subresourcesForVersion.isEmpty()) {
versionNode.set("subresources", subresourcesForVersion);
}
}
if (perVersionPrinterColumns) {
ArrayNode cols = printerColumns.get(crApiVersion);
if (!cols.isEmpty()) {
versionNode.set("additionalPrinterColumns", cols);
}
}
if (perVersionSchemas) {
versionNode.set("schema", schemas.get(crApiVersion));
}
}
result.set("versions", versions);
if (crdApiVersion.compareTo(V1) < 0 && targetKubeVersions.intersects(KubeVersion.parseRange("1.11-1.15"))) {
result.put("version", Arrays.stream(crd.versions()).map(v -> ApiVersion.parse(v.name())).filter(this::shouldIncludeVersion).findFirst().map(ApiVersion::toString).orElseThrow());
}
if (!perVersionSchemas) {
result.set("validation", schemas.values().iterator().next());
}
return result;
}
use of io.strimzi.crdgenerator.annotations.Crd in project strimzi by strimzi.
the class DocGenerator method generate.
public void generate(Class<? extends CustomResource> crdClass) throws IOException {
Crd crd = crdClass.getAnnotation(Crd.class);
appendAnchor(crd, crdClass);
appendHeading(crd, "`" + crd.spec().names().kind() + "`");
appendCommonTypeDoc(crd, crdClass);
}
Aggregations