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");
}
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");
}
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());
}
}
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);
}
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);
}
Aggregations