.addToMatchLabels("app", "nginx") .endSelector() .endSpec() .build();
.endSpec() .endTemplate() .endSpec() .build();
.endSpec() .endTemplate() .endSpec() .build();
private Deployment createDeployment(String appId, AppDeploymentRequest request, Map<String, String> idMap, int externalPort) { int replicas = getCountFromRequest(request); Map<String, String> annotations = getPodAnnotations(request); Map<String, String> deploymentLabels = getDeploymentLabels(request); PodSpec podSpec = createPodSpec(appId, request, externalPort, false); Deployment d = new DeploymentBuilder().withNewMetadata().withName(appId).withLabels(idMap) .addToLabels(SPRING_MARKER_KEY, SPRING_MARKER_VALUE).addToLabels(deploymentLabels).endMetadata() .withNewSpec().withNewSelector().addToMatchLabels(idMap).endSelector().withReplicas(replicas) .withNewTemplate().withNewMetadata().withLabels(idMap).addToLabels(SPRING_MARKER_KEY, SPRING_MARKER_VALUE) .addToLabels(deploymentLabels).withAnnotations(annotations).endMetadata().withSpec(podSpec).endTemplate() .endSpec().build(); return client.apps().deployments().create(d); }
@Override public void visit(DeploymentBuilder deploymentBuilder) { deploymentBuilder.editOrNewSpec().editOrNewTemplate().editOrNewSpec().endSpec().endTemplate().endSpec(); mergeDeploymentSpec(deploymentBuilder, spec); } });
@Override public void visit(DeploymentBuilder item) { item.editOrNewSpec() .withRevisionHistoryLimit(maxRevisionHistories) .endSpec(); } });
private void mergeDeploymentSpec(DeploymentBuilder builder, DeploymentSpec spec) { DeploymentFluent.SpecNested<DeploymentBuilder> specBuilder = builder.editSpec(); KubernetesResourceUtil.mergeSimpleFields(specBuilder, spec); specBuilder.endSpec(); }
@Override public void visit(DeploymentBuilder item) { DeploymentFluent.SpecNested<DeploymentBuilder> spec = item.getSpec() == null ? item.withNewSpec() : item.editSpec(); DeploymentSpecFluent.TemplateNested<DeploymentFluent.SpecNested<DeploymentBuilder>> template = spec.getTemplate() == null ? spec.withNewTemplate() : spec.editTemplate(); template.endTemplate().endSpec(); } });
@Override public boolean reap() { Deployment deployment = oper.cascading(false).edit().editSpec().withReplicas(0).endSpec().done(); //TODO: These checks shouldn't be used as they are not realistic. We just use them to support mock/crud tests. Need to find a cleaner way to do so. if (deployment.getStatus() != null) { waitForObservedGeneration(deployment.getStatus().getObservedGeneration()); } if (deployment.getSpec().getSelector() != null) { reapMatchingReplicaSets(deployment.getSpec().getSelector()); } return false; }
@Override public Deployment scale(int count, boolean wait) { Deployment res = cascading(false).edit().editSpec().withReplicas(count).endSpec().done(); if (wait) { waitUntilDeploymentIsScaled(count); res = getMandatory(); } return res; }