Skip to content

Commit

Permalink
Merge branch 'main' into bump/kindcontainer
Browse files Browse the repository at this point in the history
  • Loading branch information
gonmmarques authored Mar 5, 2024
2 parents 9493a7e + 74df926 commit f409b01
Show file tree
Hide file tree
Showing 43 changed files with 1,151 additions and 221 deletions.
10 changes: 2 additions & 8 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<packaging>pom</packaging>

<properties>
<angus-activation.version>2.0.1</angus-activation.version>
<angus-activation.version>2.0.2</angus-activation.version>
<bouncycastle.version>1.77</bouncycastle.version>
<bouncycastle.fips.version>1.0.2.4</bouncycastle.fips.version>
<bouncycastle.tls.fips.version>1.0.18</bouncycastle.tls.fips.version>
Expand Down Expand Up @@ -64,7 +64,7 @@
<smallrye-mutiny-vertx-binding.version>3.9.0</smallrye-mutiny-vertx-binding.version>
<smallrye-reactive-messaging.version>4.17.0</smallrye-reactive-messaging.version>
<smallrye-stork.version>2.5.0</smallrye-stork.version>
<jakarta.activation.version>2.1.2</jakarta.activation.version>
<jakarta.activation.version>2.1.3</jakarta.activation.version>
<jakarta.annotation-api.version>2.1.1</jakarta.annotation-api.version>
<jakarta.authentication-api>3.0.0</jakarta.authentication-api>
<jakarta.authorization-api.version>2.1.0</jakarta.authorization-api.version>
Expand Down Expand Up @@ -140,7 +140,6 @@
<rest-assured.version>5.4.0</rest-assured.version>
<hamcrest.version>2.2</hamcrest.version><!-- The version needs to be compatible with both REST Assured and Awaitility -->
<junit.jupiter.version>5.10.2</junit.jupiter.version>
<junit-pioneer.version>1.5.0</junit-pioneer.version>
<infinispan.version>14.0.25.Final</infinispan.version>
<infinispan.protostream.version>4.6.5.Final</infinispan.protostream.version>
<caffeine.version>3.1.5</caffeine.version>
Expand Down Expand Up @@ -5241,11 +5240,6 @@
<artifactId>elasticsearch-rest-client-sniffer</artifactId>
<version>${elasticsearch-opensource-components.version}</version>
</dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>${junit-pioneer.version}</version>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<opensearch-server.version>2.11.1</opensearch-server.version>
<opensearch.image>docker.io/opensearchproject/opensearch:${opensearch-server.version}</opensearch.image>
<opensearch.protocol>http</opensearch.protocol>
<junit-pioneer.version>2.2.0</junit-pioneer.version>

<!-- Database images for JDBC/Reactive/Hibernate tests and devservices -->
<postgres.image>docker.io/postgres:14</postgres.image>
Expand Down Expand Up @@ -289,6 +290,12 @@
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>${junit-pioneer.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.asciidoctor</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,11 @@ private void copyDependency(Set<ArtifactKey> parentFirstArtifacts, OutputTargetB
}
}
if (removedFromThisArchive.isEmpty()) {
Files.copy(resolvedDep, targetPath, StandardCopyOption.REPLACE_EXISTING);
Files.copy(resolvedDep, targetPath, StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES);
} else {
//we have removed classes, we need to handle them correctly
// we copy jars for which we remove entries to the same directory
// which seems a bit odd to me
filterZipFile(resolvedDep, targetPath, removedFromThisArchive);
}
}
Expand Down Expand Up @@ -1251,6 +1253,8 @@ private void filterZipFile(Path resolvedDep, Path targetPath, Set<String> transf
}
}
}
// let's make sure we keep the original timestamp
Files.setLastModifiedTime(targetPath, Files.getLastModifiedTime(resolvedDep));
}
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
15 changes: 14 additions & 1 deletion docs/src/main/asciidoc/getting-started-testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,20 @@ So if you need to call methods such as `verify` you should hang on to the mock i
==== Further simplification with `@InjectMock`

Building on the features provided by `QuarkusMock`, Quarkus also allows users to effortlessly take advantage of link:https://site.mockito.org/[Mockito] for mocking the beans supported by `QuarkusMock`.
This functionality is available with the `@io.quarkus.test.InjectMock` annotation if the `quarkus-junit5-mockito` dependency is present.

[IMPORTANT]
====
This functionality is available with the `@io.quarkus.test.InjectMock` annotation **only if** the `quarkus-junit5-mockito` dependency is present:
[source,xml]
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-mockito</artifactId>
<scope>test</scope>
</dependency>
----
====

