Search in sources :

Example 6 with DeploymentSpec

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

the class DockerImageWatcher method updateImageName.

private void updateImageName(KubernetesClient kubernetes, String namespace, HasMetadata entity, String imagePrefix, String imageName) {
    String name = KubernetesHelper.getName(entity);
    if (entity instanceof Deployment) {
        Deployment resource = (Deployment) entity;
        DeploymentSpec spec = resource.getSpec();
        if (spec != null) {
            if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
                kubernetes.extensions().deployments().inNamespace(namespace).withName(name).replace(resource);
            }
        }
    } else if (entity instanceof ReplicaSet) {
        ReplicaSet resource = (ReplicaSet) entity;
        ReplicaSetSpec spec = resource.getSpec();
        if (spec != null) {
            if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
                kubernetes.extensions().replicaSets().inNamespace(namespace).withName(name).replace(resource);
            }
        }
    } else if (entity instanceof ReplicationController) {
        ReplicationController resource = (ReplicationController) entity;
        ReplicationControllerSpec spec = resource.getSpec();
        if (spec != null) {
            if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
                kubernetes.replicationControllers().inNamespace(namespace).withName(name).replace(resource);
            }
        }
    } else if (entity instanceof DeploymentConfig) {
        DeploymentConfig resource = (DeploymentConfig) entity;
        DeploymentConfigSpec spec = resource.getSpec();
        if (spec != null) {
            if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) {
                OpenShiftClient openshiftClient = new Controller(kubernetes).getOpenShiftClientOrNull();
                if (openshiftClient == null) {
                    log.warn("Ignoring DeploymentConfig %s as not connected to an OpenShift cluster", name);
                }
                openshiftClient.deploymentConfigs().inNamespace(namespace).withName(name).replace(resource);
            }
        }
    }
}
Also used : DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) ReplicaSetSpec(io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec) Controller(io.fabric8.kubernetes.api.Controller) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec)

Example 7 with DeploymentSpec

use of io.fabric8.kubernetes.api.model.apps.DeploymentSpec in project jointware by isdream.

the class PerfComparator method createByObject.

public static void createByObject() {
    Deployment dm = new Deployment();
    {
        ObjectMeta md = new ObjectMeta();
        ;
        md.setName("busybox-dm");
        md.setNamespace("wuheng");
        {
            Map<String, String> labels = new HashMap<String, String>();
            labels.put("app", "busybox-dm");
            md.setLabels(labels);
        }
        dm.setMetadata(md);
    }
    {
        DeploymentSpec spec = new DeploymentSpec();
        spec.setReplicas(2);
        {
            PodTemplateSpec template = new PodTemplateSpec();
            {
                PodSpec pc = new PodSpec();
                {
                    List<Container> containers = new ArrayList<Container>();
                    {
                        Container c = new Container();
                        {
                            c.setImage("dcr.io:5000/busybox:latest");
                            c.setImagePullPolicy("IfNotPresent");
                            c.setName("busybox-dm");
                            List<String> commands = new ArrayList<String>();
                            {
                                commands.add("sleep");
                                commands.add("3600");
                            }
                            c.setCommand(commands);
                        }
                        containers.add(c);
                    }
                    pc.setContainers(containers);
                }
                template.setSpec(pc);
            }
            spec.setTemplate(template);
        }
        dm.setSpec(spec);
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) PodTemplateSpec(io.fabric8.kubernetes.api.model.PodTemplateSpec) Container(io.fabric8.kubernetes.api.model.Container) DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) HashMap(java.util.HashMap) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment)

Example 8 with DeploymentSpec

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

the class KubernetesResourceUtil method getPodLabelSelector.

