use of io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionCondition in project strimzi by strimzi.
the class StructuralCrdIT method assertApiVersionsAreStructuralInApiextensionsV1.
private void assertApiVersionsAreStructuralInApiextensionsV1(String api, VersionRange<ApiVersion> shouldBeStructural) {
Pattern pattern = Pattern.compile("[^.]spec\\.versions\\[([0-9]+)\\]\\.[^,]*?");
CustomResourceDefinition crd = cluster.client().getClient().apiextensions().v1().customResourceDefinitions().withName(api).get();
// We can't make the following assertion because the current version of fabric8 always requests
// the CRD using v1beta1 api version, so the apiserver just replaces it and serves it.
// assertEquals(crdApiVersion, ApiVersion.parse(crd.getApiVersion().replace("apiextensions.k8s.io/", "")));
Set<ApiVersion> presentCrdApiVersions = crd.getSpec().getVersions().stream().map(v -> ApiVersion.parse(v.getName())).collect(Collectors.toSet());
assertTrue(presentCrdApiVersions.contains(shouldBeStructural.lower()), "CRD has versions " + presentCrdApiVersions + " which doesn't include " + shouldBeStructural.lower() + " which should be structural");
Map<Integer, ApiVersion> indexedVersions = new HashMap<>();
int i = 0;
for (CustomResourceDefinitionVersion version : crd.getSpec().getVersions()) {
indexedVersions.put(i, ApiVersion.parse(version.getName()));
}
Optional<CustomResourceDefinitionCondition> first = crd.getStatus().getConditions().stream().filter(cond -> "NonStructuralSchema".equals(cond.getType()) && "True".equals(cond.getStatus())).findFirst();
if (first.isPresent()) {
Matcher matcher = pattern.matcher(first.get().getMessage());
while (matcher.find()) {
Integer index = Integer.valueOf(matcher.group(1));
ApiVersion nonStructuralVersion = indexedVersions.get(index);
if (shouldBeStructural.contains(nonStructuralVersion)) {
fail(api + "/ " + nonStructuralVersion + " should be structural but there's a complaint about " + matcher.group());
}
}
}
}
use of io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionCondition in project strimzi-kafka-operator by strimzi.
the class StructuralCrdIT method assertApiVersionsAreStructuralInApiextensionsV1.
private void assertApiVersionsAreStructuralInApiextensionsV1(String api, VersionRange<ApiVersion> shouldBeStructural) {
Pattern pattern = Pattern.compile("[^.]spec\\.versions\\[([0-9]+)\\]\\.[^,]*?");
CustomResourceDefinition crd = cluster.client().getClient().apiextensions().v1().customResourceDefinitions().withName(api).get();
// We can't make the following assertion because the current version of fabric8 always requests
// the CRD using v1beta1 api version, so the apiserver just replaces it and serves it.
// assertEquals(crdApiVersion, ApiVersion.parse(crd.getApiVersion().replace("apiextensions.k8s.io/", "")));
Set<ApiVersion> presentCrdApiVersions = crd.getSpec().getVersions().stream().map(v -> ApiVersion.parse(v.getName())).collect(Collectors.toSet());
assertTrue(presentCrdApiVersions.contains(shouldBeStructural.lower()), "CRD has versions " + presentCrdApiVersions + " which doesn't include " + shouldBeStructural.lower() + " which should be structural");
Map<Integer, ApiVersion> indexedVersions = new HashMap<>();
int i = 0;
for (CustomResourceDefinitionVersion version : crd.getSpec().getVersions()) {
indexedVersions.put(i, ApiVersion.parse(version.getName()));
}
Optional<CustomResourceDefinitionCondition> first = crd.getStatus().getConditions().stream().filter(cond -> "NonStructuralSchema".equals(cond.getType()) && "True".equals(cond.getStatus())).findFirst();
if (first.isPresent()) {
Matcher matcher = pattern.matcher(first.get().getMessage());
while (matcher.find()) {
Integer index = Integer.valueOf(matcher.group(1));
ApiVersion nonStructuralVersion = indexedVersions.get(index);
if (shouldBeStructural.contains(nonStructuralVersion)) {
fail(api + "/ " + nonStructuralVersion + " should be structural but there's a complaint about " + matcher.group());
}
}
}
}
Aggregations