Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix openshift deployment related issues #23239

Merged
merged 4 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void buildFromJar(ContainerImageConfig containerImageConfig, BuildpackCon
return;
}

log.info("Starting (local) container image build for jar using builpack.");
String targetImageName = runBuildpackBuild(buildpackConfig, containerImage, containerImageConfig, pushRequest,
outputTarget, false /* isNative */);

Expand Down Expand Up @@ -109,6 +110,7 @@ public void buildFromNative(ContainerImageConfig containerImageConfig, Buildpack
"The native binary produced by the build is not a Linux binary and therefore cannot be used in a Linux container image. Consider adding \"quarkus.native.container-build=true\" to your configuration");
}

log.info("Starting (local) container image build for native binary using buildpack.");
String targetImageName = runBuildpackBuild(buildpackConfig, containerImage, containerImageConfig, pushRequest,
outputTarget, true /* isNative */);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void dockerBuildFromJar(DockerConfig dockerConfig,
dockerFileBaseInformation.get().getBaseImage()));
}

log.info("Building docker image for jar.");
log.info("Starting (local) container image build for jar using docker.");

ImageIdReader reader = new ImageIdReader();
String builtContainerImage = createContainerImage(containerImageConfig, dockerConfig, containerImageInfo, out, reader,
Expand Down Expand Up @@ -143,7 +143,7 @@ public void dockerBuildFromNativeImage(DockerConfig dockerConfig,
"The native binary produced by the build is not a Linux binary and therefore cannot be used in a Linux container image. Consider adding \"quarkus.native.container-build=true\" to your configuration");
}

log.info("Starting docker image build");
log.info("Starting (local) container image build for native binary using docker.");

