use of io.strimzi.crdgenerator.annotations.Crd in project strimzi 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 by strimzi.
the class CrdGenerator method buildScale.
private ObjectNode buildScale(Crd.Spec crd, ApiVersion crApiVersion) {
ObjectNode scaleNode;
Crd.Spec.Subresources.Scale[] scales = crd.subresources().scale();
if (scales.length > 1 && !KubeVersion.supportsSchemaPerVersion(targetKubeVersions)) {
err("Multiple scales specified but " + targetKubeVersions.lower() + " doesn't support schema per version");
}
List<Crd.Spec.Subresources.Scale> filteredScales = Arrays.stream(scales).filter(sc -> ApiVersion.parseRange(sc.apiVersion()).contains(crApiVersion)).collect(Collectors.toList());
if (filteredScales.size() == 1) {
scaleNode = nf.objectNode();
Crd.Spec.Subresources.Scale scale = filteredScales.get(0);
scaleNode.put("specReplicasPath", scale.specReplicasPath());
scaleNode.put("statusReplicasPath", scale.statusReplicasPath());
if (!scale.labelSelectorPath().isEmpty()) {
scaleNode.put("labelSelectorPath", scale.labelSelectorPath());
}
} else if (filteredScales.size() > 1 && KubeVersion.supportsSchemaPerVersion(targetKubeVersions)) {
throw new RuntimeException("Each custom resource definition can have only one scale sub-resource.");
} else {
scaleNode = null;
}
return scaleNode;
}
use of io.strimzi.crdgenerator.annotations.Crd in project strimzi by strimzi.
the class CrdGenerator method buildAdditionalPrinterColumns.
private ArrayNode buildAdditionalPrinterColumns(Crd.Spec crd, ApiVersion crApiVersion) {
ArrayNode cols = nf.arrayNode();
if (crd.additionalPrinterColumns().length != 0) {
for (Crd.Spec.AdditionalPrinterColumn col : Arrays.stream(crd.additionalPrinterColumns()).filter(col -> crApiVersion == null || ApiVersion.parseRange(col.apiVersion()).contains(crApiVersion)).collect(Collectors.toList())) {
ObjectNode colNode = cols.addObject();
colNode.put("name", col.name());
colNode.put("description", col.description());
colNode.put(crdApiVersion.compareTo(V1) >= 0 ? "jsonPath" : "JSONPath", col.jsonPath());
colNode.put("type", col.type());
if (col.priority() != 0) {
colNode.put("priority", col.priority());
}
if (!col.format().isEmpty()) {
colNode.put("format", col.format());
}
}
}
return cols;
}
use of io.strimzi.crdgenerator.annotations.Crd in project strimzi by strimzi.
the class CrdGenerator method generate.
public int generate(Class<? extends CustomResource> crdClass, Writer out) throws IOException {
ObjectNode node = nf.objectNode();
Crd crd = crdClass.getAnnotation(Crd.class);
if (crd == null) {
err(crdClass + " is not annotated with @Crd");
} else {
node.put("apiVersion", "apiextensions.k8s.io/" + crdApiVersion).put("kind", "CustomResourceDefinition").putObject("metadata").put("name", crd.spec().names().plural() + "." + crd.spec().group());
if (!labels.isEmpty()) {
((ObjectNode) node.get("metadata")).putObject("labels").setAll(labels.entrySet().stream().collect(Collectors.<Map.Entry<String, String>, String, JsonNode, LinkedHashMap<String, JsonNode>>toMap(Map.Entry::getKey, e -> new TextNode(e.getValue().replace("%group%", crd.spec().group()).replace("%plural%", crd.spec().names().plural()).replace("%singular%", crd.spec().names().singular())), (x, y) -> x, LinkedHashMap::new)));
}
node.set("spec", buildSpec(crdApiVersion, crd.spec(), crdClass));
}
mapper.writeValue(out, node);
return numErrors;
}
use of io.strimzi.crdgenerator.annotations.Crd in project strimzi-kafka-operator by strimzi.
the class CrdGenerator method buildAdditionalPrinterColumns.
private ArrayNode buildAdditionalPrinterColumns(Crd.Spec crd, ApiVersion crApiVersion) {
ArrayNode cols = nf.arrayNode();
if (crd.additionalPrinterColumns().length != 0) {
for (Crd.Spec.AdditionalPrinterColumn col : Arrays.stream(crd.additionalPrinterColumns()).filter(col -> crApiVersion == null || ApiVersion.parseRange(col.apiVersion()).contains(crApiVersion)).collect(Collectors.toList())) {
ObjectNode colNode = cols.addObject();
colNode.put("name", col.name());
colNode.put("description", col.description());
colNode.put(crdApiVersion.compareTo(V1) >= 0 ? "jsonPath" : "JSONPath", col.jsonPath());
colNode.put("type", col.type());
if (col.priority() != 0) {
colNode.put("priority", col.priority());
}
if (!col.format().isEmpty()) {
colNode.put("format", col.format());
}
}
}
return cols;
}
Aggregations