io.fabric8.kubernetes.api.model.EnvVarSourceBuilder Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.EnvVarSourceBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InitJobManagerDecorator.java From flink with Apache License 2.0 | 6 votes |
private Container decorateMainContainer(Container container) { final ResourceRequirements requirements = KubernetesUtils.getResourceRequirements( kubernetesJobManagerParameters.getJobManagerMemoryMB(), kubernetesJobManagerParameters.getJobManagerCPU(), Collections.emptyMap()); return new ContainerBuilder(container) .withName(kubernetesJobManagerParameters.getJobManagerMainContainerName()) .withImage(kubernetesJobManagerParameters.getImage()) .withImagePullPolicy(kubernetesJobManagerParameters.getImagePullPolicy().name()) .withResources(requirements) .withPorts(getContainerPorts()) .withEnv(getCustomizedEnvs()) .addNewEnv() .withName(ENV_FLINK_POD_IP_ADDRESS) .withValueFrom(new EnvVarSourceBuilder() .withNewFieldRef(API_VERSION, POD_IP_FIELD_PATH) .build()) .endEnv() .build(); }
Example #2
Source File: AbstractModel.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
/** * Build an environment variable instance with the provided name from a field reference * using the Downward API * * @param name The name of the environment variable * @param field The field path from which the value is set * * @return The environment variable object */ protected static EnvVar buildEnvVarFromFieldRef(String name, String field) { EnvVarSource envVarSource = new EnvVarSourceBuilder() .withNewFieldRef() .withFieldPath(field) .endFieldRef() .build(); return new EnvVarBuilder() .withName(name) .withValueFrom(envVarSource) .build(); }
Example #3
Source File: SecretEnvVar.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@Override public EnvVar buildEnvVar() { return new EnvVarBuilder() // .withName(getKey()) // .withValueFrom(new EnvVarSourceBuilder() // .withSecretKeyRef( (new SecretKeySelectorBuilder() .withKey(secretKey) .withName(secretName) .withOptional(optional) .build())) // .build()) // .build(); }
Example #4
Source File: KubernetesWithApplicationPropertiesTest.java From quarkus with Apache License 2.0 | 4 votes |
@Test public void assertGeneratedResources() throws IOException { Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); assertThat(kubernetesDir) .isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")) .isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml")); List<HasMetadata> kubernetesList = DeserializationUtil .deserializeAsList(kubernetesDir.resolve("kubernetes.yml")); assertThat(kubernetesList).hasSize(4); assertThat(kubernetesList).filteredOn(i -> "Deployment".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { assertThat(i).isInstanceOfSatisfying(Deployment.class, d -> { assertThat(d.getMetadata()).satisfies(m -> { assertThat(m.getName()).isEqualTo("test-it"); assertThat(m.getLabels()).contains(entry("foo", "bar")); }); assertThat(d.getSpec()).satisfies(deploymentSpec -> { assertThat(deploymentSpec.getReplicas()).isEqualTo(3); assertThat(deploymentSpec.getTemplate()).satisfies(t -> { assertThat(t.getSpec()).satisfies(podSpec -> { assertThat(podSpec.getContainers()).hasOnlyOneElementSatisfying(container -> { assertThat(container.getEnv()).extracting("name", "value") .contains(tuple("MY_ENV_VAR", "SOMEVALUE")); assertThat(container.getEnv()).extracting("name", "valueFrom") .contains(tuple("MY_NAME", new EnvVarSourceBuilder().withNewFieldRef().withFieldPath("metadata.name") .endFieldRef().build())); assertThat(container.getImage()) .isEqualTo("quay.io/grp/kubernetes-with-application-properties:0.1-SNAPSHOT"); assertThat(container.getPorts()).hasOnlyOneElementSatisfying(p -> { assertThat(p.getContainerPort()).isEqualTo(9090); }); assertThat(container.getImagePullPolicy()).isEqualTo("IfNotPresent"); }); }); }); }); }); }); assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { assertThat(i).isInstanceOfSatisfying(Service.class, s -> { assertThat(s.getSpec()).satisfies(spec -> { assertEquals("NodePort", spec.getType()); assertThat(spec.getPorts()).hasSize(1).hasOnlyOneElementSatisfying(p -> { assertThat(p.getPort()).isEqualTo(9090); }); }); }); }); assertThat(kubernetesList).filteredOn(i -> "ServiceAccount".equals(i.getKind())).hasSize(1) .hasOnlyElementsOfType(ServiceAccount.class); assertThat(kubernetesList).filteredOn(i -> "Ingress".equals(i.getKind())).hasOnlyOneElementSatisfying(i -> { assertThat(i).isInstanceOfSatisfying(Ingress.class, in -> { assertThat(in.getSpec().getRules()).hasOnlyOneElementSatisfying(r -> { assertThat(r.getHost()).isEqualTo("example.com"); }); }); }); }
Example #5
Source File: TeiidOpenShiftClient.java From syndesis with Apache License 2.0 | 4 votes |
protected EnvVar envFromSecret(String secret, String key) { return new EnvVarBuilder().withName(envName(key)) .withValueFrom(new EnvVarSourceBuilder().withNewSecretKeyRef(key, secret, false).build()).build(); }
Example #6
Source File: EnvironmentVariableSecretApplier.java From che with Eclipse Public License 2.0 | 4 votes |
/** * Applies secret as environment variable into workspace containers, respecting automount * attribute and optional devfile automount property override. * * @param env kubernetes environment with workspace containers configuration * @param runtimeIdentity identity of current runtime * @param secret source secret to apply * @throws InfrastructureException on misconfigured secrets or other apply error */ @Override public void applySecret(KubernetesEnvironment env, RuntimeIdentity runtimeIdentity, Secret secret) throws InfrastructureException { boolean secretAutomount = Boolean.parseBoolean(secret.getMetadata().getAnnotations().get(ANNOTATION_AUTOMOUNT)); for (PodData podData : env.getPodsData().values()) { if (!podData.getRole().equals(PodRole.DEPLOYMENT)) { continue; } for (Container container : podData.getSpec().getContainers()) { Optional<ComponentImpl> component = getComponent(env, container.getName()); // skip components that explicitly disable automount if (component.isPresent() && isComponentAutomountFalse(component.get())) { continue; } // if automount disabled globally and not overridden in component if (!secretAutomount && (!component.isPresent() || !isComponentAutomountTrue(component.get()))) { continue; } for (Entry<String, String> secretDataEntry : secret.getData().entrySet()) { final String mountEnvName = envName(secret, secretDataEntry.getKey(), runtimeIdentity); container .getEnv() .add( new EnvVarBuilder() .withName(mountEnvName) .withValueFrom( new EnvVarSourceBuilder() .withSecretKeyRef( new SecretKeySelectorBuilder() .withName(secret.getMetadata().getName()) .withKey(secretDataEntry.getKey()) .build()) .build()) .build()); } } } }