forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't generate the init task for db migration if migrate at start is off
The `quarkus.[flyway or liquibase or liquibase-mongodb].enabled` and `quarkus.[flyway or liquibase or liquibase-mongodb].migrate-at-start` properties are runtime properties, so I have to create the following build time properties to read these values and allow users configurating it: - `quarkus.[flyway or liquibase or liquibase-mongodb].generate-init-task` with default value `quarkus.[flyway or liquibase or liquibase-mongodb].enabled` - `quarkus.[flyway or liquibase or liquibase-mongodb].migrate-with-init-task` with default value `quarkus.[flyway or liquibase or liquibase-mongodb].migrate-at-start` Plus, I've extended the coverage of these extensions with the K8s tests. Fix quarkusio#33097
- Loading branch information
Showing
14 changed files
with
577 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...src/test/java/io/quarkus/it/kubernetes/KubernetesWithFlywayInitMigrationDisabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package io.quarkus.it.kubernetes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
import io.fabric8.kubernetes.api.model.batch.v1.Job; | ||
import io.fabric8.kubernetes.api.model.rbac.RoleBinding; | ||
import io.quarkus.bootstrap.model.AppArtifact; | ||
import io.quarkus.builder.Version; | ||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class KubernetesWithFlywayInitMigrationDisabledTest { | ||
|
||
private static final String NAME = "kubernetes-with-flyway-init-migration-disabled"; | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class)) | ||
.setApplicationName(NAME) | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.setLogFileName("k8s.log") | ||
.overrideConfigKey("quarkus.flyway.migrate-at-start", "false") | ||
.setForcedDependencies(Arrays.asList( | ||
new AppArtifact("io.quarkus", "quarkus-kubernetes", Version.getVersion()), | ||
new AppArtifact("io.quarkus", "quarkus-flyway", Version.getVersion()))); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
public void assertGeneratedResources() throws IOException { | ||
final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); | ||
assertThat(kubernetesDir) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml")); | ||
List<HasMetadata> kubernetesList = DeserializationUtil | ||
.deserializeAsList(kubernetesDir.resolve("kubernetes.yml")); | ||
|
||
Optional<Deployment> deployment = kubernetesList.stream() | ||
.filter(d -> "Deployment".equals(d.getKind()) | ||
&& NAME.equals(d.getMetadata().getName())) | ||
.map(d -> (Deployment) d).findAny(); | ||
|
||
assertTrue(deployment.isPresent()); | ||
assertThat(deployment).satisfies(j -> j.isPresent()); | ||
assertThat(deployment.get()).satisfies(d -> { | ||
assertThat(d.getMetadata()).satisfies(m -> { | ||
assertThat(m.getName()).isEqualTo(NAME); | ||
}); | ||
|
||
assertThat(d.getSpec()).satisfies(deploymentSpec -> { | ||
assertThat(deploymentSpec.getTemplate()).satisfies(t -> { | ||
assertThat(t.getSpec()).satisfies(podSpec -> { | ||
assertThat(podSpec.getInitContainers()).noneSatisfy(container -> { | ||
assertThat(container.getName()).isEqualTo("init"); | ||
}); | ||
|
||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
Optional<Job> job = kubernetesList.stream() | ||
.filter(j -> "Job".equals(j.getKind()) && "flyway-init".equals(j.getMetadata().getName())).map(j -> (Job) j) | ||
.findAny(); | ||
assertFalse(job.isPresent()); | ||
|
||
Optional<RoleBinding> roleBinding = kubernetesList.stream().filter( | ||
r -> r instanceof RoleBinding && (NAME + "-view-jobs").equals(r.getMetadata().getName())) | ||
.map(r -> (RoleBinding) r).findFirst(); | ||
assertFalse(roleBinding.isPresent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
.../test/java/io/quarkus/it/kubernetes/KubernetesWithLiquibaseInitMigrationDisabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package io.quarkus.it.kubernetes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
import io.fabric8.kubernetes.api.model.batch.v1.Job; | ||
import io.fabric8.kubernetes.api.model.rbac.RoleBinding; | ||
import io.quarkus.bootstrap.model.AppArtifact; | ||
import io.quarkus.builder.Version; | ||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class KubernetesWithLiquibaseInitMigrationDisabledTest { | ||
|
||
private static final String NAME = "kubernetes-with-liquibase-init-migration-disabled"; | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class)) | ||
.setApplicationName(NAME) | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.setLogFileName("k8s.log") | ||
.overrideConfigKey("quarkus.liquibase.migrate-at-start", "false") | ||
.setForcedDependencies(Arrays.asList( | ||
new AppArtifact("io.quarkus", "quarkus-kubernetes", Version.getVersion()), | ||
new AppArtifact("io.quarkus", "quarkus-liquibase", Version.getVersion()))); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
public void assertGeneratedResources() throws IOException { | ||
final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); | ||
assertThat(kubernetesDir) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml")); | ||
List<HasMetadata> kubernetesList = DeserializationUtil | ||
.deserializeAsList(kubernetesDir.resolve("kubernetes.yml")); | ||
|
||
Optional<Deployment> deployment = kubernetesList.stream() | ||
.filter(d -> "Deployment".equals(d.getKind()) | ||
&& NAME.equals(d.getMetadata().getName())) | ||
.map(d -> (Deployment) d).findAny(); | ||
|
||
assertTrue(deployment.isPresent()); | ||
assertThat(deployment).satisfies(j -> j.isPresent()); | ||
assertThat(deployment.get()).satisfies(d -> { | ||
assertThat(d.getMetadata()).satisfies(m -> { | ||
assertThat(m.getName()).isEqualTo(NAME); | ||
}); | ||
|
||
assertThat(d.getSpec()).satisfies(deploymentSpec -> { | ||
assertThat(deploymentSpec.getTemplate()).satisfies(t -> { | ||
assertThat(t.getSpec()).satisfies(podSpec -> { | ||
assertThat(podSpec.getInitContainers()).noneSatisfy(container -> { | ||
assertThat(container.getName()).isEqualTo("init"); | ||
}); | ||
|
||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
Optional<Job> job = kubernetesList.stream() | ||
.filter(j -> "Job".equals(j.getKind()) && "liquibase-init".equals(j.getMetadata().getName())).map(j -> (Job) j) | ||
.findAny(); | ||
assertFalse(job.isPresent()); | ||
|
||
Optional<RoleBinding> roleBinding = kubernetesList.stream().filter( | ||
r -> r instanceof RoleBinding && (NAME + "-view-jobs").equals(r.getMetadata().getName())) | ||
.map(r -> (RoleBinding) r).findFirst(); | ||
assertFalse(roleBinding.isPresent()); | ||
} | ||
} |
Oops, something went wrong.