Search in sources :

Example 41 with EnvVar

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

the class MySQL method deploy.

@Override
public void deploy() {
    List<ContainerPort> ports = new LinkedList<>();
    ports.add(new ContainerPortBuilder().withName("mysql-cmd").withContainerPort(3306).withProtocol("TCP").build());
    List<EnvVar> templateParams = new ArrayList<>();
    templateParams.add(new EnvVar("MYSQL_USER", DB_USER, null));
    templateParams.add(new EnvVar("MYSQL_PASSWORD", DB_PASSWORD, null));
    templateParams.add(new EnvVar("MYSQL_DATABASE", DB_SCHEMA, null));
    OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(APP_NAME).withImage("quay.io/syndesis_qe/mysql-57-centos7").addAllToPorts(ports).addAllToEnv(templateParams).endContainer().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
    ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
    serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("mysql-cmd").withPort(3306).withTargetPort(new IntOrString(3306)).build());
    OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
    try {
        OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.areExactlyNPodsReady(LABEL_NAME, APP_NAME, 1));
        Thread.sleep(20 * 1000);
    } catch (InterruptedException | TimeoutException e) {
        log.error("Wait for {} deployment failed ", APP_NAME, e);
    }
    Account mysqlAccount = new Account();
    mysqlAccount.setService("mysql");
    Map<String, String> accountParameters = new HashMap<>();
    accountParameters.put("url", DB_URL);
    accountParameters.put("user", DB_USER);
    accountParameters.put("password", DB_PASSWORD);
    accountParameters.put("schema", DB_SCHEMA);
    mysqlAccount.setProperties(accountParameters);
    AccountsDirectory.getInstance().addAccount("mysql", mysqlAccount);
}
Also used : Account(io.syndesis.qe.account.Account) HashMap(java.util.HashMap) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArrayList(java.util.ArrayList) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) LinkedList(java.util.LinkedList) ServiceSpecBuilder(io.fabric8.kubernetes.api.model.ServiceSpecBuilder) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) TimeoutException(java.util.concurrent.TimeoutException)

Example 42 with EnvVar

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

the class SFTP method deploy.

@Override
public void deploy() {
    // preparation for our specific SFTP image to fit Openshift requirements:
    OpenShiftUtils.getInstance().serviceAccounts().createNew().withNewMetadata().withName(serviceAccountName).endMetadata().addToImagePullSecrets(new LocalObjectReference(TestConfiguration.syndesisPullSecretName())).done();
    OpenShiftUtils.getInstance().securityContextConstraints().withName("anyuid").edit().addNewUser("system:serviceaccount:" + TestConfiguration.openShiftNamespace() + ":" + serviceAccountName).done();
    OpenShiftUtils.getInstance().securityContextConstraints().withName("anyuid").edit().addToDefaultAddCapabilities("SYS_CHROOT").done();
    if (!isDeployed()) {
        List<ContainerPort> ports = new LinkedList<>();
        ports.add(new ContainerPortBuilder().withName("sftp-cmd").withContainerPort(sftpPort).withProtocol("TCP").build());
        List<EnvVar> templateParams = new ArrayList<>();
        templateParams.add(new EnvVar("SFTP_USERS", userAndPassword, null));
        OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(appName).addToLabels(labelName, appName).endMetadata().editOrNewSpec().addToSelector(labelName, appName).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(labelName, appName).endMetadata().editOrNewSpec().addNewContainer().withName(appName).withImage("quay.io/syndesis_qe/sftpd-alp:latest").addAllToPorts(ports).addAllToEnv(templateParams).endContainer().withServiceAccount(serviceAccountName).endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
        ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(labelName, appName);
        serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("sftp-cmd").withPort(sftpPort).withTargetPort(new IntOrString(sftpPort)).build());
        OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(appName).addToLabels(labelName, appName).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).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) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) 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 43 with EnvVar

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

the class SyndesisDB method deploy.

