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.
Support Kubernetes RollingUpdate configuration
Fix quarkusio#34047
- Loading branch information
Showing
5 changed files
with
110 additions
and
0 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
19 changes: 19 additions & 0 deletions
19
...anilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/RollingUpdateConfig.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,19 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class RollingUpdateConfig { | ||
/** | ||
* Specifies the maximum number of Pods that can be unavailable during the update process. | ||
*/ | ||
@ConfigItem(defaultValue = "25%") | ||
String maxUnavailable; | ||
|
||
/** | ||
* Specifies the maximum number of Pods that can be created over the desired number of Pods. | ||
*/ | ||
@ConfigItem(defaultValue = "25%") | ||
String maxSurge; | ||
} |
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
63 changes: 63 additions & 0 deletions
63
...d-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithStrategyRollingUpdateTest.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,63 @@ | ||
|
||
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.List; | ||
|
||
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.Version; | ||
import io.quarkus.maven.dependency.Dependency; | ||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class KubernetesWithStrategyRollingUpdateTest { | ||
|
||
private static final String APP_NAME = "kubernetes-with-strategy-rolling-update"; | ||
private static final String STRATEGY_TYPE = "RollingUpdate"; | ||
private static final String MAX_UNAVAILABLE = "35%"; | ||
private static final String MAX_SURGE = "39%"; | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) | ||
.setApplicationName(APP_NAME) | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.overrideConfigKey("quarkus.kubernetes.strategy", STRATEGY_TYPE) | ||
.overrideConfigKey("quarkus.kubernetes.rolling-update.max-unavailable", MAX_UNAVAILABLE) | ||
.overrideConfigKey("quarkus.kubernetes.rolling-update.max-surge", MAX_SURGE) | ||
.setForcedDependencies(List.of(Dependency.of("io.quarkus", "quarkus-kubernetes", 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")); | ||
|
||
assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> { | ||
assertThat(d.getMetadata()).satisfies(m -> { | ||
assertThat(m.getName()).isEqualTo(APP_NAME); | ||
}); | ||
|
||
assertThat(d.getSpec()).satisfies(spec -> { | ||
assertThat(spec.getStrategy().getType()).isEqualTo(STRATEGY_TYPE); | ||
assertThat(spec.getStrategy().getRollingUpdate()).isNotNull(); | ||
assertThat(spec.getStrategy().getRollingUpdate().getMaxUnavailable().getStrVal()).isEqualTo(MAX_UNAVAILABLE); | ||
assertThat(spec.getStrategy().getRollingUpdate().getMaxSurge().getStrVal()).isEqualTo(MAX_SURGE); | ||
}); | ||
}); | ||
} | ||
} |