Search in sources :

Example 11 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.apps.DeploymentBuilder in project fabric8-maven-plugin by fabric8io.

the class MergeResourceTest method testMergeDeploymentMetadataWithNoSpec.

@Test
public void testMergeDeploymentMetadataWithNoSpec() throws Exception {
    Deployment resource = new DeploymentBuilder().withNewMetadata().withName("cheese").addToAnnotations("overwriteKey", "originalValue").addToAnnotations("unchangedKey", "shouldNotChange").addToAnnotations("unchangedBlankKey", "").addToAnnotations("deletedKey", "shouldBeDeleted").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withImage("cheese-image").endContainer().endSpec().endTemplate().endSpec().build();
    Deployment override = new DeploymentBuilder().withNewMetadata().withName("cheese").addToAnnotations("overwriteKey", "newValue").addToAnnotations("deletedKey", "").endMetadata().build();
    HasMetadata answer = KubernetesResourceUtil.mergeResources(resource, override, log, false);
    assertNotNull(answer);
    log.info("Override metadata on Deployment with no spec generated: " + KubernetesHelper.toYaml(answer));
    Map<String, String> annotations = answer.getMetadata().getAnnotations();
    assertDataModified(annotations, "Deployment.metadata.annotations");
    assertDataNotModified(resource.getMetadata().getAnnotations(), "Original Deployment.metadata.annotations");
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) Test(org.junit.Test)

Example 12 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.apps.DeploymentBuilder in project fabric8-maven-plugin by fabric8io.

the class MergeResourceTest method testMergeDeploymentMetadataAndEnvVars.

@Test
public void testMergeDeploymentMetadataAndEnvVars() throws Exception {
    Deployment resource = new DeploymentBuilder().withNewMetadata().withName("cheese").addToAnnotations("overwriteKey", "originalValue").addToAnnotations("unchangedKey", "shouldNotChange").addToAnnotations("unchangedBlankKey", "").addToAnnotations("deletedKey", "shouldBeDeleted").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withImage("cheese-image").addToEnv(new EnvVarBuilder().withName("ENV_UPDATED").withValue("OLD_VALUE").build()).addToEnv(new EnvVarBuilder().withName("ENV_UNMODIFIED").withValue("SHOULD_NOT_CHANGE").build()).addToEnv(new EnvVarBuilder().withName("ENV_DELETED").withValue("DELETE_ME").build()).endContainer().endSpec().endTemplate().endSpec().build();
    Deployment override = new DeploymentBuilder().withNewMetadata().withName("cheese").addToAnnotations("overwriteKey", "newValue").addToAnnotations("deletedKey", "").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().addToEnv(new EnvVarBuilder().withName("ENV_UPDATED").withValue("NEW_VALUE").build()).addToEnv(new EnvVarBuilder().withName("ENV_DELETED").withValue("").build()).addToEnv(new EnvVarBuilder().withName("ENV_ADDED").withValue("ADDED_VALUE").build()).endContainer().endSpec().endTemplate().endSpec().build();
    HasMetadata answer = KubernetesResourceUtil.mergeResources(resource, override, log, false);
    assertThat(answer).describedAs("mergeResult").isInstanceOf(Deployment.class);
    Deployment result = (Deployment) answer;
    log.info("Override metadata on Deployment generated: " + KubernetesHelper.toYaml(answer));
    Map<String, String> annotations = answer.getMetadata().getAnnotations();
    assertDataModified(annotations, "Deployment.metadata.annotations");
    assertDataNotModified(resource.getMetadata().getAnnotations(), "Original Deployment.metadata.annotations");
    assertEnvModified(result.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv(), "Deployment.spec.template.spec.containers[0].env");
    assertEnvNotModified(resource.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv(), "Original Deployment.spec.template.spec.containers[0].env");
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) Test(org.junit.Test)

Example 13 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.apps.DeploymentBuilder in project iobserve-analysis by research-iobserve.

the class AllocationExecutor method execute.

@Override
public void execute(final AllocateNodeAction action) {
    final ResourceContainer resourceContainer = action.getTargetResourceContainer();
    final String rcName = this.normalizeComponentName(resourceContainer.getEntityName());
    final Map<String, String> labels = this.computeDeploymentLabels(resourceContainer);
    // Build deployment blueprint
    final Deployment podDeployment = // 
    new DeploymentBuilder().withApiVersion(// 
    AllocationExecutor.API_VERSION).withKind(// 
    "Deployment").withNewMetadata().withLabels(// 
    labels).withName(// 
    rcName).endMetadata().withNewSpec().withReplicas(// 
    1).withNewSelector().addToMatchLabels(AllocationExecutor.COMPONENT_LABEL_KEY, // 
    rcName).endSelector().withNewTemplate().withNewMetadata().addToLabels(AllocationExecutor.COMPONENT_LABEL_KEY, // 
    rcName).withName(// 
    rcName).endMetadata().withNewSpec().withHostname(// 
    rcName).withSubdomain(// 
    this.subdomain).addNewContainer().withImage(// 
    this.imageLocator).withName(// 
    "").withNewResources().endResources().addNewEnv().withName(// 
    "LOGGER").withValue(// 
    "%LOGGER%").endEnv().endContainer().endSpec().endTemplate().endSpec().build();
    this.podsToDeploy.put(rcName, podDeployment);
    if (AllocationExecutor.LOGGER.isDebugEnabled()) {
        AllocationExecutor.LOGGER.debug("Created blueprint for pod deployment " + podDeployment.getMetadata().getName());
    }
}
Also used : Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) ResourceContainer(org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)

Example 14 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.apps.DeploymentBuilder in project fabric8 by fabric8io.

the class YamlSerialiseTest method testSerialiseYaml.

@Test
public void testSerialiseYaml() throws Exception {
    Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("foo").endMetadata().withNewSpec().withReplicas(1).withNewTemplate().withNewSpec().addNewContainer().withImage("cheese").endContainer().endSpec().endTemplate().endSpec().build();
    File outFile = new File(new File(basedir), "target/test-data/deployment.yml");
    outFile.getParentFile().mkdirs();
    KubernetesHelper.saveYamlNotEmpty(deployment, outFile);
    String yaml = IOHelpers.readFully(outFile);
    System.out.println("YAML: " + yaml);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) File(java.io.File) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) Test(org.junit.Test)

Example 15 with DeploymentBuilder

use of io.fabric8.kubernetes.api.model.apps.DeploymentBuilder in project keycloak by keycloak.

the class KeycloakDeployment method getReconciledResource.

@Override
public Optional<HasMetadata> getReconciledResource() {
    // clone not to change the base template
    Deployment baseDeployment = new DeploymentBuilder(this.baseDeployment).build();
    Deployment reconciledDeployment;
    if (existingDeployment == null) {
        Log.info("No existing Deployment found, using the default");
        reconciledDeployment = baseDeployment;
    } else {
        Log.info("Existing Deployment found, updating specs");
        reconciledDeployment = existingDeployment;
        // don't override metadata, just specs
        reconciledDeployment.setSpec(baseDeployment.getSpec());
    }
    return Optional.of(reconciledDeployment);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)

Aggregations

DeploymentBuilder (io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder)13 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)11 Container (io.fabric8.kubernetes.api.model.Container)6 Test (org.junit.Test)5 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)4 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)3 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)2 DeploymentSpec (io.fabric8.kubernetes.api.model.extensions.DeploymentSpec)2 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 TypedVisitor (io.fabric8.kubernetes.api.builder.TypedVisitor)1 ConfigMapVolumeSourceBuilder (io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder)1 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)1