ImageIdReader reader = new ImageIdReader();
String builtContainerImage = createContainerImage(containerImageConfig, dockerConfig, containerImage, out, reader, true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void buildFromJar(ContainerImageConfig containerImageConfig, JibConfig ji
setUser(jibConfig, jibContainerBuilder);
setPlatforms(jibConfig, jibContainerBuilder);
handleExtraFiles(outputTarget, jibContainerBuilder);
log.info("Starting (local) container image build for jar using jib.");
JibContainer container = containerize(containerImageConfig, jibConfig, containerImage, jibContainerBuilder,
pushRequest.isPresent());
writeOutputFiles(container, jibConfig, outputTarget);
Expand Down Expand Up @@ -195,6 +196,8 @@ public void buildFromNative(ContainerImageConfig containerImageConfig, JibConfig
setUser(jibConfig, jibContainerBuilder);
setPlatforms(jibConfig, jibContainerBuilder);
handleExtraFiles(outputTarget, jibContainerBuilder);

log.info("Starting (local) container image build for native binary using jib.");
JibContainer container = containerize(containerImageConfig, jibConfig, containerImage, jibContainerBuilder,
pushRequest.isPresent());
writeOutputFiles(container, jibConfig, outputTarget);
Expand All @@ -221,7 +224,6 @@ private JibContainer containerize(ContainerImageConfig containerImageConfig,
previousContextStorageSysProp = System.setProperty(OPENTELEMETRY_CONTEXT_CONTEXT_STORAGE_PROVIDER_SYS_PROP,
"default");

log.info("Starting container image build");
JibContainer container = jibContainerBuilder.containerize(containerizer);
log.infof("%s container image %s (%s)\n",
containerImageConfig.isPushExplicitlyEnabled() ? "Pushed" : "Created",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,8 @@ public void openshiftBuildFromJar(OpenshiftConfig openshiftConfig,
}

String namespace = Optional.ofNullable(kubernetesClient.getClient().getNamespace()).orElse("default");
LOG.info("Performing openshift binary build with jar on server: " + kubernetesClient.getClient().getMasterUrl()
+ " in namespace:" + namespace + ".");

LOG.info("Starting (in-cluster) container image build for jar using: " + config.buildStrategy + " on server: "
+ kubernetesClient.getClient().getMasterUrl() + " in namespace:" + namespace + ".");
//The contextRoot is where inside the tarball we will add the jars. A null value means everything will be added under '/' while "target" means everything will be added under '/target'.
//For docker kind of builds where we use instructions like: `COPY target/*.jar /deployments` it using '/target' is a requirement.
//For s2i kind of builds where jars are expected directly in the '/' we have to use null.
Expand Down Expand Up @@ -302,9 +301,9 @@ public void openshiftBuildFromNative(OpenshiftConfig openshiftConfig, S2iConfig
}

String namespace = Optional.ofNullable(kubernetesClient.getClient().getNamespace()).orElse("default");
LOG.info("Performing openshift binary build with native image on server: " + kubernetesClient.getClient().getMasterUrl()
+ " in namespace:" + namespace + ".");

LOG.info("Starting (in-cluster) container image build for jar using: " + config.buildStrategy + " on server: "
+ kubernetesClient.getClient().getMasterUrl() + " in namespace:" + namespace + ".");
Optional<GeneratedFileSystemResourceBuildItem> openshiftYml = generatedResources
.stream()
.filter(r -> r.getName().endsWith("kubernetes" + File.separator + "openshift.yml"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationInfoBuildItem;
import io.quarkus.kubernetes.deployment.OpenshiftConfig;
import io.quarkus.kubernetes.deployment.OpenshiftConfig.DeploymentResourceKind;
import io.quarkus.kubernetes.deployment.ResourceNameUtil;
import io.quarkus.kubernetes.spi.KubernetesDeploymentTargetBuildItem;
import io.quarkus.kubernetes.spi.KubernetesResourceMetadataBuildItem;
Expand All @@ -17,17 +18,15 @@ public void checkOpenshift(ApplicationInfoBuildItem applicationInfo, OpenshiftCo
BuildProducer<KubernetesDeploymentTargetBuildItem> deploymentTargets,
BuildProducer<KubernetesResourceMetadataBuildItem> resourceMeta) {

String kind = config.getDepoymentResourceKind();
String group = config.getDepoymentResourceGroup();
String version = config.getDepoymentResourceVersion();

DeploymentResourceKind deploymentResourceKind = config.getDeploymentResourceKind();
deploymentTargets
.produce(
new KubernetesDeploymentTargetBuildItem(OPENSHIFT, kind, group,
version, true));
new KubernetesDeploymentTargetBuildItem(OPENSHIFT, deploymentResourceKind.kind,
deploymentResourceKind.apiGroup,
deploymentResourceKind.apiVersion, true));

String name = ResourceNameUtil.getResourceName(config, applicationInfo);
resourceMeta.produce(new KubernetesResourceMetadataBuildItem(OPENSHIFT, group,
version, kind, name));
resourceMeta.produce(new KubernetesResourceMetadataBuildItem(OPENSHIFT, deploymentResourceKind.apiGroup,
deploymentResourceKind.apiVersion, deploymentResourceKind.kind, name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private DeploymentTargetEntry determineDeploymentTarget(
final DeploymentTargetEntry selectedTarget;

boolean checkForMissingRegistry = true;
boolean checkForNamespaceGroupAlignment = true;
boolean checkForNamespaceGroupAlignment = false;
List<String> userSpecifiedDeploymentTargets = KubernetesConfigUtil.getUserSpecifiedDeploymentTargets();
if (userSpecifiedDeploymentTargets.isEmpty()) {
selectedTarget = targets.getEntriesSortedByPriority().get(0);
Expand All @@ -155,6 +155,8 @@ private DeploymentTargetEntry determineDeploymentTarget(
if (OPENSHIFT.equals(selectedTarget.getName())) {
checkForMissingRegistry = Capability.CONTAINER_IMAGE_S2I.equals(activeContainerImageCapability)
|| Capability.CONTAINER_IMAGE_OPENSHIFT.equals(activeContainerImageCapability);

// We should ensure that we have image group and namespace alignment we are not using deployment triggers via DeploymentConfig.
if (!targets.getEntriesSortedByPriority().get(0).getKind().equals("DeploymentConfig")) {
checkForNamespaceGroupAlignment = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.quarkus.container.spi.ContainerImageBuildRequestBuildItem;
import io.quarkus.container.spi.ContainerImageInfoBuildItem;
import io.quarkus.container.spi.ContainerImagePushRequestBuildItem;
import io.quarkus.container.spi.FallbackContainerImageRegistryBuildItem;
import io.quarkus.deployment.IsNormalNotRemoteDev;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
Expand All @@ -14,6 +15,7 @@ public class KubernetesDeployerPrerequisite {
@BuildStep(onlyIf = IsNormalNotRemoteDev.class)
public void prepare(ContainerImageInfoBuildItem containerImage,
Optional<SelectedKubernetesDeploymentTargetBuildItem> selectedDeploymentTarget,
Optional<FallbackContainerImageRegistryBuildItem> fallbackRegistry,
BuildProducer<ContainerImageBuildRequestBuildItem> buildRequestProducer,
BuildProducer<ContainerImagePushRequestBuildItem> pushRequestProducer) {

Expand All @@ -28,7 +30,8 @@ public void prepare(ContainerImageInfoBuildItem containerImage,
// 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
// since all updates are meant to find the image from the docker daemon
if (containerImage.getRegistry().isPresent() &&
boolean registryIsPresent = containerImage.getRegistry().isPresent() || fallbackRegistry.isPresent();
if (registryIsPresent &&
!selectedDeploymentTarget.get().getEntry().getName().equals(Constants.MINIKUBE)) {
pushRequestProducer.produce(new ContainerImagePushRequestBuildItem());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

import io.dekorate.kubernetes.annotation.ImagePullPolicy;
import io.dekorate.kubernetes.annotation.ServiceType;
import io.quarkus.container.image.deployment.ContainerImageCapabilitiesUtil;
import io.quarkus.container.image.deployment.ContainerImageConfig;
import io.quarkus.deployment.Capabilities;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;

Expand All @@ -32,9 +35,9 @@ public static enum DeploymentResourceKind {
DeploymentConfig(DEPLOYMENT_CONFIG, DEPLOYMENT_CONFIG_GROUP, DEPLOYMENT_CONFIG_VERSION),
StatefulSet(STATEFULSET, DEPLOYMENT_GROUP, DEPLOYMENT_VERSION);

final String kind;
final String apiGroup;
final String apiVersion;
public final String kind;
public final String apiGroup;
public final String apiVersion;

DeploymentResourceKind(String kind, String apiGroup, String apiVersion) {
this.kind = kind;
Expand All @@ -55,8 +58,8 @@ public static enum DeploymentResourceKind {
* The kind of the deployment resource to use.
* Supported values are 'Deployment' and 'DeploymentConfig' defaulting to the later.
*/
@ConfigItem(defaultValue = "DeploymentConfig")
DeploymentResourceKind deploymentKind;
@ConfigItem
Optional<DeploymentResourceKind> deploymentKind;

/**
* The name of the group this component belongs too
Expand Down Expand Up @@ -505,15 +508,13 @@ public Optional<ExpositionConfig> getExposition() {
return Optional.of(route);
}

public String getDepoymentResourceGroup() {
return deploymentKind.apiGroup;
}

public String getDepoymentResourceVersion() {
return deploymentKind.apiVersion;
public static boolean isOpenshiftBuildEnabled(ContainerImageConfig containerImageConfig, Capabilities capabilities) {
boolean implictlyEnabled = ContainerImageCapabilitiesUtil.getActiveContainerImageCapability(capabilities)
.filter(c -> c.contains("openshift") || c.contains("s2i")).isPresent();
return containerImageConfig.builder.map(b -> b.equals("openshfit") || b.equals("s2i")).orElse(implictlyEnabled);
}

public String getDepoymentResourceKind() {
return deploymentKind.kind;
public DeploymentResourceKind getDeploymentResourceKind() {
return deploymentKind.orElse(DeploymentResourceKind.DeploymentConfig);
}
}
Loading