Search in sources :

Example 1 with ExternalConfigurationEnvVarSource

use of io.strimzi.api.kafka.model.connect.ExternalConfigurationEnvVarSource in project strimzi 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;
}
Also used : ExternalConfigurationEnv(io.strimzi.api.kafka.model.connect.ExternalConfigurationEnv) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) ArrayList(java.util.ArrayList) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ExternalConfigurationEnvVarSource(io.strimzi.api.kafka.model.connect.ExternalConfigurationEnvVarSource) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) EnvVarSource(io.fabric8.kubernetes.api.model.EnvVarSource) ExternalConfigurationEnvVarSource(io.strimzi.api.kafka.model.connect.ExternalConfigurationEnvVarSource)

Example 2 with ExternalConfigurationEnvVarSource

use of io.strimzi.api.kafka.model.connect.ExternalConfigurationEnvVarSource 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;
}
Also used : ExternalConfigurationEnv(io.strimzi.api.kafka.model.connect.ExternalConfigurationEnv) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) ArrayList(java.util.ArrayList) ContainerEnvVar(io.strimzi.api.kafka.model.ContainerEnvVar) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ExternalConfigurationEnvVarSource(io.strimzi.api.kafka.model.connect.ExternalConfigurationEnvVarSource) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) EnvVarSource(io.fabric8.kubernetes.api.model.EnvVarSource) ExternalConfigurationEnvVarSource(io.strimzi.api.kafka.model.connect.ExternalConfigurationEnvVarSource)

Aggregations

EnvVar (io.fabric8.kubernetes.api.model.EnvVar)2 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)2 EnvVarSource (io.fabric8.kubernetes.api.model.EnvVarSource)2 EnvVarSourceBuilder (io.fabric8.kubernetes.api.model.EnvVarSourceBuilder)2 ContainerEnvVar (io.strimzi.api.kafka.model.ContainerEnvVar)2 ExternalConfigurationEnv (io.strimzi.api.kafka.model.connect.ExternalConfigurationEnv)2 ExternalConfigurationEnvVarSource (io.strimzi.api.kafka.model.connect.ExternalConfigurationEnvVarSource)2 ArrayList (java.util.ArrayList)2