Search in sources :

Example 1 with KafkaConnectDockerfile

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)));
    }
}
Also used : Annotations(io.strimzi.operator.common.Annotations) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) ServiceAccountOperator(io.strimzi.operator.common.operator.resource.ServiceAccountOperator) BuildOperator(io.strimzi.operator.common.operator.resource.BuildOperator) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) BuildConfigOperator(io.strimzi.operator.common.operator.resource.BuildConfigOperator) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Build(io.fabric8.openshift.api.model.Build) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) KafkaConnectBuild(io.strimzi.operator.cluster.model.KafkaConnectBuild) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Pod(io.fabric8.kubernetes.api.model.Pod) KafkaConnectDockerfile(io.strimzi.operator.cluster.model.KafkaConnectDockerfile) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Reconciliation(io.strimzi.operator.common.Reconciliation) ImagePullPolicy(io.strimzi.operator.cluster.model.ImagePullPolicy) KafkaConnectBuildUtils(io.strimzi.operator.cluster.model.KafkaConnectBuildUtils) List(java.util.List) Util(io.strimzi.operator.common.Util) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaConnectDockerfile(io.strimzi.operator.cluster.model.KafkaConnectDockerfile)

Example 2 with KafkaConnectDockerfile

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)));
    }
}
Also used : Annotations(io.strimzi.operator.common.Annotations) LocalObjectReference(io.fabric8.kubernetes.api.model.LocalObjectReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) ServiceAccountOperator(io.strimzi.operator.common.operator.resource.ServiceAccountOperator) BuildOperator(io.strimzi.operator.common.operator.resource.BuildOperator) ConfigMapOperator(io.strimzi.operator.common.operator.resource.ConfigMapOperator) BuildConfigOperator(io.strimzi.operator.common.operator.resource.BuildConfigOperator) PodOperator(io.strimzi.operator.common.operator.resource.PodOperator) Build(io.fabric8.openshift.api.model.Build) ResourceOperatorSupplier(io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier) ReconciliationLogger(io.strimzi.operator.common.ReconciliationLogger) KafkaConnectBuild(io.strimzi.operator.cluster.model.KafkaConnectBuild) DeploymentOperator(io.strimzi.operator.common.operator.resource.DeploymentOperator) Pod(io.fabric8.kubernetes.api.model.Pod) KafkaConnectDockerfile(io.strimzi.operator.cluster.model.KafkaConnectDockerfile) Future(io.vertx.core.Future) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Reconciliation(io.strimzi.operator.common.Reconciliation) ImagePullPolicy(io.strimzi.operator.cluster.model.ImagePullPolicy) KafkaConnectBuildUtils(io.strimzi.operator.cluster.model.KafkaConnectBuildUtils) List(java.util.List) Util(io.strimzi.operator.common.Util) ContainerStateTerminated(io.fabric8.kubernetes.api.model.ContainerStateTerminated) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) PlatformFeaturesAvailability(io.strimzi.operator.PlatformFeaturesAvailability) ClusterOperatorConfig(io.strimzi.operator.cluster.ClusterOperatorConfig) KafkaConnectResources(io.strimzi.api.kafka.model.KafkaConnectResources) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) KafkaConnectDockerfile(io.strimzi.operator.cluster.model.KafkaConnectDockerfile)

Aggregations

ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 ContainerStateTerminated (io.fabric8.kubernetes.api.model.ContainerStateTerminated)2 LocalObjectReference (io.fabric8.kubernetes.api.model.LocalObjectReference)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 Build (io.fabric8.openshift.api.model.Build)2 KafkaConnectResources (io.strimzi.api.kafka.model.KafkaConnectResources)2 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)2 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)2 ImagePullPolicy (io.strimzi.operator.cluster.model.ImagePullPolicy)2 KafkaConnectBuild (io.strimzi.operator.cluster.model.KafkaConnectBuild)2 KafkaConnectBuildUtils (io.strimzi.operator.cluster.model.KafkaConnectBuildUtils)2 KafkaConnectDockerfile (io.strimzi.operator.cluster.model.KafkaConnectDockerfile)2 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)2 Annotations (io.strimzi.operator.common.Annotations)2 Reconciliation (io.strimzi.operator.common.Reconciliation)2 ReconciliationLogger (io.strimzi.operator.common.ReconciliationLogger)2 Util (io.strimzi.operator.common.Util)2 BuildConfigOperator (io.strimzi.operator.common.operator.resource.BuildConfigOperator)2 BuildOperator (io.strimzi.operator.common.operator.resource.BuildOperator)2