public static LabelSelector getPodLabelSelector(HasMetadata entity) {
    LabelSelector selector = null;
    if (entity instanceof Deployment) {
        Deployment resource = (Deployment) entity;
        DeploymentSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof ReplicaSet) {
        ReplicaSet resource = (ReplicaSet) entity;
        ReplicaSetSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof DeploymentConfig) {
        DeploymentConfig resource = (DeploymentConfig) entity;
        DeploymentConfigSpec spec = resource.getSpec();
        if (spec != null) {
            selector = toLabelSelector(spec.getSelector());
        }
    } else if (entity instanceof ReplicationController) {
        ReplicationController resource = (ReplicationController) entity;
        ReplicationControllerSpec spec = resource.getSpec();
        if (spec != null) {
            selector = toLabelSelector(spec.getSelector());
        }
    } else if (entity instanceof DaemonSet) {
        DaemonSet resource = (DaemonSet) entity;
        DaemonSetSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof StatefulSet) {
        StatefulSet resource = (StatefulSet) entity;
        StatefulSetSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    } else if (entity instanceof Job) {
        Job resource = (Job) entity;
        JobSpec spec = resource.getSpec();
        if (spec != null) {
            selector = spec.getSelector();
        }
    }
    return selector;
}
Also used : StatefulSetSpec(io.fabric8.kubernetes.api.model.extensions.StatefulSetSpec) ReplicaSetSpec(io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DaemonSetSpec(io.fabric8.kubernetes.api.model.extensions.DaemonSetSpec) DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) DaemonSet(io.fabric8.kubernetes.api.model.extensions.DaemonSet) JobSpec(io.fabric8.kubernetes.api.model.JobSpec) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Job(io.fabric8.kubernetes.api.model.Job) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec)

Example 9 with DeploymentSpec

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

the class DebugEnricher method enableDebug.

private boolean enableDebug(HasMetadata entity) {
    if (entity instanceof Deployment) {
        Deployment resource = (Deployment) entity;
        DeploymentSpec spec = resource.getSpec();
        if (spec != null) {
            return enableDebugging(entity, spec.getTemplate());
        }
    } else if (entity instanceof ReplicaSet) {
        ReplicaSet resource = (ReplicaSet) entity;
        ReplicaSetSpec spec = resource.getSpec();
        if (spec != null) {
            return enableDebugging(entity, spec.getTemplate());
        }
    } else if (entity instanceof ReplicationController) {
        ReplicationController resource = (ReplicationController) entity;
        ReplicationControllerSpec spec = resource.getSpec();
        if (spec != null) {
            return enableDebugging(entity, spec.getTemplate());
        }
    } else if (entity instanceof DeploymentConfig) {
        DeploymentConfig resource = (DeploymentConfig) entity;
        DeploymentConfigSpec spec = resource.getSpec();
        if (spec != null) {
            return enableDebugging(entity, spec.getTemplate());
        }
    }
    return false;
}
Also used : DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) ReplicaSetSpec(io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec)

Example 10 with DeploymentSpec

use of io.fabric8.kubernetes.api.model.apps.DeploymentSpec in project fabric8 by fabric8io.

the class DeploymentPodsAssert method pods.

@Override
public PodSelectionAssert pods() {
    spec().isNotNull().selector().isNotNull();
    DeploymentSpec spec = this.actual.getSpec();
    Integer replicas = spec.getReplicas();
    LabelSelector selector = spec.getSelector();
    Map<String, String> matchLabels = selector.getMatchLabels();
    List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions();
    return new PodSelectionAssert(client, replicas, matchLabels, matchExpressions, "DeploymentConfig " + KubernetesHelper.getName(actual));
}
Also used : DeploymentSpec(io.fabric8.kubernetes.api.model.extensions.DeploymentSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) LabelSelectorRequirement(io.fabric8.kubernetes.api.model.LabelSelectorRequirement)

Aggregations

DeploymentSpec (io.fabric8.kubernetes.api.model.extensions.DeploymentSpec)9 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)7 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)4 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)4 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)4 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)4 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)4 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)4 ReplicaSetSpec (io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec)4 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)4 DeploymentConfigSpec (io.fabric8.openshift.api.model.DeploymentConfigSpec)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)3 HashMap (java.util.HashMap)3 Controller (io.fabric8.kubernetes.api.Controller)2 Container (io.fabric8.kubernetes.api.model.Container)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)2 DeploymentBuilder (io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)2 StatefulSetSpec (io.fabric8.kubernetes.api.model.extensions.StatefulSetSpec)2 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)2