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();
}
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);
}
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;
}
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;
}
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;
}
Aggregations