@Override
public void deploy() {
    List<ContainerPort> ports = new LinkedList<>();
    ports.add(new ContainerPortBuilder().withName("psql-cmd").withContainerPort(5432).withProtocol("TCP").build());
    List<EnvVar> templateParams = new ArrayList<>();
    templateParams.add(new EnvVar("POSTGRESQL_USER", DB_ROOT_USER, null));
    templateParams.add(new EnvVar("POSTGRESQL_PASSWORD", DB_PASSWORD, null));
    // sample DB schema is created by post start script, this DB is not important
    templateParams.add(new EnvVar("POSTGRESQL_DATABASE", "whatever", null));
    templateParams.add(new EnvVar("POSTGRESQL_SAMPLEDB_PASSWORD", DB_PASSWORD, null));
    // config map with the post start script
    if (OpenShiftUtils.getInstance().getConfigMap("syndesis-sampledb-config") == null) {
        try (InputStream is = ClassLoader.getSystemResourceAsStream("templates/syndesis-sampledb-config.yml")) {
            ConfigMap cm = OpenShiftUtils.getInstance().configMaps().load(is).get();
            OpenShiftUtils.getInstance().createConfigMap(cm);
        } catch (IOException ex) {
            throw new IllegalArgumentException("Unable to read config map ", ex);
        }
    }
    OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(APP_NAME).withImage("quay.io/syndesis_qe/postgresql-10-centos7:latest").addAllToPorts(ports).addAllToEnv(templateParams).editOrNewLifecycle().editOrNewPostStart().editOrNewExec().addNewCommand("/bin/sh").addNewCommand("-c").addNewCommand("/var/lib/pgsql/sampledb/postStart.sh").endExec().endPostStart().endLifecycle().addNewVolumeMount().withNewMountPath("/var/lib/pgsql/sampledb").withName("syndesis-sampledb-config").endVolumeMount().endContainer().addNewVolume().editOrNewConfigMap().withName("syndesis-sampledb-config").withDefaultMode(511).endConfigMap().withName("syndesis-sampledb-config").endVolume().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
    ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
    serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("psql-cmd").withPort(5432).withTargetPort(new IntOrString(5432)).build());
    OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
    try {
        OpenShiftWaitUtils.waitFor(OpenShiftWaitUtils.areExactlyNPodsReady(LABEL_NAME, APP_NAME, 1));
        Thread.sleep(20 * 1000);
    } catch (InterruptedException | TimeoutException e) {
        log.error("Wait for {} deployment failed ", APP_NAME, e);
    }
    Account syndesisDbAccount = new Account();
    syndesisDbAccount.setService("SyndesisDB");
    Map<String, String> accountParameters = new HashMap<>();
    accountParameters.put("url", DB_URL);
    accountParameters.put("user", DB_SAMPLE_DB_USER);
    accountParameters.put("password", DB_PASSWORD);
    accountParameters.put("schema", DB_SCHEMA);
    syndesisDbAccount.setProperties(accountParameters);
    AccountsDirectory.getInstance().addAccount(Account.Name.SYNDESIS_DB.getId(), syndesisDbAccount);
    Connection defaultPostgresDBConnection = connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_ORIGINAL);
    // (When the test suite was killed before, the backup can exist and original connection was already changed, ignore in that case
    if (connectionsEndpoint.getConnectionByName(DEFAULT_PSQL_CONNECTION_BACKUP) == null) {
        connectionsEndpoint.create(defaultPostgresDBConnection.builder().name(DEFAULT_PSQL_CONNECTION_BACKUP).id("1000").build());
    }
    // config prop for new instance
    Map<String, String> configuredProperties = new HashMap<>(defaultPostgresDBConnection.getConfiguredProperties());
    configuredProperties.put("schema", DB_SCHEMA);
    configuredProperties.put("password", DB_PASSWORD);
    configuredProperties.put("user", DB_SAMPLE_DB_USER);
    configuredProperties.put("url", DB_URL);
    Connection build = defaultPostgresDBConnection.builder().configuredProperties(configuredProperties).build();
    connectionsEndpoint.update(defaultPostgresDBConnection.getId().get(), build);
}
Also used : Account(io.syndesis.qe.account.Account) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) InputStream(java.io.InputStream) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArrayList(java.util.ArrayList) Connection(io.syndesis.common.model.connection.Connection) IOException(java.io.IOException) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) LinkedList(java.util.LinkedList) ServiceSpecBuilder(io.fabric8.kubernetes.api.model.ServiceSpecBuilder) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) TimeoutException(java.util.concurrent.TimeoutException)

