Search in sources :

Example 1 with KafkaConnectTemplate

use of io.strimzi.api.kafka.model.template.KafkaConnectTemplate in project strimzi by strimzi.

the class KafkaConnectCluster method fromSpec.

/**
 * Abstracts the calling of setters on a (subclass of) KafkaConnectCluster
 * from the instantiation of the (subclass of) KafkaConnectCluster,
 * thus permitting reuse of the setter-calling code for subclasses.
 */
protected static <C extends KafkaConnectCluster> C fromSpec(Reconciliation reconciliation, KafkaConnectSpec spec, KafkaVersion.Lookup versions, C kafkaConnect) {
    kafkaConnect.setReplicas(spec.getReplicas() != null && spec.getReplicas() >= 0 ? spec.getReplicas() : DEFAULT_REPLICAS);
    kafkaConnect.tracing = spec.getTracing();
    AbstractConfiguration config = kafkaConnect.getConfiguration();
    if (config == null) {
        config = new KafkaConnectConfiguration(reconciliation, spec.getConfig().entrySet());
        kafkaConnect.setConfiguration(config);
    }
    if (kafkaConnect.tracing != null) {
        config.setConfigOption("consumer.interceptor.classes", "io.opentracing.contrib.kafka.TracingConsumerInterceptor");
        config.setConfigOption("producer.interceptor.classes", "io.opentracing.contrib.kafka.TracingProducerInterceptor");
    }
    if (kafkaConnect.getImage() == null) {
        kafkaConnect.setImage(versions.kafkaConnectVersion(spec.getImage(), spec.getVersion()));
    }
    kafkaConnect.setResources(spec.getResources());
    kafkaConnect.setLogging(spec.getLogging());
    kafkaConnect.setGcLoggingEnabled(spec.getJvmOptions() == null ? DEFAULT_JVM_GC_LOGGING_ENABLED : spec.getJvmOptions().isGcLoggingEnabled());
    if (spec.getJvmOptions() != null) {
        kafkaConnect.setJavaSystemProperties(spec.getJvmOptions().getJavaSystemProperties());
    }
    kafkaConnect.setJvmOptions(spec.getJvmOptions());
    if (spec.getJmxOptions() != null) {
        kafkaConnect.setJmxEnabled(Boolean.TRUE);
        AuthenticationUtils.configureKafkaConnectJmxOptions(spec.getJmxOptions().getAuthentication(), kafkaConnect);
    }
    if (spec.getReadinessProbe() != null) {
        kafkaConnect.setReadinessProbe(spec.getReadinessProbe());
    }
    if (spec.getLivenessProbe() != null) {
        kafkaConnect.setLivenessProbe(spec.getLivenessProbe());
    }
    kafkaConnect.setRack(spec.getRack());
    String initImage = spec.getClientRackInitImage();
    if (initImage == null) {
        initImage = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_KAFKA_INIT_IMAGE, "quay.io/strimzi/operator:latest");
    }
    kafkaConnect.setInitImage(initImage);
    // Parse different types of metrics configurations
    ModelUtils.parseMetrics(kafkaConnect, spec);
    kafkaConnect.setBootstrapServers(spec.getBootstrapServers());
    kafkaConnect.setTls(spec.getTls());
    String warnMsg = AuthenticationUtils.validateClientAuthentication(spec.getAuthentication(), spec.getTls() != null);
    if (!warnMsg.isEmpty()) {
        LOGGER.warnCr(reconciliation, warnMsg);
    }
    kafkaConnect.setAuthentication(spec.getAuthentication());
    if (spec.getTemplate() != null) {
        KafkaConnectTemplate template = spec.getTemplate();
        ModelUtils.parseDeploymentTemplate(kafkaConnect, template.getDeployment());
        ModelUtils.parsePodTemplate(kafkaConnect, template.getPod());
        ModelUtils.parseInternalServiceTemplate(kafkaConnect, template.getApiService());
        if (template.getClusterRoleBinding() != null && template.getClusterRoleBinding().getMetadata() != null) {
            kafkaConnect.templateClusterRoleBindingLabels = template.getClusterRoleBinding().getMetadata().getLabels();
            kafkaConnect.templateClusterRoleBindingAnnotations = template.getClusterRoleBinding().getMetadata().getAnnotations();
        }
        if (template.getConnectContainer() != null && template.getConnectContainer().getEnv() != null) {
            kafkaConnect.templateContainerEnvVars = template.getConnectContainer().getEnv();
        }
        if (template.getInitContainer() != null && template.getInitContainer().getEnv() != null) {
            kafkaConnect.templateInitContainerEnvVars = template.getInitContainer().getEnv();
        }
        if (template.getConnectContainer() != null && template.getConnectContainer().getSecurityContext() != null) {
            kafkaConnect.templateContainerSecurityContext = template.getConnectContainer().getSecurityContext();
        }
        if (template.getInitContainer() != null && template.getInitContainer().getSecurityContext() != null) {
            kafkaConnect.templateInitContainerSecurityContext = template.getInitContainer().getSecurityContext();
        }
        if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
            kafkaConnect.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
            kafkaConnect.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
        }
        if (template.getJmxSecret() != null && template.getJmxSecret().getMetadata() != null) {
            kafkaConnect.templateJmxSecretLabels = template.getJmxSecret().getMetadata().getLabels();
            kafkaConnect.templateJmxSecretAnnotations = template.getJmxSecret().getMetadata().getAnnotations();
        }
        ModelUtils.parsePodDisruptionBudgetTemplate(kafkaConnect, template.getPodDisruptionBudget());
    }
    if (spec.getExternalConfiguration() != null) {
        ExternalConfiguration externalConfiguration = spec.getExternalConfiguration();
        if (externalConfiguration.getEnv() != null && !externalConfiguration.getEnv().isEmpty()) {
            kafkaConnect.externalEnvs = externalConfiguration.getEnv();
        }
        if (externalConfiguration.getVolumes() != null && !externalConfiguration.getVolumes().isEmpty()) {
            kafkaConnect.externalVolumes = externalConfiguration.getVolumes();
        }
    }
    kafkaConnect.templatePodLabels = Util.mergeLabelsOrAnnotations(kafkaConnect.templatePodLabels, DEFAULT_POD_LABELS);
    return kafkaConnect;
}
Also used : KafkaConnectTemplate(io.strimzi.api.kafka.model.template.KafkaConnectTemplate) ExternalConfiguration(io.strimzi.api.kafka.model.connect.ExternalConfiguration)

