Search in sources :

Example 1 with CustomResourceDefinitionVersion

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;
}
Also used : EnumSet(java.util.EnumSet) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) CustomResourceDefinitionVersion(io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionVersion) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

CustomResourceDefinitionVersion (io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionVersion)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1