Using `@InjectMock`, the previous example could be written as follows:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,9 @@ quarkus.oidc-client.credentials.secret=secret
quarkus.oidc-client.grant.type=exchange
quarkus.oidc-client.grant-options.exchange.audience=quarkus-app-exchange
quarkus.oidc-token-propagation.exchange-token=true
quarkus.oidc-token-propagation.exchange-token=true <1>
----
<1> Please note that the `exchange-token` configuration property is ignored when the OidcClient name is set with the `io.quarkus.oidc.token.propagation.AccessToken#exchangeTokenClient` annotation attribute.

Note `AccessTokenRequestReactiveFilter` will use `OidcClient` to exchange the current token, and you can use `quarkus.oidc-client.grant-options.exchange` to set the additional exchange properties expected by your OpenID Connect Provider.

Expand All @@ -1051,7 +1052,7 @@ quarkus.oidc-client.scopes=https://graph.microsoft.com/user.read,offline_access
quarkus.oidc-token-propagation-reactive.exchange-token=true
----

`AccessTokenRequestReactiveFilter` uses a default `OidcClient` by default. A named `OidcClient` can be selected with a `quarkus.oidc-token-propagation-reactive.client-name` configuration property.
`AccessTokenRequestReactiveFilter` uses a default `OidcClient` by default. A named `OidcClient` can be selected with a `quarkus.oidc-token-propagation-reactive.client-name` configuration property or with the `io.quarkus.oidc.token.propagation.AccessToken#exchangeTokenClient` annotation attribute.

[[token-propagation]]
== Token Propagation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,14 @@ private JibContainerBuilder createContainerBuilderFromFastJar(String baseJvmImag

try {
Instant now = Instant.now();
boolean enforceModificationTime = !jibConfig.useCurrentTimestampFileModification;
Instant modificationTime = jibConfig.useCurrentTimestampFileModification ? now : Instant.EPOCH;

JibContainerBuilder jibContainerBuilder = toJibContainerBuilder(baseJvmImage, jibConfig);
if (fastChangingLibPaths.isEmpty()) {
// just create a layer with the entire lib structure intact
addLayer(jibContainerBuilder, Collections.singletonList(componentsPath.resolve(JarResultBuildStep.LIB)),
workDirInContainer, "fast-jar-lib", isMutableJar, modificationTime);
workDirInContainer, "fast-jar-lib", isMutableJar, enforceModificationTime, modificationTime);
} else {
// we need to manually create each layer
// the idea here is that the fast changing libraries are created in a later layer, thus when they do change,
Expand All @@ -549,14 +550,9 @@ private JibContainerBuilder createContainerBuilderFromFastJar(String baseJvmImag
AbsoluteUnixPath libPathInContainer = workDirInContainer.resolve(JarResultBuildStep.LIB)
.resolve(JarResultBuildStep.BOOT_LIB)
.resolve(lib.getFileName());
if (appCDSResult.isPresent()) {
// the boot lib jars need to preserve the modification time because otherwise AppCDS won't work
bootLibsLayerBuilder.addEntry(lib, libPathInContainer,
Files.getLastModifiedTime(lib).toInstant());
} else {
bootLibsLayerBuilder.addEntry(lib, libPathInContainer);
}

// the boot lib jars need to preserve the modification time because otherwise AppCDS won't work
bootLibsLayerBuilder.addEntry(lib, libPathInContainer,
Files.getLastModifiedTime(lib).toInstant());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand All @@ -569,15 +565,15 @@ private JibContainerBuilder createContainerBuilderFromFastJar(String baseJvmImag
.resolve(JarResultBuildStep.DEPLOYMENT_LIB);
addLayer(jibContainerBuilder, Collections.singletonList(deploymentPath),
workDirInContainer.resolve(JarResultBuildStep.LIB),
"fast-jar-deployment-libs", true, modificationTime);
"fast-jar-deployment-libs", true, enforceModificationTime, modificationTime);
}

AbsoluteUnixPath libsMainPath = workDirInContainer.resolve(JarResultBuildStep.LIB)
.resolve(JarResultBuildStep.MAIN);
addLayer(jibContainerBuilder, nonFastChangingLibPaths, libsMainPath, "fast-jar-normal-libs",
isMutableJar, modificationTime);
isMutableJar, enforceModificationTime, modificationTime);
addLayer(jibContainerBuilder, new ArrayList<>(fastChangingLibPaths), libsMainPath, "fast-jar-changing-libs",
isMutableJar, modificationTime);
isMutableJar, enforceModificationTime, modificationTime);
}

