use of io.strimzi.api.kafka.model.connect.ExternalConfigurationEnv in project strimzi by strimzi.
the class KafkaConnectClusterTest method testInvalidExternalConfigurationEnvs.
@ParallelTest
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(Reconciliation.DUMMY_RECONCILIATION, 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));
}
use of io.strimzi.api.kafka.model.connect.ExternalConfigurationEnv in project strimzi-kafka-operator by strimzi.
the class KafkaConnectCluster method getExternalConfigurationEnvVars.
private List<EnvVar> getExternalConfigurationEnvVars() {
List<EnvVar> varList = new ArrayList<>();
for (ExternalConfigurationEnv var : externalEnvs) {
String name = var.getName();
if (name != null && !name.startsWith("KAFKA_") && !name.startsWith("STRIMZI_")) {
ExternalConfigurationEnvVarSource valueFrom = var.getValueFrom();
if (valueFrom != null) {
if (valueFrom.getConfigMapKeyRef() != null && valueFrom.getSecretKeyRef() != null) {
LOGGER.warnCr(reconciliation, "Environment variable {} with external Kafka Connect configuration has to contain exactly one reference to either ConfigMap or Secret", name);
} else {
if (valueFrom.getConfigMapKeyRef() != null) {
EnvVarSource envVarSource = new EnvVarSourceBuilder().withConfigMapKeyRef(var.getValueFrom().getConfigMapKeyRef()).build();
varList.add(new EnvVarBuilder().withName(name).withValueFrom(envVarSource).build());
} else if (valueFrom.getSecretKeyRef() != null) {
EnvVarSource envVarSource = new EnvVarSourceBuilder().withSecretKeyRef(var.getValueFrom().getSecretKeyRef()).build();
varList.add(new EnvVarBuilder().withName(name).withValueFrom(envVarSource).build());
}
}
}
} else {
LOGGER.warnCr(reconciliation, "Name of an environment variable with external Kafka Connect configuration cannot start with `KAFKA_` or `STRIMZI`.");
}
}
return varList;
}
use of io.strimzi.api.kafka.model.connect.ExternalConfigurationEnv in project strimzi-kafka-operator by strimzi.
the class KafkaConnectClusterTest method testExternalConfigurationSecretEnvs.
@ParallelTest
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(Reconciliation.DUMMY_RECONCILIATION, 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()));
}
use of io.strimzi.api.kafka.model.connect.ExternalConfigurationEnv in project strimzi-kafka-operator by strimzi.
the class KafkaConnectClusterTest method testExternalConfigurationConfigEnvs.
@ParallelTest
public void testExternalConfigurationConfigEnvs() {
ExternalConfigurationEnv env = new ExternalConfigurationEnvBuilder().withName("MY_ENV_VAR").withNewValueFrom().withConfigMapKeyRef(new ConfigMapKeySelectorBuilder().withName("my-map").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(Reconciliation.DUMMY_RECONCILIATION, 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().getConfigMapKeyRef(), is(env.getValueFrom().getConfigMapKeyRef()));
}
use of io.strimzi.api.kafka.model.connect.ExternalConfigurationEnv in project strimzi-kafka-operator by strimzi.
the class KafkaConnectClusterTest method testNoExternalConfigurationEnvs.
@ParallelTest
public void testNoExternalConfigurationEnvs() {
ExternalConfigurationEnv env = new ExternalConfigurationEnvBuilder().withName("MY_ENV_VAR").withNewValueFrom().endValueFrom().build();
KafkaConnect resource = new KafkaConnectBuilder(this.resource).editSpec().withNewExternalConfiguration().withEnv(env).endExternalConfiguration().endSpec().build();
KafkaConnectCluster kc = KafkaConnectCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, 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));
}
Aggregations