Search in sources :

Example 16 with ContainerBuilder

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;
}
Also used : LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) HashMap(java.util.HashMap) PodSecurityContext(io.fabric8.kubernetes.api.model.PodSecurityContext) StatefulSetUpdateStrategyBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetUpdateStrategyBuilder) ArrayList(java.util.ArrayList) StatefulSetBuilder(io.fabric8.kubernetes.api.model.extensions.StatefulSetBuilder) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) PodSecurityContextBuilder(io.fabric8.kubernetes.api.model.PodSecurityContextBuilder) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet)

Example 17 with ContainerBuilder

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;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) DeploymentStrategyBuilder(io.fabric8.openshift.api.model.DeploymentStrategyBuilder) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) DeploymentTriggerPolicy(io.fabric8.openshift.api.model.DeploymentTriggerPolicy) DeploymentTriggerPolicyBuilder(io.fabric8.openshift.api.model.DeploymentTriggerPolicyBuilder) DeploymentStrategy(io.fabric8.openshift.api.model.DeploymentStrategy)

Example 18 with ContainerBuilder

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();
}
Also used : DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Container(io.fabric8.kubernetes.api.model.Container) CustomSizing(com.netflix.spinnaker.halyard.config.model.v1.node.CustomSizing) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) QuantityBuilder(io.fabric8.kubernetes.api.model.QuantityBuilder) Collectors(java.util.stream.Collectors) List(java.util.List) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) Map(java.util.Map) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 19 with ContainerBuilder

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();
}
Also used : ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) ArrayList(java.util.ArrayList) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IOException(java.io.IOException) URL(java.net.URL)

Example 20 with ContainerBuilder

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();
}
Also used : ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) ObjectReferenceBuilder(io.fabric8.kubernetes.api.model.ObjectReferenceBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) DeploymentTriggerPolicyBuilder(io.fabric8.openshift.api.model.DeploymentTriggerPolicyBuilder)

Aggregations

ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)21 Container (io.fabric8.kubernetes.api.model.Container)13 ArrayList (java.util.ArrayList)9 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)7 Pod (io.fabric8.kubernetes.api.model.Pod)7 EnvVar (io.fabric8.kubernetes.api.model.EnvVar)5 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)5 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)5 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)5 List (java.util.List)5 Map (java.util.Map)5 FlinkPod (org.apache.flink.kubernetes.kubeclient.FlinkPod)5 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)4 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)4 Volume (io.fabric8.kubernetes.api.model.Volume)4 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)4 DeploymentBuilder (io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 Service (io.fabric8.kubernetes.api.model.Service)3