Example 2 with KafkaConnectTemplate

use of io.strimzi.api.kafka.model.template.KafkaConnectTemplate in project strimzi-kafka-operator by strimzi.

the class KafkaConnectCluster method fromSpec.

/**
 * Abstracts the calling of setters on a (subclass of) KafkaConnectCluster
 * from the instantiation of the (subclass of) KafkaConnectCluster,
 * thus permitting reuse of the setter-calling code for subclasses.
 */
protected static <C extends KafkaConnectCluster> C fromSpec(Reconciliation reconciliation, KafkaConnectSpec spec, KafkaVersion.Lookup versions, C kafkaConnect) {
    kafkaConnect.setReplicas(spec.getReplicas() != null && spec.getReplicas() >= 0 ? spec.getReplicas() : DEFAULT_REPLICAS);
    kafkaConnect.tracing = spec.getTracing();
    AbstractConfiguration config = kafkaConnect.getConfiguration();
    if (config == null) {
        config = new KafkaConnectConfiguration(reconciliation, spec.getConfig().entrySet());
        kafkaConnect.setConfiguration(config);
    }
    if (kafkaConnect.tracing != null) {
        config.setConfigOption("consumer.interceptor.classes", "io.opentracing.contrib.kafka.TracingConsumerInterceptor");
        config.setConfigOption("producer.interceptor.classes", "io.opentracing.contrib.kafka.TracingProducerInterceptor");
    }
    if (kafkaConnect.getImage() == null) {
        kafkaConnect.setImage(versions.kafkaConnectVersion(spec.getImage(), spec.getVersion()));
    }
    kafkaConnect.setResources(spec.getResources());
    kafkaConnect.setLogging(spec.getLogging());
    kafkaConnect.setGcLoggingEnabled(spec.getJvmOptions() == null ? DEFAULT_JVM_GC_LOGGING_ENABLED : spec.getJvmOptions().isGcLoggingEnabled());
    if (spec.getJvmOptions() != null) {
        kafkaConnect.setJavaSystemProperties(spec.getJvmOptions().getJavaSystemProperties());
    }
    kafkaConnect.setJvmOptions(spec.getJvmOptions());
    if (spec.getJmxOptions() != null) {
        kafkaConnect.setJmxEnabled(Boolean.TRUE);
        AuthenticationUtils.configureKafkaConnectJmxOptions(spec.getJmxOptions().getAuthentication(), kafkaConnect);
    }
    if (spec.getReadinessProbe() != null) {
        kafkaConnect.setReadinessProbe(spec.getReadinessProbe());
    }
    if (spec.getLivenessProbe() != null) {
        kafkaConnect.setLivenessProbe(spec.getLivenessProbe());
    }
    kafkaConnect.setRack(spec.getRack());
    String initImage = spec.getClientRackInitImage();
    if (initImage == null) {
        initImage = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_KAFKA_INIT_IMAGE, "quay.io/strimzi/operator:latest");
    }
    kafkaConnect.setInitImage(initImage);
    // Parse different types of metrics configurations
    ModelUtils.parseMetrics(kafkaConnect, spec);
    kafkaConnect.setBootstrapServers(spec.getBootstrapServers());
    kafkaConnect.setTls(spec.getTls());
    String warnMsg = AuthenticationUtils.validateClientAuthentication(spec.getAuthentication(), spec.getTls() != null);
    if (!warnMsg.isEmpty()) {
        LOGGER.warnCr(reconciliation, warnMsg);
    }
    kafkaConnect.setAuthentication(spec.getAuthentication());
    if (spec.getTemplate() != null) {
        KafkaConnectTemplate template = spec.getTemplate();
        ModelUtils.parseDeploymentTemplate(kafkaConnect, template.getDeployment());
        ModelUtils.parsePodTemplate(kafkaConnect, template.getPod());
        ModelUtils.parseInternalServiceTemplate(kafkaConnect, template.getApiService());
        if (template.getClusterRoleBinding() != null && template.getClusterRoleBinding().getMetadata() != null) {
            kafkaConnect.templateClusterRoleBindingLabels = template.getClusterRoleBinding().getMetadata().getLabels();
            kafkaConnect.templateClusterRoleBindingAnnotations = template.getClusterRoleBinding().getMetadata().getAnnotations();
        }
        if (template.getConnectContainer() != null && template.getConnectContainer().getEnv() != null) {
            kafkaConnect.templateContainerEnvVars = template.getConnectContainer().getEnv();
        }
        if (template.getInitContainer() != null && template.getInitContainer().getEnv() != null) {
            kafkaConnect.templateInitContainerEnvVars = template.getInitContainer().getEnv();
        }
        if (template.getConnectContainer() != null && template.getConnectContainer().getSecurityContext() != null) {
            kafkaConnect.templateContainerSecurityContext = template.getConnectContainer().getSecurityContext();
        }
        if (template.getInitContainer() != null && template.getInitContainer().getSecurityContext() != null) {
            kafkaConnect.templateInitContainerSecurityContext = template.getInitContainer().getSecurityContext();
        }
        if (template.getServiceAccount() != null && template.getServiceAccount().getMetadata() != null) {
            kafkaConnect.templateServiceAccountLabels = template.getServiceAccount().getMetadata().getLabels();
            kafkaConnect.templateServiceAccountAnnotations = template.getServiceAccount().getMetadata().getAnnotations();
        }
        if (template.getJmxSecret() != null && template.getJmxSecret().getMetadata() != null) {
            kafkaConnect.templateJmxSecretLabels = template.getJmxSecret().getMetadata().getLabels();
            kafkaConnect.templateJmxSecretAnnotations = template.getJmxSecret().getMetadata().getAnnotations();
        }
        ModelUtils.parsePodDisruptionBudgetTemplate(kafkaConnect, template.getPodDisruptionBudget());
    }
    if (spec.getExternalConfiguration() != null) {
        ExternalConfiguration externalConfiguration = spec.getExternalConfiguration();
        if (externalConfiguration.getEnv() != null && !externalConfiguration.getEnv().isEmpty()) {
            kafkaConnect.externalEnvs = externalConfiguration.getEnv();
        }
        if (externalConfiguration.getVolumes() != null && !externalConfiguration.getVolumes().isEmpty()) {
            kafkaConnect.externalVolumes = externalConfiguration.getVolumes();
        }
    }
    kafkaConnect.templatePodLabels = Util.mergeLabelsOrAnnotations(kafkaConnect.templatePodLabels, DEFAULT_POD_LABELS);
    return kafkaConnect;
}
Also used : KafkaConnectTemplate(io.strimzi.api.kafka.model.template.KafkaConnectTemplate) ExternalConfiguration(io.strimzi.api.kafka.model.connect.ExternalConfiguration)

