Search in sources :

Example 46 with EnvVar

use of io.fabric8.kubernetes.api.model.EnvVar 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)

Example 47 with EnvVar

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

the class HTTPValidationSteps method configureKeystore.

@When("^configure keystore in (HTTP|HTTPS) integration dc$")
public void configureKeystore(String protocol) {
    if ("HTTP".equals(protocol)) {
        return;
    }
    try {
        OpenShiftWaitUtils.waitFor(() -> !OpenShiftUtils.getInstance().deploymentConfigs().withLabel("syndesis.io/type", "integration").list().getItems().isEmpty(), 300000L);
    } catch (TimeoutException | InterruptedException e) {
        fail("Unable to find integration deployment config after 5 minutes");
    } catch (Exception e) {
    // ignore
    }
    List<DeploymentConfig> integrationDcs = OpenShiftUtils.getInstance().deploymentConfigs().withLabel("syndesis.io/type", "integration").list().getItems();
    Assertions.assertThat(integrationDcs).as("There should be only one integration deployment config").hasSize(1);
    DeploymentConfig dc = integrationDcs.get(0);
    log.debug("Waiting until next integration state check interval");
    String serverLog = OpenShiftUtils.getPodLogs("syndesis-server");
    while (serverLog.equals(OpenShiftUtils.getPodLogs("syndesis-server"))) {
        TestUtils.sleepIgnoreInterrupt(5000L);
    }
    TestUtils.withRetry(() -> {
        try {
            // @formatter:off
            OpenShiftUtils.getInstance().deploymentConfigs().withName(dc.getMetadata().getName()).edit().editSpec().editTemplate().editSpec().addNewVolume().withName("keystore").withNewSecret().withSecretName(HTTPEndpoints.KEYSTORE_SECRET_NAME).endSecret().endVolume().editFirstContainer().addNewVolumeMount().withNewMountPath("/opt/jboss/").withName("keystore").endVolumeMount().addToEnv(new EnvVar("JAVA_OPTIONS", "-Djackson.deserialization.whitelist.packages=io.syndesis.common.model,io.atlasmap" + " -Djavax.net.ssl.trustStore=/opt/jboss/keystore.p12 -Djavax.net.ssl.trustStorePassword=tomcat -Djavax.net.ssl.trustStoreAlias=tomcat", null)).endContainer().endSpec().endTemplate().endSpec().done();
            // @formatter:on
            // Just to be sure, delete the integration pod if it exists, so that the change in DC is picked up
            OpenShiftUtils.getInstance().deletePods("syndesis.io/type", "integration");
            return true;
        } catch (KubernetesClientException kce) {
            log.debug("Caught KubernetesClientException: ", kce);
            return false;
        }
    }, 3, 30000L, "Unable to edit deployment config");
}
Also used : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) When(io.cucumber.java.en.When)

Example 48 with EnvVar

use of io.fabric8.kubernetes.api.model.EnvVar in project flink by apache.

the class KubernetesJobManagerFactoryTest method testPodSpec.

