use of io.fabric8.kubernetes.api.model.EnvVar in project kubernetes by ballerinax.
the class EnvVarTest method configMapKeyRefTest.
/**
* Build bal file with deployment having name and configMapKeyRef environment variables.
* @throws IOException Error when loading the generated yaml.
* @throws InterruptedException Error when compiling the ballerina file.
* @throws KubernetesPluginException Error when deleting the generated artifacts folder.
*/
@Test
public void configMapKeyRefTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "config_map_key_ref.bal"), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("config_map_key_ref_deployment.yaml").toFile();
Assert.assertTrue(deploymentYAML.exists());
Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
List<EnvVar> envVars = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
Assert.assertEquals(envVars.size(), 2, "Invalid number of environment variables found.");
Assert.assertEquals(envVars.get(0).getName(), "SPECIAL_LEVEL_KEY", "Invalid environment variable name found.");
Assert.assertEquals(envVars.get(0).getValueFrom().getConfigMapKeyRef().getName(), "special-config", "Invalid environment variable value found.");
Assert.assertEquals(envVars.get(0).getValueFrom().getConfigMapKeyRef().getKey(), "special.how", "Invalid environment variable value found.");
Assert.assertEquals(envVars.get(1).getName(), "LOG_LEVEL", "Invalid environment variable name found.");
Assert.assertEquals(envVars.get(1).getValueFrom().getConfigMapKeyRef().getName(), "env-config", "Invalid environment variable value found.");
Assert.assertEquals(envVars.get(1).getValueFrom().getConfigMapKeyRef().getKey(), "log_level", "Invalid environment variable value found.");
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
use of io.fabric8.kubernetes.api.model.EnvVar in project kubernetes by ballerinax.
the class KnativeUtils method populateEnvVar.
/**
* Get a list of environment variables.
*
* @param envMap Map of Environment variables
* @return List of env vars
*/
public static List<EnvVar> populateEnvVar(Map<String, EnvVarValueModel> envMap) {
List<EnvVar> envVars = new ArrayList<>();
if (envMap == null) {
return envVars;
}
envMap.forEach((k, v) -> {
EnvVar envVar = null;
if (v.getValue() != null) {
envVar = new EnvVarBuilder().withName(k).withValue(v.getValue()).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.FieldRef) {
EnvVarValueModel.FieldRef fieldRefModel = (EnvVarValueModel.FieldRef) v.getValueFrom();
ObjectFieldSelector fieldRef = new ObjectFieldSelectorBuilder().withFieldPath(fieldRefModel.getFieldPath()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withFieldRef(fieldRef).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.SecretKeyRef) {
EnvVarValueModel.SecretKeyRef secretKeyRefModel = (EnvVarValueModel.SecretKeyRef) v.getValueFrom();
SecretKeySelector secretRef = new SecretKeySelectorBuilder().withName(secretKeyRefModel.getName()).withKey(secretKeyRefModel.getKey()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withSecretKeyRef(secretRef).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.ResourceFieldRef) {
EnvVarValueModel.ResourceFieldRef resourceFieldRefModel = (EnvVarValueModel.ResourceFieldRef) v.getValueFrom();
ResourceFieldSelector resourceFieldRef = new ResourceFieldSelectorBuilder().withContainerName(resourceFieldRefModel.getContainerName()).withResource(resourceFieldRefModel.getResource()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withResourceFieldRef(resourceFieldRef).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
} else if (v.getValueFrom() instanceof EnvVarValueModel.ConfigMapKeyValue) {
EnvVarValueModel.ConfigMapKeyValue configMapKeyValue = (EnvVarValueModel.ConfigMapKeyValue) v.getValueFrom();
ConfigMapKeySelector configMapKey = new ConfigMapKeySelectorBuilder().withKey(configMapKeyValue.getKey()).withName(configMapKeyValue.getName()).build();
EnvVarSource envVarSource = new EnvVarSourceBuilder().withConfigMapKeyRef(configMapKey).build();
envVar = new EnvVarBuilder().withName(k).withValueFrom(envVarSource).build();
}
if (envVar != null) {
envVars.add(envVar);
}
});
return envVars;
}
use of io.fabric8.kubernetes.api.model.EnvVar in project syndesis-qe by syndesisio.
the class Syndesis method deployOperator.
public void deployOperator() {
List<HasMetadata> resourceList = getOperatorResources();
final String operatorResourcesName = "syndesis-operator";
Optional<HasMetadata> serviceAccount = resourceList.stream().filter(resource -> "ServiceAccount".equals(resource.getKind()) && operatorResourcesName.equals(resource.getMetadata().getName())).findFirst();
if (serviceAccount.isPresent()) {
((ServiceAccount) serviceAccount.get()).getImagePullSecrets().add(new LocalObjectReference(TestConfiguration.syndesisPullSecretName()));
} else {
log.error("Service account not found in resources");
}
OpenShiftUtils.getInstance().serviceAccounts().withName("default").edit().addToImagePullSecrets(new LocalObjectReference(TestConfiguration.syndesisPullSecretName())).done();
List<EnvVar> envVarsToAdd = new ArrayList<>();
envVarsToAdd.add(new EnvVar("TEST_SUPPORT", "true", null));
// For upgrade, we want to override images only for "current" version
if (operatorImage.equals(TestConfiguration.syndesisOperatorImage())) {
Set<Image> images = EnumSet.allOf(Image.class);
for (Image image : images) {
if (TestConfiguration.image(image) != null) {
// override image, e.g. from BUILD_PROPERTIES
log.info("Overriding " + image.name().toLowerCase() + " image with " + TestConfiguration.image(image));
envVarsToAdd.add(new EnvVar("RELATED_IMAGE_" + image.name(), TestConfiguration.image(image), null));
} else {
// use images from Quay instead of DockerHub for Syndesis components
switch(image) {
case META:
case S2I:
case UI:
case SERVER:
case UPGRADE:
log.info("Overriding " + image.name().toLowerCase() + " image with quay variant");
String version = TestConfiguration.syndesisInstallVersion() != null ? TestConfiguration.syndesisInstallVersion() : "latest";
envVarsToAdd.add(new EnvVar("RELATED_IMAGE_" + image.name(), String.format("%s/syndesis/syndesis-%s:%s", TestConfiguration.get().readValue(SYNDESIS_DOCKER_REGISTRY), image.name().toLowerCase(), version), null));
}
}
}
}
if ((TestUtils.isProdBuild() && getOperatorImage().contains("1.8")) || getOperatorImage().contains("1.11")) {
// apply this hotfix for 1.8 prod version, needs for OSD because it doesn't see proxy eng repo
if (TestUtils.isProdBuild()) {
envVarsToAdd.add(new EnvVar("RELATED_IMAGE_PSQL_EXPORTER", "registry.redhat.io/fuse7/fuse-postgres-exporter-rhel7:1.8", null));
}
// needs for upgrade test when previous version is 1.11
DeploymentConfig dc = (DeploymentConfig) resourceList.stream().filter(r -> "DeploymentConfig".equals(r.getKind()) && operatorResourcesName.equals(r.getMetadata().getName())).findFirst().orElseThrow(() -> new RuntimeException("Unable to find deployment config in operator resources"));
dc.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv().addAll(envVarsToAdd);
} else {
Deployment deployment = (Deployment) resourceList.stream().filter(r -> "Deployment".equals(r.getKind()) && operatorResourcesName.equals(r.getMetadata().getName())).findFirst().orElseThrow(() -> new RuntimeException("Unable to find deployment in operator resources"));
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv().addAll(envVarsToAdd);
}
OpenShiftUtils.asRegularUser(() -> OpenShiftUtils.getInstance().resourceList(resourceList).createOrReplace());
log.info("Waiting for syndesis-operator to be ready");
try {
OpenShiftUtils.getInstance().waiters().areExactlyNPodsReady(1, "syndesis.io/component", operatorResourcesName).interval(TimeUnit.SECONDS, 20).timeout(TimeUnit.MINUTES, 10).waitFor();
} catch (WaiterException e) {
InfraFail.fail("Unable to find operator pod in 10 minutes");
}
}
use of io.fabric8.kubernetes.api.model.EnvVar in project syndesis-qe by syndesisio.
the class Kudu method deploy.
@Override
public void deploy() {
if (!OpenShiftUtils.isDcDeployed(APP_NAME)) {
List<ContainerPort> ports = new LinkedList<>();
ports.add(new ContainerPortBuilder().withName(APP_NAME).withContainerPort(KUDU_PORT).withProtocol("TCP").build());
List<EnvVar> templateParams = new ArrayList<>();
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/kudu-2in1:latest").addAllToPorts(ports).addAllToEnv(templateParams).addNewVolumeMount().withName(MOUNT_NAME_MASTER).withMountPath(MOUNT_PATH_MASTER).withReadOnly(false).endVolumeMount().addNewVolumeMount().withName(MOUNT_NAME_TSERVER).withMountPath(MOUNT_PATH_TSERVER).withReadOnly(false).endVolumeMount().endContainer().addNewVolume().withName(MOUNT_NAME_MASTER).withNewEmptyDir().endEmptyDir().endVolume().addNewVolume().withName(MOUNT_NAME_TSERVER).withNewEmptyDir().endEmptyDir().endVolume().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, APP_NAME);
serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName(APP_NAME).withPort(KUDU_PORT).withTargetPort(new IntOrString(KUDU_PORT)).build());
OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(APP_NAME).addToLabels(LABEL_NAME, APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
}
if (!OpenShiftUtils.isDcDeployed(API_APP_NAME)) {
List<ContainerPort> ports = new LinkedList<>();
ports.add(new ContainerPortBuilder().withName(API_APP_NAME).withContainerPort(REST_PORT).build());
OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(API_APP_NAME).addToLabels(LABEL_NAME, API_APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, API_APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, API_APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(API_APP_NAME).withImage("quay.io/syndesis_qe/kudu-rest-api:latest").addAllToPorts(ports).endContainer().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, API_APP_NAME);
serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName("kudu-rest-api-service").withPort(REST_PORT).withTargetPort(new IntOrString(REST_PORT)).build());
OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(API_APP_NAME).addToLabels(LABEL_NAME, API_APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
final Route route = new RouteBuilder().withNewMetadata().withName(API_APP_NAME).endMetadata().withNewSpec().withPath("/").withWildcardPolicy("None").withNewTls().withTermination("edge").withInsecureEdgeTerminationPolicy("Allow").endTls().withNewTo().withKind("Service").withName(API_APP_NAME).endTo().endSpec().build();
log.info("Creating route {} with path {}", API_APP_NAME, "/");
OpenShiftUtils.getInstance().routes().createOrReplace(route);
}
createAccount();
}
use of io.fabric8.kubernetes.api.model.EnvVar in project syndesis-qe by syndesisio.
the class IRC method deployIrcController.
private static void deployIrcController() {
List<ContainerPort> ports = new LinkedList<>();
ports.add(new ContainerPortBuilder().withName(CONTROLLER_APP_NAME).withContainerPort(CONTROLLER_PORT).withProtocol("TCP").build());
List<EnvVar> envVars = new ArrayList<>();
envVars.add(new EnvVar("HOST", SERVER_APP_NAME, null));
OpenShiftUtils.getInstance().deploymentConfigs().createOrReplaceWithNew().editOrNewMetadata().withName(CONTROLLER_APP_NAME).addToLabels(LABEL_NAME, CONTROLLER_APP_NAME).endMetadata().editOrNewSpec().addToSelector(LABEL_NAME, CONTROLLER_APP_NAME).withReplicas(1).editOrNewTemplate().editOrNewMetadata().addToLabels(LABEL_NAME, CONTROLLER_APP_NAME).endMetadata().editOrNewSpec().addNewContainer().withName(CONTROLLER_APP_NAME).withImage("quay.io/syndesis_qe/irc-controller:latest").addAllToPorts(ports).addAllToEnv(envVars).endContainer().endSpec().endTemplate().addNewTrigger().withType("ConfigChange").endTrigger().endSpec().done();
ServiceSpecBuilder serviceSpecBuilder = new ServiceSpecBuilder().addToSelector(LABEL_NAME, CONTROLLER_APP_NAME);
serviceSpecBuilder.addToPorts(new ServicePortBuilder().withName(CONTROLLER_APP_NAME).withPort(CONTROLLER_PORT).withTargetPort(new IntOrString(CONTROLLER_PORT)).build());
OpenShiftUtils.getInstance().services().createOrReplaceWithNew().editOrNewMetadata().withName(CONTROLLER_APP_NAME).addToLabels(LABEL_NAME, CONTROLLER_APP_NAME).endMetadata().editOrNewSpecLike(serviceSpecBuilder.build()).endSpec().done();
OpenShiftUtils.getInstance().routes().createOrReplaceWithNew().withNewMetadata().withName(CONTROLLER_APP_NAME).endMetadata().withNewSpec().withPath("/").withWildcardPolicy("None").withNewTls().withTermination("edge").withInsecureEdgeTerminationPolicy("Allow").endTls().withNewTo().withKind("Service").withName(CONTROLLER_APP_NAME).endTo().endSpec().done();
}
Aggregations