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;
}
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();
}
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();
}
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;
}
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;
}
Aggregations