Search in sources :

Example 1 with DockerOutput

use of io.strimzi.api.kafka.model.connect.build.DockerOutput in project strimzi by strimzi.

the class KafkaConnectBuild method getVolumes.

/**
 * Generates a list of volumes used by the builder pod
 *
 * @param isOpenShift   Flag defining whether we are running on OpenShift
 *
 * @return  List of volumes
 */
private List<Volume> getVolumes(boolean isOpenShift) {
    List<Volume> volumes = new ArrayList<>(2);
    volumes.add(VolumeUtils.createConfigMapVolume("dockerfile", KafkaConnectResources.dockerFileConfigMapName(cluster), Collections.singletonMap("Dockerfile", "Dockerfile")));
    if (build.getOutput() instanceof DockerOutput) {
        DockerOutput output = (DockerOutput) build.getOutput();
        if (output.getPushSecret() != null) {
            volumes.add(VolumeUtils.createSecretVolume("docker-credentials", output.getPushSecret(), Collections.singletonMap(".dockerconfigjson", "config.json"), isOpenShift));
        }
    } else {
        throw new RuntimeException("Kubernetes build requires output of type `docker`.");
    }
    return volumes;
}
Also used : Volume(io.fabric8.kubernetes.api.model.Volume) ArrayList(java.util.ArrayList) DockerOutput(io.strimzi.api.kafka.model.connect.build.DockerOutput)

Example 2 with DockerOutput

use of io.strimzi.api.kafka.model.connect.build.DockerOutput in project strimzi by strimzi.

the class KafkaConnectBuild method generateBuildConfig.

/**
 * Generates a BuildConfig which will be used to build new container images with additional connector plugins on OCP.
 *
 * @param dockerfile    Dockerfile which should be built by the BuildConfig
 *
 * @return  OpenShift BuildConfig for building new container images on OpenShift
 */
public BuildConfig generateBuildConfig(KafkaConnectDockerfile dockerfile) {
    BuildOutput output;
    if (build.getOutput() instanceof DockerOutput) {
        DockerOutput dockerOutput = (DockerOutput) build.getOutput();
        output = new BuildOutputBuilder().withNewTo().withKind("DockerImage").withName(dockerOutput.getImage()).endTo().build();
        if (dockerOutput.getPushSecret() != null) {
            output.setPushSecret(new LocalObjectReferenceBuilder().withName(dockerOutput.getPushSecret()).build());
        }
    } else if (build.getOutput() instanceof ImageStreamOutput) {
        ImageStreamOutput imageStreamOutput = (ImageStreamOutput) build.getOutput();
        output = new BuildOutputBuilder().withNewTo().withKind("ImageStreamTag").withName(imageStreamOutput.getImage()).endTo().build();
    } else {
        throw new RuntimeException("Unknown output type " + build.getOutput().getType());
    }
    DockerBuildStrategyBuilder dockerBuildStrategyBuilder = new DockerBuildStrategyBuilder();
    if (pullSecret != null) {
        dockerBuildStrategyBuilder.withNewPullSecret().withName(pullSecret).endPullSecret();
    }
    return new BuildConfigBuilder().withNewMetadata().withName(KafkaConnectResources.buildConfigName(cluster)).withLabels(getLabelsWithStrimziName(name, templateBuildConfigLabels).toMap()).withAnnotations(templateBuildConfigAnnotations).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withOutput(output).withNewSource().withType("Dockerfile").withDockerfile(dockerfile.getDockerfile()).endSource().withNewStrategy().withType("Docker").withDockerStrategy(dockerBuildStrategyBuilder.build()).endStrategy().withResources(build.getResources()).withRunPolicy("Serial").withFailedBuildsHistoryLimit(5).withSuccessfulBuildsHistoryLimit(5).withFailedBuildsHistoryLimit(5).endSpec().build();
}
Also used : BuildOutput(io.fabric8.openshift.api.model.BuildOutput) ImageStreamOutput(io.strimzi.api.kafka.model.connect.build.ImageStreamOutput) DockerBuildStrategyBuilder(io.fabric8.openshift.api.model.DockerBuildStrategyBuilder) BuildOutputBuilder(io.fabric8.openshift.api.model.BuildOutputBuilder) DockerOutput(io.strimzi.api.kafka.model.connect.build.DockerOutput) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder)

Example 3 with DockerOutput

use of io.strimzi.api.kafka.model.connect.build.DockerOutput in project strimzi-kafka-operator by strimzi.

the class KafkaConnectBuild method generateBuildConfig.

/**
 * Generates a BuildConfig which will be used to build new container images with additional connector plugins on OCP.
 *
 * @param dockerfile    Dockerfile which should be built by the BuildConfig
 *
 * @return  OpenShift BuildConfig for building new container images on OpenShift
 */
