-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41808 from iocanel/kubernetes-output-directory
Introduce build item to control kubernetes output dir
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...netes/spi/src/main/java/io/quarkus/kubernetes/spi/CustomKubernetesOutputDirBuildItem.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,23 @@ | ||
package io.quarkus.kubernetes.spi; | ||
|
||
import java.nio.file.Path; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* Build item that allows us to supply a custom output dir instead of defaulting to {project.target.dir}/kubernetes | ||
* It's different from the {@link KubernetesOutputDirBuildItem} as it's used to communicate the intention to override the dir | ||
* while {@link KubernetesOutputDirBuildItem} is used to communicate the effective output dir. | ||
*/ | ||
public final class CustomKubernetesOutputDirBuildItem extends SimpleBuildItem { | ||
|
||
private final Path outputDir; | ||
|
||
public CustomKubernetesOutputDirBuildItem(Path outputDir) { | ||
this.outputDir = outputDir; | ||
} | ||
|
||
public Path getOutputDir() { | ||
return outputDir; | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
...tandard-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithCustomOutputDirTest.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,72 @@ | ||
package io.quarkus.it.kubernetes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
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.quarkus.builder.BuildContext; | ||
import io.quarkus.kubernetes.spi.CustomKubernetesOutputDirBuildItem; | ||
import io.quarkus.kubernetes.spi.CustomProjectRootBuildItem; | ||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestBuildStep; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class KubernetesWithCustomOutputDirTest { | ||
|
||
private static final String APP_NAME = "kubernetes-with-custom-output-dir"; | ||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) | ||
.setApplicationName(APP_NAME) | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.addBuildChainCustomizerEntries( | ||
new QuarkusProdModeTest.BuildChainCustomizerEntry(CustomProjectRootBuildItemProducerProdMode.class, | ||
List.of(CustomProjectRootBuildItem.class, CustomKubernetesOutputDirBuildItem.class), | ||
Collections.emptyList())); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
public void assertGeneratedResources() throws IOException { | ||
final Path kubernetesDir = prodModeTestResults.getBuildDir().getParent().resolve("custom-sources") | ||
.resolve(".kubernetes"); | ||
assertThat(kubernetesDir) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml")) | ||
.satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2)); | ||
List<HasMetadata> kubernetesList = DeserializationUtil.deserializeAsList(kubernetesDir.resolve("kubernetes.yml")); | ||
assertThat(kubernetesList).filteredOn(h -> h.getMetadata().getName().equals(APP_NAME)) | ||
.filteredOn(e -> e instanceof Deployment).singleElement().satisfies(d -> { | ||
assertThat(d.getMetadata()).satisfies(m -> { | ||
assertThat(m.getName()).isEqualTo(APP_NAME); | ||
}); | ||
}); | ||
} | ||
|
||
public static class CustomProjectRootBuildItemProducerProdMode extends ProdModeTestBuildStep { | ||
|
||
public CustomProjectRootBuildItemProducerProdMode(Map<String, Object> testContext) { | ||
super(testContext); | ||
} | ||
|
||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(new CustomProjectRootBuildItem( | ||
(Path) getTestContext().get(QuarkusProdModeTest.BUILD_CONTEXT_CUSTOM_SOURCES_PATH_KEY))); | ||
context.produce(new CustomKubernetesOutputDirBuildItem( | ||
((Path) getTestContext().get(QuarkusProdModeTest.BUILD_CONTEXT_CUSTOM_SOURCES_PATH_KEY)) | ||
.resolve(".kubernetes"))); | ||
} | ||
} | ||
} |