@Test
public void testPodSpec() throws IOException {
    kubernetesJobManagerSpecification = KubernetesJobManagerFactory.buildKubernetesJobManagerSpecification(flinkPod, kubernetesJobManagerParameters);
    final PodSpec resultPodSpec = this.kubernetesJobManagerSpecification.getDeployment().getSpec().getTemplate().getSpec();
    assertEquals(1, resultPodSpec.getContainers().size());
    assertEquals(SERVICE_ACCOUNT_NAME, resultPodSpec.getServiceAccountName());
    assertEquals(3, resultPodSpec.getVolumes().size());
    final Container resultedMainContainer = resultPodSpec.getContainers().get(0);
    assertEquals(Constants.MAIN_CONTAINER_NAME, resultedMainContainer.getName());
    assertEquals(CONTAINER_IMAGE, resultedMainContainer.getImage());
    assertEquals(CONTAINER_IMAGE_PULL_POLICY.name(), resultedMainContainer.getImagePullPolicy());
    assertEquals(3, resultedMainContainer.getEnv().size());
    assertTrue(resultedMainContainer.getEnv().stream().anyMatch(envVar -> envVar.getName().equals("key1")));
    assertEquals(3, resultedMainContainer.getPorts().size());
    final Map<String, Quantity> requests = resultedMainContainer.getResources().getRequests();
    assertEquals(Double.toString(JOB_MANAGER_CPU), requests.get("cpu").getAmount());
    assertEquals(String.valueOf(JOB_MANAGER_MEMORY), requests.get("memory").getAmount());
    assertEquals(1, resultedMainContainer.getCommand().size());
    // The args list is [bash, -c, 'java -classpath $FLINK_CLASSPATH ...'].
    assertEquals(3, resultedMainContainer.getArgs().size());
    assertEquals(3, resultedMainContainer.getVolumeMounts().size());
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) SecurityOptions(org.apache.flink.configuration.SecurityOptions) KubernetesTestUtils(org.apache.flink.kubernetes.KubernetesTestUtils) KubernetesJobManagerTestBase(org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerTestBase) CONFIG_FILE_LOG4J_NAME(org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOG4J_NAME) Map(java.util.Map) ExternalServiceDecorator(org.apache.flink.kubernetes.kubeclient.decorators.ExternalServiceDecorator) DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) KubernetesUtils(org.apache.flink.kubernetes.utils.KubernetesUtils) KubernetesConfigOptions(org.apache.flink.kubernetes.configuration.KubernetesConfigOptions) FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Collectors(java.util.stream.Collectors) Base64(java.util.Base64) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Secret(io.fabric8.kubernetes.api.model.Secret) Matchers.is(org.hamcrest.Matchers.is) Constants(org.apache.flink.kubernetes.utils.Constants) Container(io.fabric8.kubernetes.api.model.Container) KubernetesConfigOptionsInternal(org.apache.flink.kubernetes.configuration.KubernetesConfigOptionsInternal) HashMap(java.util.HashMap) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) KubernetesHaServicesFactory(org.apache.flink.kubernetes.highavailability.KubernetesHaServicesFactory) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) DeploymentOptions(org.apache.flink.configuration.DeploymentOptions) FlinkConfMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.FlinkConfMountDecorator) Service(io.fabric8.kubernetes.api.model.Service) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) KubernetesDeploymentTarget(org.apache.flink.kubernetes.configuration.KubernetesDeploymentTarget) FLINK_CONF_FILENAME(org.apache.flink.configuration.GlobalConfiguration.FLINK_CONF_FILENAME) InternalServiceDecorator(org.apache.flink.kubernetes.kubeclient.decorators.InternalServiceDecorator) Assert.assertNotNull(org.junit.Assert.assertNotNull) KubernetesJobManagerSpecification(org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerSpecification) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) KubernetesSessionClusterEntrypoint(org.apache.flink.kubernetes.entrypoint.KubernetesSessionClusterEntrypoint) HadoopConfMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.HadoopConfMountDecorator) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KerberosMountDecorator(org.apache.flink.kubernetes.kubeclient.decorators.KerberosMountDecorator) Assert.assertNull(org.junit.Assert.assertNull) HeadlessClusterIPService(org.apache.flink.kubernetes.kubeclient.services.HeadlessClusterIPService) CONFIG_FILE_LOGBACK_NAME(org.apache.flink.kubernetes.utils.Constants.CONFIG_FILE_LOGBACK_NAME) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Collections(java.util.Collections) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) Assert.assertEquals(org.junit.Assert.assertEquals) Container(io.fabric8.kubernetes.api.model.Container) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Quantity(io.fabric8.kubernetes.api.model.Quantity) Test(org.junit.Test)

Example 49 with EnvVar

use of io.fabric8.kubernetes.api.model.EnvVar in project flink by apache.

the class EnvSecretsDecoratorTest method testWhetherPodOrContainerIsDecorated.

@Test
public void testWhetherPodOrContainerIsDecorated() {
    final FlinkPod resultFlinkPod = envSecretsDecorator.decorateFlinkPod(baseFlinkPod);
    List<EnvVar> envVarList = resultFlinkPod.getMainContainer().getEnv();
    assertEquals(1, envVarList.size());
    assertEquals(ENV_NAME, envVarList.get(0).getName());
}
Also used : FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Test(org.junit.Test)

Example 50 with EnvVar

use of io.fabric8.kubernetes.api.model.EnvVar in project flink by apache.

the class HadoopConfMountDecoratorTest method testMainContainerWithHadoopConfVolumeMount.

@Test
public void testMainContainerWithHadoopConfVolumeMount() throws IOException {
    setHadoopConfDirEnv();
    generateHadoopConfFileItems();
    final FlinkPod resultFlinkPod = hadoopConfMountDecorator.decorateFlinkPod(baseFlinkPod);
    final List<VolumeMount> resultVolumeMounts = resultFlinkPod.getMainContainer().getVolumeMounts();
    assertEquals(1, resultVolumeMounts.size());
    final VolumeMount resultVolumeMount = resultVolumeMounts.get(0);
    assertEquals(Constants.HADOOP_CONF_VOLUME, resultVolumeMount.getName());
    assertEquals(Constants.HADOOP_CONF_DIR_IN_POD, resultVolumeMount.getMountPath());
    final Map<String, String> expectedEnvs = new HashMap<String, String>() {

        {
            put(Constants.ENV_HADOOP_CONF_DIR, Constants.HADOOP_CONF_DIR_IN_POD);
        }
    };
    final Map<String, String> resultEnvs = resultFlinkPod.getMainContainer().getEnv().stream().collect(Collectors.toMap(EnvVar::getName, EnvVar::getValue));
    assertEquals(expectedEnvs, resultEnvs);
}
Also used : FlinkPod(org.apache.flink.kubernetes.kubeclient.FlinkPod) HashMap(java.util.HashMap) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) Test(org.junit.Test)

Aggregations

EnvVar (io.fabric8.kubernetes.api.model.EnvVar)51 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)11 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)10 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)10 HashMap (java.util.HashMap)10 Container (io.fabric8.kubernetes.api.model.Container)9 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)9 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)9 File (java.io.File)8 List (java.util.List)8 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)7 Pod (io.fabric8.kubernetes.api.model.Pod)7 ServiceSpecBuilder (io.fabric8.kubernetes.api.model.ServiceSpecBuilder)7 Map (java.util.Map)7 Test (org.testng.annotations.Test)7 LinkedList (java.util.LinkedList)6 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)5 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)5