Skip to content

Commit

Permalink
Cover GitOps friendly Kubernetes additions
Browse files Browse the repository at this point in the history
Quarkus 3 allows making K8s manifests more Git-friendly [1]
We cover them with these changes, with a single exception[2]

[1] quarkusio/quarkus#31373
[2] quarkusio/quarkus#34673
  • Loading branch information
fedinskiy committed Jul 13, 2023
1 parent 9aa58fa commit 3c55090
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ secrets.app-prop-sha256-handler=${sha256::0e8c2a8b8ecfbd52c3ef17acd44498ee2b892c
quarkus.kubernetes-client.devservices.enabled=false

quarkus.kubernetes-config.secrets.enabled=true

quarkus.openshift.idempotent=true
# this variable is relative to the "current directory" and not to the project root
# see https://github.com/quarkusio/quarkus/blob/main/docs/src/main/asciidoc/deploying-to-kubernetes.adoc?plain=1#L212
# or https://quarkus.io/guides/deploying-to-kubernetes#generating-idempotent-resources
# quarkus.kubernetes.output-directory=target/openshift todo https://github.com/quarkusio/quarkus/issues/34673
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@
import static io.quarkus.ts.configmap.api.server.OpenShiftBaseConfigIT.applyConfig;
import static java.lang.String.format;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import jakarta.inject.Inject;

Expand Down Expand Up @@ -56,6 +66,32 @@ public void testConfigSourcePriorities() {
assertEquals("side note environment variable", configProperties.sideNote);
}

@Test
void configIsIdempotent() throws IOException {
Predicate<String> containsCommit = line -> line.contains("app.quarkus.io/commit-id");
Predicate<String> containsTimestamp = line -> line.contains("app.quarkus.io/build-timestamp");

// todo change to custom path when https://github.com/quarkusio/quarkus/issues/34673 will be fixed
Path folder = app.getServiceFolder().resolve("target/kubernetes").toAbsolutePath();
assertTrue(Files.exists(folder), "Folder " + folder + " should exist!");

List<String> openshift = Files.readAllLines(folder.resolve("openshift.yml"));
assertNotEquals(0, openshift.size(), "File openshift.yml should exist and have content!");

// we do not use idempotent mode for kubernetes, so it should stay as before
List<String> kubernetes = Files.readAllLines(folder.resolve("kubernetes.yml"));
assertNotEquals(0, kubernetes.size(), "File kubernetes.yml should exist and have content!");
assertTrue(kubernetes.stream().anyMatch(containsTimestamp), "File kubernetes.yml should contain timestamps!");
assertTrue(kubernetes.stream().anyMatch(containsCommit), "File kubernetes.yml should contain commit ids!");

// openshift uses idempotent mode
List<String> offendingLines = openshift.stream()
.filter(containsTimestamp.or(containsCommit))
.collect(Collectors.toList());
assertEquals(Collections.emptyList(), offendingLines, "Non-idempotent lines found!");

}

private static void loadConfigSource(Service service) {
// create Secrets and ConfigMaps
applyConfig(CONFIGMAP_YAML, openShiftClient);
Expand Down

0 comments on commit 3c55090

Please sign in to comment.