use of io.strimzi.api.annotations.ApiVersion 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.api.annotations.ApiVersion in project strimzi-kafka-operator 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;
}
Aggregations