Example 3 with KafkaConnectTemplate

use of io.strimzi.api.kafka.model.template.KafkaConnectTemplate in project strimzi by strimzi.

the class KafkaConnectBuild method fromCrd.

/**
 * Created the KafkaConnectBuild instance from the Kafka Connect Custom Resource
 *
 * @param reconciliation The reconciliation
 * @param kafkaConnect  Kafka Connect CR with the build configuration
 * @param versions      Kafka versions configuration
 * @return              Instance of KafkaConnectBuild class
 */
@SuppressWarnings({ "checkstyle:CyclomaticComplexity", "checkstyle:NPathComplexity" })
public static KafkaConnectBuild fromCrd(Reconciliation reconciliation, KafkaConnect kafkaConnect, KafkaVersion.Lookup versions) {
    KafkaConnectBuild build = new KafkaConnectBuild(reconciliation, kafkaConnect);
    KafkaConnectSpec spec = kafkaConnect.getSpec();
    if (spec == null) {
        throw new InvalidResourceException("Required .spec section is missing.");
    }
    build.setOwnerReference(kafkaConnect);
    if (spec.getBuild() != null) {
        validateBuildConfiguration(spec.getBuild());
        // The additionalKanikoOptions are validated separately to avoid parsing the list twice
        if (spec.getBuild().getOutput() != null && spec.getBuild().getOutput() instanceof DockerOutput) {
            DockerOutput dockerOutput = (DockerOutput) spec.getBuild().getOutput();
            if (dockerOutput.getAdditionalKanikoOptions() != null && !dockerOutput.getAdditionalKanikoOptions().isEmpty()) {
                validateAdditionalKanikoOptions(dockerOutput.getAdditionalKanikoOptions());
                build.additionalKanikoOptions = dockerOutput.getAdditionalKanikoOptions();
            }
        }
    }
    build.baseImage = versions.kafkaConnectVersion(spec.getImage(), spec.getVersion());
    if (spec.getTemplate() != null) {
        KafkaConnectTemplate template = spec.getTemplate();
        ModelUtils.parsePodTemplate(build, template.getBuildPod());
        if (template.getBuildContainer() != null && template.getBuildContainer().getEnv() != null) {
            build.templateBuildContainerEnvVars = template.getBuildContainer().getEnv();
        }
        if (template.getBuildContainer() != null && template.getBuildContainer().getSecurityContext() != null) {
            build.templateBuildContainerSecurityContext = template.getBuildContainer().getSecurityContext();
        }
        if (template.getBuildConfig() != null) {
            build.pullSecret = template.getBuildConfig().getPullSecret();
            if (template.getBuildConfig().getMetadata() != null) {
                if (template.getBuildConfig().getMetadata().getLabels() != null) {
                    build.templateBuildConfigLabels = template.getBuildConfig().getMetadata().getLabels();
                }
                if (template.getBuildConfig().getMetadata().getAnnotations() != null) {
                    build.templateBuildConfigAnnotations = template.getBuildConfig().getMetadata().getAnnotations();
                }
            }
        }
        if (template.getBuildServiceAccount() != null && template.getBuildServiceAccount().getMetadata() != null) {
            build.templateServiceAccountLabels = template.getBuildServiceAccount().getMetadata().getLabels();
            build.templateServiceAccountAnnotations = template.getBuildServiceAccount().getMetadata().getAnnotations();
        }
    }
    build.templatePodLabels = Util.mergeLabelsOrAnnotations(build.templatePodLabels, DEFAULT_POD_LABELS);
    build.build = spec.getBuild();
    return build;
}
Also used : KafkaConnectTemplate(io.strimzi.api.kafka.model.template.KafkaConnectTemplate) KafkaConnectSpec(io.strimzi.api.kafka.model.KafkaConnectSpec) DockerOutput(io.strimzi.api.kafka.model.connect.build.DockerOutput)

