Search in sources :

Example 11 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project kie-wb-common by kiegroup.

the class OpenShiftClient method getDeploymentConfig.

private DeploymentConfig getDeploymentConfig(KubernetesList list, String svcName) {
    if (list != null) {
        List<HasMetadata> items = list.getItems();
        String dcName = null;
        for (HasMetadata item : items) {
            if (item instanceof Service && item.getMetadata().getName().equals(svcName)) {
                Map<String, String> selector = ((Service) item).getSpec().getSelector();
                dcName = selector.get("deploymentconfig");
                if (dcName == null) {
                    dcName = selector.get("deploymentConfig");
                }
                break;
            }
        }
        if (dcName != null) {
            for (HasMetadata item : items) {
                if (item instanceof DeploymentConfig && item.getMetadata().getName().equals(dcName)) {
                    return (DeploymentConfig) item;
                }
            }
        }
    }
    return null;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Service(io.fabric8.kubernetes.api.model.Service) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) DoneableDeploymentConfig(io.fabric8.openshift.api.model.DoneableDeploymentConfig) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Example 12 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project kie-wb-common by kiegroup.

the class OpenShiftTemplate method load.

@SuppressWarnings({ "rawtypes", "unchecked" })
private Template load(InputStream templateStream) {
    String generatedName = Utils.randomString("template-", 10);
    Template temp = null;
    Object item = Serialization.unmarshal(templateStream);
    if (item instanceof Template) {
        temp = (Template) item;
    } else if (item instanceof HasMetadata) {
        HasMetadata h = (HasMetadata) item;
        temp = new TemplateBuilder().withNewMetadata().withName(generatedName).withNamespace(h != null && h.getMetadata() != null ? h.getMetadata().getNamespace() : null).endMetadata().withObjects(h).build();
    } else if (item instanceof KubernetesResourceList) {
        List<HasMetadata> list = ((KubernetesResourceList<HasMetadata>) item).getItems();
        temp = new TemplateBuilder().withNewMetadata().withName(generatedName).endMetadata().withObjects(list.toArray(new HasMetadata[list.size()])).build();
    } else if (item instanceof HasMetadata[]) {
        temp = new TemplateBuilder().withNewMetadata().withName(generatedName).endMetadata().withObjects((HasMetadata[]) item).build();
    } else if (item instanceof Collection) {
        List<HasMetadata> items = new ArrayList<>();
        for (Object o : (Collection) item) {
            if (o instanceof HasMetadata) {
                items.add((HasMetadata) o);
            }
        }
        temp = new TemplateBuilder().withNewMetadata().withName(generatedName).endMetadata().withObjects(items.toArray(new HasMetadata[items.size()])).build();
    }
    return temp;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) TemplateBuilder(io.fabric8.openshift.api.model.TemplateBuilder) KubernetesResourceList(io.fabric8.kubernetes.api.model.KubernetesResourceList) ArrayList(java.util.ArrayList) Collection(java.util.Collection) DoneableTemplate(io.fabric8.openshift.api.model.DoneableTemplate) Template(io.fabric8.openshift.api.model.Template)

Example 13 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.

the class ExposeEnricher method addMissingResources.

@Override
public void addMissingResources(KubernetesListBuilder builder) {
    int serviceCount = 0;
    List<HasMetadata> items = builder.getItems();
    if (items != null) {
        for (HasMetadata item : items) {
            if (item instanceof Service) {
                Service service = (Service) item;
                enrichService(service);
                serviceCount++;
            }
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Service(io.fabric8.kubernetes.api.model.Service)

Example 14 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.

the class DependencyEnricherTest method checkUniqueResources.

private boolean checkUniqueResources(List<HasMetadata> resourceList) {
    Map<KindAndName, Integer> resourceMap = new HashMap<>();
    for (int index = 0; index < resourceList.size(); index++) {
        KindAndName aKey = new KindAndName(resourceList.get(index));
        if (resourceMap.containsKey(aKey))
            return false;
        resourceMap.put(aKey, index);
    }
    return true;
}
Also used : KindAndName(io.fabric8.maven.core.util.KindAndName)

Example 15 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.

the class NameEnricher method getOrCreateMetadata.

private ObjectMeta getOrCreateMetadata(HasMetadata resource) {
    ObjectMeta metadata = resource.getMetadata();
    if (metadata == null) {
        metadata = new ObjectMeta();
        resource.setMetadata(metadata);
    }
    return metadata;
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)79 Test (org.junit.Test)25 File (java.io.File)21 ArrayList (java.util.ArrayList)21 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)16 IOException (java.io.IOException)16 Template (io.fabric8.openshift.api.model.Template)15 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)13 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)13 Service (io.fabric8.kubernetes.api.model.Service)13 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)13 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)13 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 HashMap (java.util.HashMap)9 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)8 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)8 Map (java.util.Map)8 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)7