Example 44 with EnvVar

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

the class OpenShiftUtils method updateEnvVarInDeploymentConfig.

public static void updateEnvVarInDeploymentConfig(String dcName, String key, String value) {
    DeploymentConfig dc = getInstance().getDeploymentConfig(dcName);
    List<EnvVar> vars = dc.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
    Optional<EnvVar> var = vars.stream().filter(a -> a.getName().equalsIgnoreCase(key)).findFirst();
    if (var.isPresent()) {
        var.get().setValue(value);
    } else {
        log.warn("Variable " + key + " not found in " + dcName + " deployment config, creating it.");
        vars.add(new EnvVar(key, value, null));
    }
    dc.getSpec().getTemplate().getSpec().getContainers().get(0).setEnv(vars);
    getInstance().updateDeploymentconfig(dc);
}
Also used : Arrays(java.util.Arrays) DoneablePod(io.fabric8.kubernetes.api.model.DoneablePod) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OpenShifts(cz.xtf.core.openshift.OpenShifts) LocalPortForward(io.fabric8.kubernetes.client.LocalPortForward) TimeoutException(java.util.concurrent.TimeoutException) Matcher(java.util.regex.Matcher) OpenShiftBinary(cz.xtf.core.openshift.OpenShiftBinary) VersionInfo(io.fabric8.kubernetes.client.VersionInfo) OpenShift(cz.xtf.core.openshift.OpenShift) TestConfiguration(io.syndesis.qe.TestConfiguration) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) InfraFail(io.syndesis.qe.test.InfraFail) Predicate(java.util.function.Predicate) Pod(io.fabric8.kubernetes.api.model.Pod) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) PodResource(io.fabric8.kubernetes.client.dsl.PodResource) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Assertions.fail(org.assertj.core.api.Assertions.fail) Stream(java.util.stream.Stream) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) OpenShiftWaitUtils(io.syndesis.qe.wait.OpenShiftWaitUtils) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig)

Example 45 with EnvVar

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

the class MongoDb36 method deploy.

@Override
public void deploy() {
    addAccount();
    if (isDeployed()) {
        return;
    }
    List<ContainerPort> ports = new LinkedList<>();
    ports.add(new ContainerPortBuilder().withName("mongodb").withContainerPort(MONGODB_PORT).withProtocol("TCP").build());
    List<EnvVar> templateParams = new ArrayList<>();
    templateParams.add(new EnvVar("MONGODB_ADMIN_PASSWORD", ADMIN_PASSWORD, null));
    templateParams.add(new EnvVar("MONGODB_USERNAME", MONGODB_USER, null));
    templateParams.add(new EnvVar("MONGODB_PASSWORD", MONGODB_PASSWORD, null));
    templateParams.add(new EnvVar("MONGODB_DATABASE", MONGODB_DATABASE, null));
    templateParams.add(new EnvVar("MONGODB_REPLICA_SET_NAME", MONGODB_REPLICA_SET_NAME, null));
    templateParams.add(new EnvVar("MONGODB_REPLICA_SET_MODE", MONGODB_REPLICA_SET_MODE, null));
    templateParams.add(new EnvVar("MONGODB_REPLICA_SET_KEY", MONGODB_REPLICA_SET_KEY, null));
    templateParams.add(new EnvVar("MONGODB_ROOT_PASSWORD", MONGODB_REPLICA_SET_KEY, null));
    OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(APP_NAME).withImage(MONGODB_IMAGE).addAllToPorts(ports).addAllToEnv(templateParams).endContainer().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
    ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
    serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("mongodb").withPort(MONGODB_PORT).withTargetPort(new IntOrString(MONGODB_PORT)).build());
    OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).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)

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