Search in sources :

Example 1 with LocalObjectReferenceBuilder

use of io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder 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 2 with LocalObjectReferenceBuilder

use of io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder 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 3 with LocalObjectReferenceBuilder

use of io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder in project fabric8-maven-plugin by fabric8io.

the class OpenshiftBuildService method createBuildStrategy.

private BuildStrategy createBuildStrategy(ImageConfiguration imageConfig, OpenShiftBuildStrategy osBuildStrategy, String openshiftPullSecret) {
    if (osBuildStrategy == OpenShiftBuildStrategy.docker) {
        BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
        Map<String, String> fromExt = buildConfig.getFromExt();
        String fromName, fromKind, fromNamespace;
        if (buildConfig.isDockerFileMode()) {
            fromName = extractBaseFromDockerfile(buildConfig, config.getDockerBuildContext());
        } else {
            fromName = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.name, buildConfig.getFrom());
        }
        fromKind = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.kind, "DockerImage");
        fromNamespace = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.namespace, "ImageStreamTag".equals(fromKind) ? "openshift" : null);
        BuildStrategy buildStrategy = new BuildStrategyBuilder().withType("Docker").withNewDockerStrategy().withNewFrom().withKind(fromKind).withName(fromName).withNamespace(StringUtils.isEmpty(fromNamespace) ? null : fromNamespace).endFrom().withNoCache(checkForNocache(imageConfig)).withEnv(checkForEnv(imageConfig)).endDockerStrategy().build();
        if (openshiftPullSecret != null) {
            buildStrategy.getDockerStrategy().setPullSecret(new LocalObjectReferenceBuilder().withName(openshiftPullSecret).build());
        }
        return buildStrategy;
    } else if (osBuildStrategy == OpenShiftBuildStrategy.s2i) {
        BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration();
        Map<String, String> fromExt = buildConfig.getFromExt();
        String fromName, fromKind, fromNamespace;
        if (buildConfig.isDockerFileMode()) {
            fromName = extractBaseFromDockerfile(buildConfig, config.getDockerBuildContext());
        } else {
            fromName = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.name, buildConfig.getFrom());
        }
        fromKind = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.kind, "DockerImage");
        fromNamespace = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.namespace, "ImageStreamTag".equals(fromKind) ? "openshift" : null);
        BuildStrategy buildStrategy = new BuildStrategyBuilder().withType("Source").withNewSourceStrategy().withNewFrom().withKind(fromKind).withName(fromName).withNamespace(StringUtils.isEmpty(fromNamespace) ? null : fromNamespace).endFrom().withForcePull(config.isForcePullEnabled()).endSourceStrategy().build();
        if (openshiftPullSecret != null) {
            buildStrategy.getSourceStrategy().setPullSecret(new LocalObjectReferenceBuilder().withName(openshiftPullSecret).build());
        }
        return buildStrategy;
    } else {
        throw new IllegalArgumentException("Unsupported BuildStrategy " + osBuildStrategy);
    }
}
Also used : BuildStrategyBuilder(io.fabric8.openshift.api.model.BuildStrategyBuilder) BuildStrategy(io.fabric8.openshift.api.model.BuildStrategy) OpenShiftBuildStrategy(io.fabric8.maven.core.config.OpenShiftBuildStrategy) LocalObjectReferenceBuilder(io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder) Map(java.util.Map) HashMap(java.util.HashMap) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Aggregations

LocalObjectReferenceBuilder (io.fabric8.kubernetes.api.model.LocalObjectReferenceBuilder)3 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 DockerOutput (io.strimzi.api.kafka.model.connect.build.DockerOutput)2 ImageStreamOutput (io.strimzi.api.kafka.model.connect.build.ImageStreamOutput)2 OpenShiftBuildStrategy (io.fabric8.maven.core.config.OpenShiftBuildStrategy)1 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)1 BuildStrategy (io.fabric8.openshift.api.model.BuildStrategy)1 BuildStrategyBuilder (io.fabric8.openshift.api.model.BuildStrategyBuilder)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1