Search in sources :

Example 6 with DeploymentStrategy

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);
}
Also used : IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) File(java.io.File) DeploymentStrategy(io.fabric8.kubernetes.api.model.apps.DeploymentStrategy) Test(org.testng.annotations.Test)

Example 7 with DeploymentStrategy

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();
}
Also used : DeploymentConfigSpecBuilder(io.fabric8.openshift.api.model.DeploymentConfigSpecBuilder) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) DeploymentStrategy(io.fabric8.openshift.api.model.DeploymentStrategy)

Aggregations

Container (io.fabric8.kubernetes.api.model.Container)3 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)3 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)3 DeploymentStrategy (io.fabric8.openshift.api.model.DeploymentStrategy)3 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)2 DeploymentStrategy (io.fabric8.kubernetes.api.model.apps.DeploymentStrategy)2 DeploymentConfigBuilder (io.fabric8.openshift.api.model.DeploymentConfigBuilder)2 DeploymentConfigSpecBuilder (io.fabric8.openshift.api.model.DeploymentConfigSpecBuilder)2 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)1 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)1 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 RollingUpdateDeployment (io.fabric8.kubernetes.api.model.apps.RollingUpdateDeployment)1 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)1 DeploymentBuilder (io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)1 ImageName (io.fabric8.maven.docker.util.ImageName)1 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)1 DeploymentConfigFluent (io.fabric8.openshift.api.model.DeploymentConfigFluent)1 DeploymentStrategyBuilder (io.fabric8.openshift.api.model.DeploymentStrategyBuilder)1 DeploymentTriggerPolicy (io.fabric8.openshift.api.model.DeploymentTriggerPolicy)1 DeploymentTriggerPolicyBuilder (io.fabric8.openshift.api.model.DeploymentTriggerPolicyBuilder)1