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