public BuildConfig generateBuildConfig(KafkaConnectDockerfile dockerfile) {
    BuildOutput output;
    if (build.getOutput() instanceof DockerOutput) {
        DockerOutput dockerOutput = (DockerOutput) build.getOutput();
        output = new BuildOutputBuilder().withNewTo().withKind("DockerImage").withName(dockerOutput.getImage()).endTo().build();
        if (dockerOutput.getPushSecret() != null) {
            output.setPushSecret(new LocalObjectReferenceBuilder().withName(dockerOutput.getPushSecret()).build());
        }
    } else if (build.getOutput() instanceof ImageStreamOutput) {
        ImageStreamOutput imageStreamOutput = (ImageStreamOutput) build.getOutput();
        output = new BuildOutputBuilder().withNewTo().withKind("ImageStreamTag").withName(imageStreamOutput.getImage()).endTo().build();
    } else {
        throw new RuntimeException("Unknown output type " + build.getOutput().getType());
    }
    DockerBuildStrategyBuilder dockerBuildStrategyBuilder = new DockerBuildStrategyBuilder();
    if (pullSecret != null) {
        dockerBuildStrategyBuilder.withNewPullSecret().withName(pullSecret).endPullSecret();
    }
    return new BuildConfigBuilder().withNewMetadata().withName(KafkaConnectResources.buildConfigName(cluster)).withLabels(getLabelsWithStrimziName(name, templateBuildConfigLabels).toMap()).withAnnotations(templateBuildConfigAnnotations).withNamespace(namespace).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withOutput(output).withNewSource().withType("Dockerfile").withDockerfile(dockerfile.getDockerfile()).endSource().withNewStrategy().withType("Docker").withDockerStrategy(dockerBuildStrategyBuilder.build()).endStrategy().withResources(build.getResources()).withRunPolicy("Serial").withFailedBuildsHistoryLimit(5).withSuccessfulBuildsHistoryLimit(5).withFailedBuildsHistoryLimit(5).endSpec().build();
}
Also used : BuildOutput(io.fabric8.openshift.api.model.BuildOutput) ImageStreamOutput(io.strimzi.api.kafka.model.connect.build.ImageStreamOutput) DockerBuildStrategyBuilder(io.fabric8.openshift.api.model.DockerBuildStrategyBuilder) BuildOutputBuilder(io.fabric8.openshift.api.model.BuildOutputBuilder) DockerOutput(io.strimzi.api.kafka.model.connect.build.DockerOutput) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) BuildConfigBuilder(io.fabric8.openshift.api.model.BuildConfigBuilder)

Example 4 with DockerOutput

use of io.strimzi.api.kafka.model.connect.build.DockerOutput in project strimzi by strimzi.

the class KafkaConnectBuild method getVolumeMounts.

/**
 * Generates a list of volume mounts used by the builder pod
 *
 * @return  List of volume mounts
 */
private List<VolumeMount> getVolumeMounts() {
    List<VolumeMount> volumeMounts = new ArrayList<>(2);
    volumeMounts.add(new VolumeMountBuilder().withName("dockerfile").withMountPath("/dockerfile").build());
    if (build.getOutput() instanceof DockerOutput) {
        DockerOutput output = (DockerOutput) build.getOutput();
        if (output.getPushSecret() != null) {
            volumeMounts.add(new VolumeMountBuilder().withName("docker-credentials").withMountPath("/kaniko/.docker").build());
        }
    } else {
        throw new RuntimeException("Kubernetes build requires output of type `docker`.");
    }
    return volumeMounts;
}
Also used : ArrayList(java.util.ArrayList) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) DockerOutput(io.strimzi.api.kafka.model.connect.build.DockerOutput)

Example 5 with DockerOutput

use of io.strimzi.api.kafka.model.connect.build.DockerOutput 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)

Aggregations

DockerOutput (io.strimzi.api.kafka.model.connect.build.DockerOutput)8 ArrayList (java.util.ArrayList)4 LocalObjectReferenceBuilder (io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder)2 Volume (io.fabric8.kubernetes.api.model.Volume)2 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)2 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)2 BuildConfigBuilder (io.fabric8.openshift.api.model.BuildConfigBuilder)2 BuildOutput (io.fabric8.openshift.api.model.BuildOutput)2 BuildOutputBuilder (io.fabric8.openshift.api.model.BuildOutputBuilder)2 DockerBuildStrategyBuilder (io.fabric8.openshift.api.model.DockerBuildStrategyBuilder)2 KafkaConnectSpec (io.strimzi.api.kafka.model.KafkaConnectSpec)2 ImageStreamOutput (io.strimzi.api.kafka.model.connect.build.ImageStreamOutput)2 KafkaConnectTemplate (io.strimzi.api.kafka.model.template.KafkaConnectTemplate)2