use of io.fabric8.kubernetes.api.model.apps.DeploymentStrategy in project kubernetes by ballerinax.
the class StrategyTest method rollingUpdateConfigTest.
/**
* Build bal file with deployment annotations having strategy annotations.
*
* @throws IOException Error when loading the generated yaml.
* @throws InterruptedException Error when compiling the ballerina file.
* @throws KubernetesPluginException Error when deleting the generated artifacts folder.
*/
@Test
public void rollingUpdateConfigTest() throws IOException, InterruptedException, KubernetesPluginException, DockerTestException {
Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(BAL_DIRECTORY, "rolling_config.bal"), 0);
// Check if docker image exists and correct
validateDockerfile();
validateDockerImage();
// Validate deployment yaml
File deploymentYAML = KUBERNETES_TARGET_PATH.resolve("rolling_config_deployment.yaml").toFile();
Assert.assertTrue(deploymentYAML.exists());
Deployment deployment = KubernetesTestUtils.loadYaml(deploymentYAML);
final DeploymentStrategy strategy = deployment.getSpec().getStrategy();
Assert.assertEquals(strategy.getType(), "RollingUpdate", "Invalid strategy found.");
Assert.assertNotNull(strategy.getRollingUpdate());
Assert.assertEquals(strategy.getRollingUpdate().getMaxSurge(), new IntOrString("45%"), "Invalid max surge found.");
Assert.assertEquals(strategy.getRollingUpdate().getMaxUnavailable(), new IntOrString(3), "Invalid max unavailable found.");
KubernetesUtils.deleteDirectory(KUBERNETES_TARGET_PATH);
KubernetesUtils.deleteDirectory(DOCKER_TARGET_PATH);
KubernetesTestUtils.deleteDockerImage(DOCKER_IMAGE);
}
use of io.fabric8.kubernetes.api.model.apps.DeploymentStrategy in project fabric8-maven-plugin by fabric8io.
the class DeploymentConfigEnricher method getDeploymentConfigSpec.
private DeploymentConfigSpec getDeploymentConfigSpec(Integer replicas, Integer revisionHistoryLimit, LabelSelector selector, PodTemplateSpec podTemplateSpec, String strategyType) {
DeploymentConfigSpecBuilder specBuilder = new DeploymentConfigSpecBuilder();
if (replicas != null) {
specBuilder.withReplicas(replicas);
}
if (revisionHistoryLimit != null) {
specBuilder.withRevisionHistoryLimit(revisionHistoryLimit);
}
if (selector != null) {
Map<String, String> matchLabels = selector.getMatchLabels();
if (matchLabels != null && !matchLabels.isEmpty()) {
specBuilder.withSelector(matchLabels);
}
}
if (podTemplateSpec != null) {
specBuilder.withTemplate(podTemplateSpec);
PodSpec podSpec = podTemplateSpec.getSpec();
Objects.requireNonNull(podSpec, "No PodSpec for PodTemplate:" + podTemplateSpec);
Objects.requireNonNull(podSpec, "No containers for PodTemplate.spec: " + podTemplateSpec);
}
io.fabric8.openshift.api.model.DeploymentStrategy deploymentStrategy = getDeploymentStrategy(strategyType);
if (deploymentStrategy != null) {
specBuilder.withStrategy(deploymentStrategy);
}
if (enableAutomaticTrigger.equals(Boolean.TRUE)) {
specBuilder.addNewTrigger().withType("ConfigChange").endTrigger();
}
return specBuilder.build();
}
Aggregations