use of io.strimzi.operator.cluster.model.KafkaConnectDockerfile in project strimzi-kafka-operator by strimzi.
the class ConnectBuildOperator method build.
/**
* Builds a new container image with connectors on Kubernetes using Kaniko or on OpenShift using BuildConfig
*
* @param reconciliation The reconciliation
* @param namespace Namespace of the Connect cluster
* @param connectBuild KafkaConnectBuild object
* @param deployment The existing Connect deployment
*
* @return Future for tracking the asynchronous result of the Kubernetes image build
*/
private Future<BuildInfo> build(Reconciliation reconciliation, String namespace, KafkaConnectBuild connectBuild, Deployment deployment) {
String currentBuildRevision = "";
String currentImage = "";
boolean forceRebuild = false;
if (deployment != null) {
// Extract information from the current deployment. This is used to figure out if new build needs to be run or not.
currentBuildRevision = Annotations.stringAnnotation(deployment.getSpec().getTemplate(), Annotations.STRIMZI_IO_CONNECT_BUILD_REVISION, null);
currentImage = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
forceRebuild = Annotations.hasAnnotation(deployment, Annotations.STRIMZI_IO_CONNECT_FORCE_REBUILD);
}
KafkaConnectDockerfile dockerfile = connectBuild.generateDockerfile();
String newBuildRevision = dockerfile.hashStub() + Util.hashStub(connectBuild.getBuild().getOutput().getImage());
ConfigMap dockerFileConfigMap = connectBuild.generateDockerfileConfigMap(dockerfile);
if (newBuildRevision.equals(currentBuildRevision) && !forceRebuild) {
// The revision is the same and rebuild was not forced => nothing to do
LOGGER.debugCr(reconciliation, "Build configuration did not change. Nothing new to build. Container image {} will be used.", currentImage);
return Future.succeededFuture(new BuildInfo(currentImage, newBuildRevision));
} else if (pfa.supportsS2I()) {
// Revisions differ and we have S2I support => we are on OpenShift and should do a build
return openShiftBuild(reconciliation, namespace, connectBuild, forceRebuild, dockerfile, newBuildRevision).compose(image -> Future.succeededFuture(new BuildInfo(image, newBuildRevision)));
} else {
// Revisions differ and no S2I support => we are on Kubernetes and should do a build
return kubernetesBuild(reconciliation, namespace, connectBuild, forceRebuild, dockerFileConfigMap, newBuildRevision).compose(image -> Future.succeededFuture(new BuildInfo(image, newBuildRevision)));
}
}
use of io.strimzi.operator.cluster.model.KafkaConnectDockerfile in project strimzi by strimzi.
the class ConnectBuildOperator method build.
/**
* Builds a new container image with connectors on Kubernetes using Kaniko or on OpenShift using BuildConfig
*
* @param reconciliation The reconciliation
* @param namespace Namespace of the Connect cluster
* @param connectBuild KafkaConnectBuild object
* @param deployment The existing Connect deployment
*
* @return Future for tracking the asynchronous result of the Kubernetes image build
*/
private Future<BuildInfo> build(Reconciliation reconciliation, String namespace, KafkaConnectBuild connectBuild, Deployment deployment) {
String currentBuildRevision = "";
String currentImage = "";
boolean forceRebuild = false;
if (deployment != null) {
// Extract information from the current deployment. This is used to figure out if new build needs to be run or not.
currentBuildRevision = Annotations.stringAnnotation(deployment.getSpec().getTemplate(), Annotations.STRIMZI_IO_CONNECT_BUILD_REVISION, null);
currentImage = deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage();
forceRebuild = Annotations.hasAnnotation(deployment, Annotations.STRIMZI_IO_CONNECT_FORCE_REBUILD);
}
KafkaConnectDockerfile dockerfile = connectBuild.generateDockerfile();
String newBuildRevision = dockerfile.hashStub() + Util.hashStub(connectBuild.getBuild().getOutput().getImage());
ConfigMap dockerFileConfigMap = connectBuild.generateDockerfileConfigMap(dockerfile);
if (newBuildRevision.equals(currentBuildRevision) && !forceRebuild) {
// The revision is the same and rebuild was not forced => nothing to do
LOGGER.debugCr(reconciliation, "Build configuration did not change. Nothing new to build. Container image {} will be used.", currentImage);
return Future.succeededFuture(new BuildInfo(currentImage, newBuildRevision));
} else if (pfa.supportsS2I()) {
// Revisions differ and we have S2I support => we are on OpenShift and should do a build
return openShiftBuild(reconciliation, namespace, connectBuild, forceRebuild, dockerfile, newBuildRevision).compose(image -> Future.succeededFuture(new BuildInfo(image, newBuildRevision)));
} else {
// Revisions differ and no S2I support => we are on Kubernetes and should do a build
return kubernetesBuild(reconciliation, namespace, connectBuild, forceRebuild, dockerFileConfigMap, newBuildRevision).compose(image -> Future.succeededFuture(new BuildInfo(image, newBuildRevision)));
}
}
Aggregations