Example 4 with KafkaConnectTemplate

use of io.strimzi.api.kafka.model.template.KafkaConnectTemplate in project strimzi-kafka-operator by strimzi.

the class KafkaConnectBuild method fromCrd.

/**
 * Created the KafkaConnectBuild instance from the Kafka Connect Custom Resource
 *
 * @param reconciliation The reconciliation
 * @param kafkaConnect  Kafka Connect CR with the build configuration
 * @param versions      Kafka versions configuration
 * @return              Instance of KafkaConnectBuild class
 */
@SuppressWarnings({ "checkstyle:CyclomaticComplexity", "checkstyle:NPathComplexity" })
public static KafkaConnectBuild fromCrd(Reconciliation reconciliation, KafkaConnect kafkaConnect, KafkaVersion.Lookup versions) {
    KafkaConnectBuild build = new KafkaConnectBuild(reconciliation, kafkaConnect);
    KafkaConnectSpec spec = kafkaConnect.getSpec();
    if (spec == null) {
        throw new InvalidResourceException("Required .spec section is missing.");
    }
    build.setOwnerReference(kafkaConnect);
    if (spec.getBuild() != null) {
        validateBuildConfiguration(spec.getBuild());
        // The additionalKanikoOptions are validated separately to avoid parsing the list twice
        if (spec.getBuild().getOutput() != null && spec.getBuild().getOutput() instanceof DockerOutput) {
            DockerOutput dockerOutput = (DockerOutput) spec.getBuild().getOutput();
            if (dockerOutput.getAdditionalKanikoOptions() != null && !dockerOutput.getAdditionalKanikoOptions().isEmpty()) {
                validateAdditionalKanikoOptions(dockerOutput.getAdditionalKanikoOptions());
                build.additionalKanikoOptions = dockerOutput.getAdditionalKanikoOptions();
            }
        }
    }
    build.baseImage = versions.kafkaConnectVersion(spec.getImage(), spec.getVersion());
    if (spec.getTemplate() != null) {
        KafkaConnectTemplate template = spec.getTemplate();
        ModelUtils.parsePodTemplate(build, template.getBuildPod());
        if (template.getBuildContainer() != null && template.getBuildContainer().getEnv() != null) {
            build.templateBuildContainerEnvVars = template.getBuildContainer().getEnv();
        }
        if (template.getBuildContainer() != null && template.getBuildContainer().getSecurityContext() != null) {
            build.templateBuildContainerSecurityContext = template.getBuildContainer().getSecurityContext();
        }
        if (template.getBuildConfig() != null) {
            build.pullSecret = template.getBuildConfig().getPullSecret();
            if (template.getBuildConfig().getMetadata() != null) {
                if (template.getBuildConfig().getMetadata().getLabels() != null) {
                    build.templateBuildConfigLabels = template.getBuildConfig().getMetadata().getLabels();
                }
                if (template.getBuildConfig().getMetadata().getAnnotations() != null) {
                    build.templateBuildConfigAnnotations = template.getBuildConfig().getMetadata().getAnnotations();
                }
            }
        }
        if (template.getBuildServiceAccount() != null && template.getBuildServiceAccount().getMetadata() != null) {
            build.templateServiceAccountLabels = template.getBuildServiceAccount().getMetadata().getLabels();
            build.templateServiceAccountAnnotations = template.getBuildServiceAccount().getMetadata().getAnnotations();
        }
    }
    build.templatePodLabels = Util.mergeLabelsOrAnnotations(build.templatePodLabels, DEFAULT_POD_LABELS);
    build.build = spec.getBuild();
    return build;
}
Also used : KafkaConnectTemplate(io.strimzi.api.kafka.model.template.KafkaConnectTemplate) KafkaConnectSpec(io.strimzi.api.kafka.model.KafkaConnectSpec) DockerOutput(io.strimzi.api.kafka.model.connect.build.DockerOutput)

