use of io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionVersion in project syndesis-qe by syndesisio.
the class Syndesis method getCrNames.
private Map<String, Set<String>> getCrNames() {
final Map<String, Set<String>> versionAndNames = new HashMap<>();
Map<String, Object> crs = new HashMap<>();
// (There should be always only one, but to be bullet-proof)
for (CustomResourceDefinitionVersion version : getCrd().getSpec().getVersions()) {
try {
crs.putAll(getSyndesisCrClient(version.getName()).list(TestConfiguration.openShiftNamespace()));
} catch (KubernetesClientException kce) {
// If there are no custom resources with this version, ignore
if (!kce.getMessage().contains("404")) {
throw kce;
}
}
}
JSONArray items = new JSONArray();
try {
items = new JSONObject(crs).getJSONArray("items");
} catch (JSONException ex) {
// probably the CRD isn't present in the cluster
}
for (int i = 0; i < items.length(); i++) {
final String version = StringUtils.substringAfter(items.getJSONObject(i).getString("apiVersion"), "/");
versionAndNames.computeIfAbsent(version, v -> new HashSet<>());
versionAndNames.get(version).add(items.getJSONObject(i).getJSONObject("metadata").getString("name"));
}
return versionAndNames;
}
Aggregations