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