Search in sources :

Example 6 with ContainerPort

use of io.fabric8.kubernetes.api.model.ContainerPort in project syndesis-qe by syndesisio.

the class IRC method deployIrcController.

private static void deployIrcController() {
    List<ContainerPort> ports = new LinkedList<>();
    ports.add(new ContainerPortBuilder().withName(CONTROLLER_APP_NAME).withContainerPort(CONTROLLER_PORT).withProtocol("TCP").build());
    List<EnvVar> envVars = new ArrayList<>();
    envVars.add(new EnvVar("HOST", SERVER_APP_NAME, null));
    OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(CONTROLLER_APP_NAME).addToLabels(LABEL_NAME, CONTROLLER_APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, CONTROLLER_APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, CONTROLLER_APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(CONTROLLER_APP_NAME).withImage("quay.io/syndesis_qe/irc-controller:latest").addAllToPorts(ports).addAllToEnv(envVars).endContainer().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
    ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, CONTROLLER_APP_NAME);
    serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName(CONTROLLER_APP_NAME).withPort(CONTROLLER_PORT).withTargetPort(new IntOrString(CONTROLLER_PORT)).build());
    OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(CONTROLLER_APP_NAME).addToLabels(LABEL_NAME, CONTROLLER_APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
    OpenShiftUtils.getInstance().routes().createOrReplaceWithNew().withNewMetadata().withName(CONTROLLER_APP_NAME).endMetadata().withNewSpec().withPath("/").withWildcardPolicy("None").withNewTls().withTermination("edge").withInsecureEdgeTerminationPolicy("Allow").endTls().withNewTo().withKind("Service").withName(CONTROLLER_APP_NAME).endTo().endSpec().done();
}
Also used : ServiceSpecBuilder(io.fabric8.kubernetes.api.model.ServiceSpecBuilder) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) ArrayList(java.util.ArrayList) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) LinkedList(java.util.LinkedList)

Example 7 with ContainerPort

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

the class KubernetesResourceUtil method ensureHasPort.

private static void ensureHasPort(Container container, ContainerPort port) {
    List<ContainerPort> ports = container.getPorts();
    if (ports == null) {
        ports = new ArrayList<>();
        container.setPorts(ports);
    }
    for (ContainerPort cp : ports) {
        String n1 = cp.getName();
        String n2 = port.getName();
        if (n1 != null && n2 != null && n1.equals(n2)) {
            return;
        }
        Integer p1 = cp.getContainerPort();
        Integer p2 = port.getContainerPort();
        if (p1 != null && p2 != null && p1.intValue() == p2.intValue()) {
            return;
        }
    }
    ports.add(port);
}
Also used : ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort)

Example 8 with ContainerPort

use of io.fabric8.kubernetes.api.model.ContainerPort in project strimzi by strimzi.

the class AbstractModel method createDeployment.

protected Deployment createDeployment(List<ContainerPort> ports, Probe livenessProbe, Probe readinessProbe, DeploymentStrategy updateStrategy, Map<String, String> deploymentAnnotations, Map<String, String> podAnnotations) {
    Container container = new ContainerBuilder().withName(name).withImage(getImage()).withEnv(getEnvVars()).withPorts(ports).withLivenessProbe(livenessProbe).withReadinessProbe(readinessProbe).build();
    Deployment dep = new DeploymentBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withNamespace(namespace).withAnnotations(deploymentAnnotations).endMetadata().withNewSpec().withStrategy(updateStrategy).withReplicas(replicas).withNewTemplate().withNewMetadata().withLabels(getLabelsWithName()).withAnnotations(podAnnotations).endMetadata().withNewSpec().withServiceAccountName(getServiceAccountName()).withContainers(container).endSpec().endTemplate().endSpec().build();
    return dep;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)

Example 9 with ContainerPort

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

the class KubernetesResourceUtil method mergePodSpec.

