use of io.fabric8.kubernetes.api.model.ContainerBuilder in project strimzi by strimzi.
the class AbstractModel method createStatefulSet.
protected StatefulSet createStatefulSet(List<ContainerPort> ports, List<Volume> volumes, List<PersistentVolumeClaim> volumeClaims, List<VolumeMount> volumeMounts, Probe livenessProbe, Probe readinessProbe, boolean isOpenShift) {
Map<String, String> annotations = new HashMap<>();
annotations.put(String.format("%s/%s", ClusterController.STRIMZI_CLUSTER_CONTROLLER_DOMAIN, Storage.DELETE_CLAIM_FIELD), String.valueOf(storage.isDeleteClaim()));
Container container = new ContainerBuilder().withName(name).withImage(getImage()).withEnv(getEnvVars()).withVolumeMounts(volumeMounts).withPorts(ports).withLivenessProbe(livenessProbe).withReadinessProbe(readinessProbe).build();
List<Container> initContainers = new ArrayList<>();
PodSecurityContext securityContext = null;
// there is an hack on volume mounting which needs an "init-container"
if ((this.storage.type() == Storage.StorageType.PERSISTENT_CLAIM) && !isOpenShift) {
String chown = String.format("chown -R %d:%d %s", AbstractModel.VOLUME_MOUNT_HACK_GROUPID, AbstractModel.VOLUME_MOUNT_HACK_GROUPID, volumeMounts.get(0).getMountPath());
Container initContainer = new ContainerBuilder().withName(AbstractModel.VOLUME_MOUNT_HACK_NAME).withImage(AbstractModel.VOLUME_MOUNT_HACK_IMAGE).withVolumeMounts(volumeMounts.get(0)).withCommand("sh", "-c", chown).build();
initContainers.add(initContainer);
securityContext = new PodSecurityContextBuilder().withFsGroup(AbstractModel.VOLUME_MOUNT_HACK_GROUPID).build();
}
StatefulSet statefulSet = new StatefulSetBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withNamespace(namespace).withAnnotations(annotations).endMetadata().withNewSpec().withPodManagementPolicy("Parallel").withUpdateStrategy(new StatefulSetUpdateStrategyBuilder().withType("OnDelete").build()).withSelector(new LabelSelectorBuilder().withMatchLabels(getLabelsWithName()).build()).withServiceName(headlessName).withReplicas(replicas).withNewTemplate().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withAnnotations(getPrometheusAnnotations()).endMetadata().withNewSpec().withSecurityContext(securityContext).withInitContainers(initContainers).withContainers(container).withVolumes(volumes).endSpec().endTemplate().withVolumeClaimTemplates(volumeClaims).endSpec().build();
return statefulSet;
}
use of io.fabric8.kubernetes.api.model.ContainerBuilder in project strimzi by strimzi.
the class KafkaConnectS2ICluster method generateDeploymentConfig.
/**
* Generate new DeploymentConfig
*
* @return Source ImageStream resource definition
*/
public DeploymentConfig generateDeploymentConfig() {
Container container = new ContainerBuilder().withName(name).withImage(image).withEnv(getEnvVars()).withPorts(Collections.singletonList(createContainerPort(REST_API_PORT_NAME, REST_API_PORT, "TCP"))).withLivenessProbe(createHttpProbe(healthCheckPath, REST_API_PORT_NAME, healthCheckInitialDelay, healthCheckTimeout)).withReadinessProbe(createHttpProbe(healthCheckPath, REST_API_PORT_NAME, healthCheckInitialDelay, healthCheckTimeout)).build();
DeploymentTriggerPolicy configChangeTrigger = new DeploymentTriggerPolicyBuilder().withType("ConfigChange").build();
DeploymentTriggerPolicy imageChangeTrigger = new DeploymentTriggerPolicyBuilder().withType("ImageChange").withNewImageChangeParams().withAutomatic(true).withContainerNames(name).withNewFrom().withKind("ImageStreamTag").withName(image).endFrom().endImageChangeParams().build();
DeploymentStrategy updateStrategy = new DeploymentStrategyBuilder().withType("Rolling").withNewRollingParams().withMaxSurge(new IntOrString(1)).withMaxUnavailable(new IntOrString(0)).endRollingParams().build();
DeploymentConfig dc = new DeploymentConfigBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithName()).withNamespace(namespace).endMetadata().withNewSpec().withReplicas(replicas).withNewTemplate().withNewMetadata().withLabels(getLabelsWithName()).endMetadata().withNewSpec().withContainers(container).endSpec().endTemplate().withTriggers(configChangeTrigger, imageChangeTrigger).withStrategy(updateStrategy).endSpec().build();
return dc;
}
use of io.fabric8.kubernetes.api.model.ContainerBuilder in project halyard by spinnaker.
the class ResourceBuilder method buildContainer.
static Container buildContainer(String name, ServiceSettings settings, List<ConfigSource> configSources, DeploymentEnvironment deploymentEnvironment) {
int port = settings.getPort();
List<EnvVar> envVars = settings.getEnv().entrySet().stream().map(e -> {
EnvVarBuilder envVarBuilder = new EnvVarBuilder();
return envVarBuilder.withName(e.getKey()).withValue(e.getValue()).build();
}).collect(Collectors.toList());
configSources.forEach(c -> {
c.getEnv().entrySet().forEach(envEntry -> {
EnvVarBuilder envVarBuilder = new EnvVarBuilder();
envVars.add(envVarBuilder.withName(envEntry.getKey()).withValue(envEntry.getValue()).build());
});
});
ProbeBuilder probeBuilder = new ProbeBuilder();
if (settings.getHealthEndpoint() != null) {
probeBuilder = probeBuilder.withNewHttpGet().withNewPort(port).withPath(settings.getHealthEndpoint()).endHttpGet();
} else {
probeBuilder = probeBuilder.withNewTcpSocket().withNewPort().withIntVal(port).endPort().endTcpSocket();
}
List<VolumeMount> volumeMounts = configSources.stream().map(c -> {
return new VolumeMountBuilder().withMountPath(c.getMountPath()).withName(c.getId()).build();
}).collect(Collectors.toList());
ContainerBuilder containerBuilder = new ContainerBuilder();
containerBuilder = containerBuilder.withName(name).withImage(settings.getArtifactId()).withPorts(new ContainerPortBuilder().withContainerPort(port).build()).withVolumeMounts(volumeMounts).withEnv(envVars).withReadinessProbe(probeBuilder.build()).withResources(buildResourceRequirements(name, deploymentEnvironment));
return containerBuilder.build();
}
use of io.fabric8.kubernetes.api.model.ContainerBuilder in project syndesis-qe by syndesisio.
the class HTTPEndpoints method deploy.
@Override
public void deploy() {
if (!isDeployed()) {
Map<String, String> labels = TestUtils.map(LABEL_NAME, APP_NAME);
List<ContainerPort> ports = new ArrayList<>();
ports.add(new ContainerPortBuilder().withName("http").withContainerPort(8080).build());
ports.add(new ContainerPortBuilder().withName("https").withContainerPort(8443).build());
// @formatter:off
OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().withNewMetadata().withName(APP_NAME).withLabels(labels).endMetadata().withNewSpec().withReplicas(1).withSelector(labels).withNewTemplate().withNewMetadata().withLabels(labels).endMetadata().withNewSpec().withContainers(new ContainerBuilder().withName(APP_NAME).withPorts(ports).withImage(IMAGE).build()).endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
OpenShiftUtils.getInstance().services().createOrReplaceWithNew().withNewMetadata().withName(HTTP_SERVICE_NAME).withLabels(labels).endMetadata().withNewSpec().withPorts(getServicePort(HTTP_SERVICE_NAME, 8080)).withSelector(labels).endSpec().done();
OpenShiftUtils.getInstance().services().createOrReplaceWithNew().withNewMetadata().withName(HTTPS_SERVICE_NAME).withLabels(labels).endMetadata().withNewSpec().withPorts(getServicePort(HTTPS_SERVICE_NAME, 8443)).withSelector(labels).endSpec().done();
String content = "";
// Download the keystore and base64 encode it
try {
content = new String(Base64.getEncoder().encode(IOUtils.toByteArray(new URL(KEYSTORE_URL))));
} catch (IOException e) {
fail("Unable to read " + KEYSTORE_URL, e);
}
OpenShiftUtils.getInstance().secrets().createOrReplaceWithNew().withNewMetadata().withName(KEYSTORE_SECRET_NAME).endMetadata().addToData("keystore.p12", content).done();
// @formatter:on
}
addAccounts();
}
use of io.fabric8.kubernetes.api.model.ContainerBuilder in project syndesis-qe by syndesisio.
the class ExternalDatabase method deploy.
@Override
public void deploy() {
OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().withNewMetadata().withName(NAME).withLabels(TestUtils.map("app", NAME)).endMetadata().withNewSpec().withReplicas(1).withNewTemplate().withNewMetadata().withLabels(TestUtils.map("app", NAME)).endMetadata().withNewSpec().withContainers(new ContainerBuilder().withEnv(new EnvVar("POSTGRESQL_DATABASE", "testdb", null), new EnvVar("POSTGRESQL_PASSWORD", "testpassword", null), new EnvVar("POSTGRESQL_USER", "testuser", null)).withPorts(new ContainerPortBuilder().withContainerPort(5432).withProtocol("TCP").build()).withName(NAME).withImage(" ").build()).endSpec().endTemplate().withSelector(TestUtils.map("app", NAME)).withTriggers(new DeploymentTriggerPolicyBuilder().withNewImageChangeParams().withContainerNames(NAME).withFrom(new ObjectReferenceBuilder().withKind("ImageStreamTag").withName("postgresql:12").withNamespace("openshift").build()).withAutomatic(true).endImageChangeParams().withNewType("ImageChange").build()).endSpec().done();
OpenShiftUtils.getInstance().services().createOrReplaceWithNew().withNewMetadata().withName(NAME).withLabels(TestUtils.map("app", NAME)).endMetadata().withNewSpec().addToPorts(new ServicePortBuilder().withNewName("5432-tcp").withNewTargetPort(5432).withNewProtocol("TCP").withPort(5432).build()).addToSelector(TestUtils.map("app", NAME)).endSpec().done();
// create a needed secret with the password
OpenShiftUtils.getInstance().secrets().createOrReplaceWithNew().withNewMetadata().withName("syndesis-global-config").endMetadata().withStringData(TestUtils.map("POSTGRESQL_PASSWORD", "testpassword")).withNewType("Opaque").done();
}
Aggregations