if (appCDSResult.isPresent()) {
Expand All @@ -601,9 +597,9 @@ private JibContainerBuilder createContainerBuilderFromFastJar(String baseJvmImag
}

addLayer(jibContainerBuilder, Collections.singletonList(componentsPath.resolve(JarResultBuildStep.APP)),
workDirInContainer, "fast-jar-quarkus-app", isMutableJar, modificationTime);
workDirInContainer, "fast-jar-quarkus-app", isMutableJar, enforceModificationTime, modificationTime);
addLayer(jibContainerBuilder, Collections.singletonList(componentsPath.resolve(JarResultBuildStep.QUARKUS)),
workDirInContainer, "fast-jar-quarkus", isMutableJar, modificationTime);
workDirInContainer, "fast-jar-quarkus", isMutableJar, enforceModificationTime, modificationTime);
if (ContainerImageJibConfig.DEFAULT_WORKING_DIR.equals(jibConfig.workingDirectory)) {
// this layer ensures that the working directory is writeable
// see https://github.com/GoogleContainerTools/jib/issues/1270
Expand Down Expand Up @@ -667,15 +663,25 @@ private boolean containsRunJava(String baseJvmImage) {

public JibContainerBuilder addLayer(JibContainerBuilder jibContainerBuilder, List<Path> files,
AbsoluteUnixPath pathInContainer, String name, boolean isMutableJar,
Instant now)
boolean enforceModificationTime, Instant forcedModificationTime)
throws IOException {
FileEntriesLayer.Builder layerConfigurationBuilder = FileEntriesLayer.builder().setName(name);

for (Path file : files) {
layerConfigurationBuilder.addEntryRecursive(
file, pathInContainer.resolve(file.getFileName()),
isMutableJar ? REMOTE_DEV_FOLDER_PERMISSIONS_PROVIDER : DEFAULT_FILE_PERMISSIONS_PROVIDER,
(sourcePath, destinationPath) -> now,
(sourcePath, destinationPath) -> {
if (enforceModificationTime) {
return forcedModificationTime;
}

try {
return Files.getLastModifiedTime(sourcePath).toInstant();
} catch (IOException e) {
throw new RuntimeException("Unable to get last modified time for " + sourcePath, e);
}
},
isMutableJar ? REMOTE_DEV_OWNERSHIP_PROVIDER : DEFAULT_OWNERSHIP_PROVIDER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationInfoBuildItem;
import io.quarkus.kubernetes.deployment.DeploymentResourceKind;
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 @@ -22,13 +22,13 @@ public void checkOpenshift(ApplicationInfoBuildItem applicationInfo, Capabilitie
DeploymentResourceKind deploymentResourceKind = config.getDeploymentResourceKind(capabilities);
deploymentTargets
.produce(
new KubernetesDeploymentTargetBuildItem(OPENSHIFT, deploymentResourceKind.kind,
deploymentResourceKind.apiGroup,
deploymentResourceKind.apiVersion, true,
new KubernetesDeploymentTargetBuildItem(OPENSHIFT, deploymentResourceKind.getKind(),
deploymentResourceKind.getGroup(),
deploymentResourceKind.getVersion(), true,
config.getDeployStrategy()));

String name = ResourceNameUtil.getResourceName(config, applicationInfo);
resourceMeta.produce(new KubernetesResourceMetadataBuildItem(OPENSHIFT, deploymentResourceKind.apiGroup,
deploymentResourceKind.apiVersion, deploymentResourceKind.kind, name));
resourceMeta.produce(new KubernetesResourceMetadataBuildItem(OPENSHIFT, deploymentResourceKind.getGroup(),
deploymentResourceKind.getVersion(), deploymentResourceKind.getKind(), name));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package io.quarkus.kubernetes.deployment;

import static io.quarkus.kubernetes.deployment.Constants.BATCH_GROUP;
import static io.quarkus.kubernetes.deployment.Constants.BATCH_VERSION;
import static io.quarkus.kubernetes.deployment.Constants.CRONJOB;
import static io.quarkus.kubernetes.deployment.Constants.DEPLOYMENT;
import static io.quarkus.kubernetes.deployment.Constants.DEPLOYMENT_CONFIG;
import static io.quarkus.kubernetes.deployment.Constants.DEPLOYMENT_CONFIG_GROUP;
import static io.quarkus.kubernetes.deployment.Constants.DEPLOYMENT_CONFIG_VERSION;
import static io.quarkus.kubernetes.deployment.Constants.DEPLOYMENT_GROUP;
import static io.quarkus.kubernetes.deployment.Constants.DEPLOYMENT_VERSION;
import static io.quarkus.kubernetes.deployment.Constants.JOB;
import static io.quarkus.kubernetes.deployment.Constants.KNATIVE;
import static io.quarkus.kubernetes.deployment.Constants.KNATIVE_SERVICE;
import static io.quarkus.kubernetes.deployment.Constants.KNATIVE_SERVICE_GROUP;
import static io.quarkus.kubernetes.deployment.Constants.KNATIVE_SERVICE_VERSION;
import static io.quarkus.kubernetes.deployment.Constants.OPENSHIFT;
import static io.quarkus.kubernetes.deployment.Constants.STATEFULSET;

import java.util.Set;

import io.dekorate.utils.Strings;
import io.fabric8.kubernetes.api.model.HasMetadata;

public enum DeploymentResourceKind {

Deployment(DEPLOYMENT, DEPLOYMENT_GROUP, DEPLOYMENT_VERSION),
@Deprecated(since = "OpenShift 4.14")
DeploymentConfig(DEPLOYMENT_CONFIG, DEPLOYMENT_CONFIG_GROUP, DEPLOYMENT_CONFIG_VERSION, OPENSHIFT),
StatefulSet(STATEFULSET, DEPLOYMENT_GROUP, DEPLOYMENT_VERSION),
Job(JOB, BATCH_GROUP, BATCH_VERSION),
CronJob(CRONJOB, BATCH_GROUP, BATCH_VERSION),
KnativeService(KNATIVE_SERVICE, KNATIVE_SERVICE_GROUP, KNATIVE_SERVICE_VERSION, KNATIVE);

private final String kind;
private final String group;
private final String version;
private final Set<String> requiredTargets;

DeploymentResourceKind(String kind, String group, String version, String... requiredTargets) {
this(kind, group, version, Set.of(requiredTargets));
}

DeploymentResourceKind(String kind, String group, String version, Set<String> requiredTargets) {
this.kind = kind;
this.group = group;
this.version = version;
this.requiredTargets = requiredTargets;
}

public static final DeploymentResourceKind find(String apiGroup, String apiVersion, String kind) {
for (DeploymentResourceKind deploymentResourceKind : DeploymentResourceKind.values()) {
if (deploymentResourceKind.kind.equals(kind) && deploymentResourceKind.group.equals(apiGroup)
&& deploymentResourceKind.version.equals(apiVersion)) {
return deploymentResourceKind;
}
}
String apiGroupVersion = Strings.isNullOrEmpty(apiGroup) ? apiVersion : apiGroup + "/" + apiVersion;
throw new IllegalArgumentException("Could not find DeploymentResourceKind for " + apiGroupVersion + " " + kind);
}

public boolean isAvailalbleOn(String target) {
return requiredTargets.isEmpty() || requiredTargets.contains(target);
}

public boolean matches(HasMetadata resource) {
String resourceKind = HasMetadata.getKind(resource.getClass());
String resourceVersion = HasMetadata.getApiVersion(resource.getClass());
return resourceKind.equals(getKind()) && resourceVersion.equals(getApiVersion());
}

public String getKind() {
return kind;
}

public String getGroup() {
return group;
}

public String getVersion() {
return version;
}

public Set<String> getRequiredTargets() {
return requiredTargets;
}

public String getApiVersion() {
return group + "/" + version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

public class DeploymentTargetEntry {
private final String name;
private final String kind;
private final DeploymentResourceKind deploymentResourceKind;
private final int priority;
private final DeployStrategy deployStrategy;

public DeploymentTargetEntry(String name, String kind, int priority, DeployStrategy deployStrategy) {
public DeploymentTargetEntry(String name, DeploymentResourceKind kind, int priority, DeployStrategy deployStrategy) {
this.name = name;
this.kind = kind;
this.deploymentResourceKind = kind;
this.priority = priority;
this.deployStrategy = deployStrategy;
}
Expand All @@ -19,8 +19,8 @@ public String getName() {
return name;
}

public String getKind() {
return kind;
public DeploymentResourceKind getDeploymentResourceKind() {
return deploymentResourceKind;
}

public int getPriority() {
Expand Down
Loading

0 comments on commit f409b01

Please sign in to comment.