public static String mergePodSpec(PodSpecBuilder builder, PodSpec defaultPodSpec, String defaultName, boolean sidecarEnabled) {
    // The default application container name is needed by plugin in order
    // to add ImageChange triggers in case of DeploymentConfig
    String defaultApplicationContainerName = null;
    List<Container> containers = builder.buildContainers();
    List<Container> defaultContainers = defaultPodSpec.getContainers();
    int size = defaultContainers.size();
    if (size > 0) {
        if (containers == null || containers.isEmpty()) {
            builder.addToContainers(defaultContainers.toArray(new Container[size]));
        } else {
            int idx = 0;
            for (Container defaultContainer : defaultContainers) {
                Container container = null;
                if (sidecarEnabled) {
                    // Consider container as sidecar
                    for (Container fragmentContainer : containers) {
                        if (fragmentContainer.getName() == null || fragmentContainer.getName().equals(defaultContainer.getName())) {
                            container = fragmentContainer;
                            defaultApplicationContainerName = defaultContainer.getName();
                            break;
                        }
                    }
                    if (container == null) {
                        container = new Container();
                        containers.add(container);
                    }
                } else {
                    // Old behavior
                    if (idx < containers.size()) {
                        container = containers.get(idx);
                    } else {
                        container = new Container();
                        containers.add(container);
                    }
                    // container as default application container.
                    if (defaultApplicationContainerName == null) {
                        defaultApplicationContainerName = container.getName();
                    }
                }
                mergeSimpleFields(container, defaultContainer);
                List<EnvVar> defaultEnv = defaultContainer.getEnv();
                if (defaultEnv != null) {
                    for (EnvVar envVar : defaultEnv) {
                        ensureHasEnv(container, envVar);
                    }
                }
                List<ContainerPort> defaultPorts = defaultContainer.getPorts();
                if (defaultPorts != null) {
                    for (ContainerPort port : defaultPorts) {
                        ensureHasPort(container, port);
                    }
                }
                if (container.getReadinessProbe() == null) {
                    container.setReadinessProbe(defaultContainer.getReadinessProbe());
                }
                if (container.getLivenessProbe() == null) {
                    container.setLivenessProbe(defaultContainer.getLivenessProbe());
                }
                if (container.getSecurityContext() == null) {
                    container.setSecurityContext(defaultContainer.getSecurityContext());
                }
                idx++;
            }
            builder.withContainers(containers);
        }
    } else if (!containers.isEmpty()) {
        // lets default the container name if there's none specified in the custom yaml file
        for (Container container : containers) {
            if (StringUtils.isBlank(container.getName())) {
                container.setName(defaultName);
                // do it for one container only, but not necessarily the first one
                break;
            }
        }
        builder.withContainers(containers);
    }
    // Return the main application container's name.
    return defaultApplicationContainerName;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) EnvVar(io.fabric8.kubernetes.api.model.EnvVar)

Example 10 with ContainerPort

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

the class KubernetesResourceUtil method addPort.

public static boolean addPort(List<ContainerPort> ports, String portNumberText, String portName, Logger log) {
    if (StringUtils.isBlank(portNumberText)) {
        return false;
    }
    int portValue;
    try {
        portValue = Integer.parseInt(portNumberText);
    } catch (NumberFormatException e) {
        log.warn("Could not parse remote debugging port %s as an integer: %s", portNumberText, e);
        return false;
    }
    for (ContainerPort port : ports) {
        String name = port.getName();
        Integer containerPort = port.getContainerPort();
        if (containerPort != null && containerPort.intValue() == portValue) {
            return false;
        }
    }
    ports.add(new ContainerPortBuilder().withName(portName).withContainerPort(portValue).build());
    return true;
}
Also used : ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort)

Aggregations

ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)84 ArrayList (java.util.ArrayList)34 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)31 Container (io.fabric8.kubernetes.api.model.Container)30 Pod (io.fabric8.kubernetes.api.model.Pod)22 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)18 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)17 Test (org.junit.jupiter.api.Test)16 Service (io.fabric8.kubernetes.api.model.Service)13 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)12 HashMap (java.util.HashMap)12 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)11 IOException (java.io.IOException)11 LinkedList (java.util.LinkedList)11 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)10 ServiceSpecBuilder (io.fabric8.kubernetes.api.model.ServiceSpecBuilder)10 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)10 Kafka (io.strimzi.api.kafka.model.Kafka)10 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)10 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)10