Example 5 with KafkaConnectTemplate

use of io.strimzi.api.kafka.model.template.KafkaConnectTemplate in project debezium by debezium.

the class OcpKafkaConnectDeployer method configurePullSecret.

private void configurePullSecret(KafkaConnectBuilder kcBuilder, Build kcBuild) {
    KafkaConnectTemplate template = kcBuilder.buildSpec().getTemplate();
    KafkaConnectTemplateBuilder templateBuilder = new KafkaConnectTemplateBuilder(template);
    if (kcBuild == null) {
        templateBuilder.withNewPod().addNewImagePullSecret(pullSecretName);
    } else {
        templateBuilder.withNewBuildConfig().withPullSecret(pullSecretName).endBuildConfig();
    }
    kcBuilder.editSpec().withTemplate(templateBuilder.build()).endSpec();
}
Also used : KafkaConnectTemplate(io.strimzi.api.kafka.model.template.KafkaConnectTemplate) KafkaConnectTemplateBuilder(io.strimzi.api.kafka.model.template.KafkaConnectTemplateBuilder)

Aggregations

KafkaConnectTemplate (io.strimzi.api.kafka.model.template.KafkaConnectTemplate)5 KafkaConnectSpec (io.strimzi.api.kafka.model.KafkaConnectSpec)2 ExternalConfiguration (io.strimzi.api.kafka.model.connect.ExternalConfiguration)2 DockerOutput (io.strimzi.api.kafka.model.connect.build.DockerOutput)2 KafkaConnectTemplateBuilder (io.strimzi.api.kafka.model.template.KafkaConnectTemplateBuilder)1