io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.SecretKeySelectorBuilder.
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: KafkaConnectClusterTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Test public void testInvalidExternalConfigurationEnvs() { ExternalConfigurationEnv env = new ExternalConfigurationEnvBuilder() .withName("MY_ENV_VAR") .withNewValueFrom() .withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("my-map").withKey("my-key").withOptional(false).build()) .withSecretKeyRef(new SecretKeySelectorBuilder().withName("my-secret").withKey("my-key").withOptional(false).build()) .endValueFrom() .build(); KafkaConnect resource = new KafkaConnectBuilder(this.resource) .editSpec() .withNewExternalConfiguration() .withEnv(env) .endExternalConfiguration() .endSpec() .build(); KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(resource, VERSIONS); // Check Deployment Deployment dep = kc.generateDeployment(emptyMap(), true, null, null); List<EnvVar> envs = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv(); List<EnvVar> selected = envs.stream().filter(var -> var.getName().equals("MY_ENV_VAR")).collect(Collectors.toList()); assertThat(selected.size(), is(0)); }
Example #2
Source File: KafkaMirrorMaker2ClusterTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Test public void testInvalidExternalConfigurationEnvs() { ExternalConfigurationEnv env = new ExternalConfigurationEnvBuilder() .withName("MY_ENV_VAR") .withNewValueFrom() .withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("my-map").withKey("my-key").withOptional(false).build()) .withSecretKeyRef(new SecretKeySelectorBuilder().withName("my-secret").withKey("my-key").withOptional(false).build()) .endValueFrom() .build(); KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource) .editSpec() .withNewExternalConfiguration() .withEnv(env) .endExternalConfiguration() .endSpec() .build(); KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(resource, VERSIONS); // Check Deployment Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null); List<EnvVar> envs = getContainer(dep).getEnv(); List<EnvVar> selected = envs.stream().filter(var -> var.getName().equals("MY_ENV_VAR")).collect(Collectors.toList()); assertThat(selected.size(), is(0)); }
Example #3
Source File: KafkaConnectS2IClusterTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Test public void testExternalConfigurationSecretEnvs() { ExternalConfigurationEnv env = new ExternalConfigurationEnvBuilder() .withName("MY_ENV_VAR") .withNewValueFrom() .withSecretKeyRef(new SecretKeySelectorBuilder().withName("my-secret").withKey("my-key").withOptional(false).build()) .endValueFrom() .build(); KafkaConnectS2I resource = new KafkaConnectS2IBuilder(this.resource) .editSpec() .withNewExternalConfiguration() .withEnv(env) .endExternalConfiguration() .endSpec() .build(); KafkaConnectS2ICluster kc = KafkaConnectS2ICluster.fromCrd(resource, VERSIONS); // Check DeploymentConfig DeploymentConfig dep = kc.generateDeploymentConfig(Collections.EMPTY_MAP, true, null, null); List<EnvVar> envs = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv(); List<EnvVar> selected = envs.stream().filter(var -> var.getName().equals("MY_ENV_VAR")).collect(Collectors.toList()); assertThat(selected.size(), is(1)); assertThat(selected.get(0).getName(), is("MY_ENV_VAR")); assertThat(selected.get(0).getValueFrom().getSecretKeyRef(), is(env.getValueFrom().getSecretKeyRef())); }
Example #4
Source File: KafkaConnectS2IClusterTest.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Test public void testInvalidExternalConfigurationEnvs() { ExternalConfigurationEnv env = new ExternalConfigurationEnvBuilder() .withName("MY_ENV_VAR") .withNewValueFrom() .withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("my-map").withKey("my-key").withOptional(false).build()) .withSecretKeyRef(new SecretKeySelectorBuilder().withName("my-secret").withKey("my-key").withOptional(false).build()) .endValueFrom() .build(); KafkaConnectS2I resource = new KafkaConnectS2IBuilder(this.resource) .editSpec() .withNewExternalConfiguration() .withEnv(env) .endExternalConfiguration() .endSpec() .build(); KafkaConnectS2ICluster kc = KafkaConnectS2ICluster.fromCrd(resource, VERSIONS); // Check Deployment DeploymentConfig dep = kc.generateDeploymentConfig(Collections.EMPTY_MAP, true, null, null); List<EnvVar> envs = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv(); List<EnvVar> selected = envs.stream().filter(var -> var.getName().equals("MY_ENV_VAR")).collect(Collectors.toList()); assertThat(selected.size(), is(0)); }
Example #5
Source File: KafkaConnectClusterTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Test public void testExternalConfigurationSecretEnvs() { ExternalConfigurationEnv env = new ExternalConfigurationEnvBuilder() .withName("MY_ENV_VAR") .withNewValueFrom() .withSecretKeyRef(new SecretKeySelectorBuilder().withName("my-secret").withKey("my-key").withOptional(false).build()) .endValueFrom() .build(); KafkaConnect resource = new KafkaConnectBuilder(this.resource) .editSpec() .withNewExternalConfiguration() .withEnv(env) .endExternalConfiguration() .endSpec() .build(); KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(resource, VERSIONS); // Check Deployment Deployment dep = kc.generateDeployment(emptyMap(), true, null, null); List<EnvVar> envs = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv(); List<EnvVar> selected = envs.stream().filter(var -> var.getName().equals("MY_ENV_VAR")).collect(Collectors.toList()); assertThat(selected.size(), is(1)); assertThat(selected.get(0).getName(), is("MY_ENV_VAR")); assertThat(selected.get(0).getValueFrom().getSecretKeyRef(), is(env.getValueFrom().getSecretKeyRef())); }
Example #6
Source File: KafkaMirrorMaker2ClusterTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Test public void testExternalConfigurationSecretEnvs() { ExternalConfigurationEnv env = new ExternalConfigurationEnvBuilder() .withName("MY_ENV_VAR") .withNewValueFrom() .withSecretKeyRef(new SecretKeySelectorBuilder().withName("my-secret").withKey("my-key").withOptional(false).build()) .endValueFrom() .build(); KafkaMirrorMaker2 resource = new KafkaMirrorMaker2Builder(this.resource) .editSpec() .withNewExternalConfiguration() .withEnv(env) .endExternalConfiguration() .endSpec() .build(); KafkaMirrorMaker2Cluster kmm2 = KafkaMirrorMaker2Cluster.fromCrd(resource, VERSIONS); // Check Deployment Deployment dep = kmm2.generateDeployment(emptyMap(), true, null, null); List<EnvVar> envs = getContainer(dep).getEnv(); List<EnvVar> selected = envs.stream().filter(var -> var.getName().equals("MY_ENV_VAR")).collect(Collectors.toList()); assertThat(selected.size(), is(1)); assertThat(selected.get(0).getName(), is("MY_ENV_VAR")); assertThat(selected.get(0).getValueFrom().getSecretKeyRef(), is(env.getValueFrom().getSecretKeyRef())); }
Example #7
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 #8
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()); } } } }