Skip to content

Commit

Permalink
Make quarkus.container-image.push=false effective in all k8s extensions
Browse files Browse the repository at this point in the history
This change makes sure that quarkus.container-image.push=false is
 taken into account and always prevents container images from being
 pushed, even if a kubernetes extension requests a deployment.

Resolves: quarkusio#26385
  • Loading branch information
geoand committed Jul 5, 2022
1 parent 7c5db92 commit 7612dde
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
Expand Up @@ -37,6 +37,7 @@
import io.fabric8.openshift.api.model.Route;
import io.fabric8.openshift.client.OpenShiftClient;
import io.quarkus.container.image.deployment.ContainerImageCapabilitiesUtil;
import io.quarkus.container.image.deployment.ContainerImageConfig;
import io.quarkus.container.spi.ContainerImageInfoBuildItem;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Capability;
Expand Down Expand Up @@ -64,7 +65,9 @@ public class KubernetesDeployer {
public void selectDeploymentTarget(ContainerImageInfoBuildItem containerImageInfo,
EnabledKubernetesDeploymentTargetsBuildItem targets,
Capabilities capabilities,
BuildProducer<SelectedKubernetesDeploymentTargetBuildItem> selectedDeploymentTarget) {
ContainerImageConfig containerImageConfig,
BuildProducer<SelectedKubernetesDeploymentTargetBuildItem> selectedDeploymentTarget,
BuildProducer<PreventImplicitContainerImagePushBuildItem> preventImplicitContainerImagePush) {

Optional<String> activeContainerImageCapability = ContainerImageCapabilitiesUtil
.getActiveContainerImageCapability(capabilities);
Expand All @@ -75,8 +78,11 @@ public void selectDeploymentTarget(ContainerImageInfoBuildItem containerImageInf
}

final DeploymentTargetEntry selectedTarget = determineDeploymentTarget(
containerImageInfo, targets, activeContainerImageCapability.get());
containerImageInfo, targets, activeContainerImageCapability.get(), containerImageConfig);
selectedDeploymentTarget.produce(new SelectedKubernetesDeploymentTargetBuildItem(selectedTarget));
if (MINIKUBE.equals(selectedTarget.getName())) {
preventImplicitContainerImagePush.produce(new PreventImplicitContainerImagePushBuildItem());
}
}

@BuildStep
Expand Down Expand Up @@ -141,7 +147,8 @@ public void deploy(KubernetesClientBuildItem kubernetesClient,
*/
private DeploymentTargetEntry determineDeploymentTarget(
ContainerImageInfoBuildItem containerImageInfo,
EnabledKubernetesDeploymentTargetsBuildItem targets, String activeContainerImageCapability) {
EnabledKubernetesDeploymentTargetsBuildItem targets, String activeContainerImageCapability,
ContainerImageConfig containerImageConfig) {
final DeploymentTargetEntry selectedTarget;

boolean checkForMissingRegistry = true;
Expand Down Expand Up @@ -180,6 +187,8 @@ private DeploymentTargetEntry determineDeploymentTarget(

} else if (MINIKUBE.equals(selectedTarget.getName())) {
checkForMissingRegistry = false;
} else if (containerImageConfig.isPushExplicitlyDisabled()) {
checkForMissingRegistry = false;
}

if (checkForMissingRegistry && !containerImageInfo.getRegistry().isPresent()) {
Expand Down
@@ -1,5 +1,6 @@
package io.quarkus.kubernetes.deployment;

import java.util.List;
import java.util.Optional;

import io.quarkus.container.spi.ContainerImageBuildRequestBuildItem;
Expand All @@ -16,6 +17,7 @@ public class KubernetesDeployerPrerequisite {
public void prepare(ContainerImageInfoBuildItem containerImage,
Optional<SelectedKubernetesDeploymentTargetBuildItem> selectedDeploymentTarget,
Optional<FallbackContainerImageRegistryBuildItem> fallbackRegistry,
List<PreventImplicitContainerImagePushBuildItem> preventImplicitContainerImagePush,
BuildProducer<ContainerImageBuildRequestBuildItem> buildRequestProducer,
BuildProducer<ContainerImagePushRequestBuildItem> pushRequestProducer) {

Expand All @@ -28,11 +30,10 @@ public void prepare(ContainerImageInfoBuildItem containerImage,
//Let's communicate to the container-image plugin that we need an image build and an image push.
buildRequestProducer.produce(new ContainerImageBuildRequestBuildItem());
// When a registry is present, we want to push the image
// However we need to make sure we don't push to the registry when deploying to Minikube
// However we need to make sure we don't push to the registry when deploying to a local cluster
// since all updates are meant to find the image from the docker daemon
boolean registryIsPresent = containerImage.getRegistry().isPresent() || fallbackRegistry.isPresent();
if (registryIsPresent &&
!selectedDeploymentTarget.get().getEntry().getName().equals(Constants.MINIKUBE)) {
if (registryIsPresent && preventImplicitContainerImagePush.isEmpty()) {
pushRequestProducer.produce(new ContainerImagePushRequestBuildItem());
}
}
Expand Down
Expand Up @@ -31,6 +31,7 @@
import io.dekorate.project.Project;
import io.dekorate.utils.Maps;
import io.dekorate.utils.Strings;
import io.quarkus.container.image.deployment.ContainerImageConfig;
import io.quarkus.deployment.Capabilities;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.IsTest;
Expand Down Expand Up @@ -81,6 +82,14 @@ public EnabledKubernetesDeploymentTargetsBuildItem enabledKubernetesDeploymentTa
return new EnabledKubernetesDeploymentTargetsBuildItem(entries);
}

@BuildStep
public void preventContainerPush(ContainerImageConfig containerImageConfig,
BuildProducer<PreventImplicitContainerImagePushBuildItem> producer) {
if (containerImageConfig.isPushExplicitlyDisabled()) {
producer.produce(new PreventImplicitContainerImagePushBuildItem());
}
}

@BuildStep(onlyIfNot = IsTest.class)
public void build(ApplicationInfoBuildItem applicationInfo,
OutputTargetBuildItem outputTarget,
Expand Down
@@ -0,0 +1,13 @@
package io.quarkus.kubernetes.deployment;

import io.quarkus.builder.item.MultiBuildItem;

/**
* A build item that is used to prevent the Kubernetes processing from requesting
* a container image push request.
* This is useful for cases where the kubernetes cluster is local and the container image
* is built directly into a context (i.e. a docker daemon) which the cluster has access to.
*/
public final class PreventImplicitContainerImagePushBuildItem extends MultiBuildItem {

}

0 comments on commit 7612dde

Please sign in to comment.