use of io.strimzi.api.annotations.ApiVersion.V1 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.api.annotations.ApiVersion.V1 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;
}
use of io.strimzi.api.annotations.ApiVersion.V1 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.api.annotations.ApiVersion.V1 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;
}
Aggregations