protected void doCreateDeployment(Exchange exchange, String operation) throws Exception { Deployment deployment = null; String deploymentName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_DEPLOYMENT_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); DeploymentSpec deSpec = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_DEPLOYMENT_SPEC, DeploymentSpec.class); if (ObjectHelper.isEmpty(deploymentName)) { LOG.error("Create a specific Deployment require specify a Deployment name"); throw new IllegalArgumentException("Create a specific Deployment require specify a pod name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Create a specific Deployment require specify a namespace name"); throw new IllegalArgumentException("Create a specific Deployment require specify a namespace name"); } if (ObjectHelper.isEmpty(deSpec)) { LOG.error("Create a specific Deployment require specify a Deployment spec bean"); throw new IllegalArgumentException("Create a specific Deployment require specify a Deployment spec bean"); } Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_DEPLOYMENTS_LABELS, Map.class); Deployment deploymentCreating = new DeploymentBuilder().withNewMetadata().withName(deploymentName).withLabels(labels).endMetadata().withSpec(deSpec).build(); deployment = getEndpoint().getKubernetesClient().apps().deployments().inNamespace(namespaceName).create(deploymentCreating); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(deployment); }
private static Deployment getMessagingClientDeploymentResource() { return new DeploymentBuilder() .withNewMetadata() .withName(SystemtestsOpenshiftApp.MESSAGING_CLIENTS.toString()) .endMetadata() .withNewSpec() .withNewSelector()
.withName(name) .withLabels(getLabelsWithName(templateDeploymentLabels)) .withNamespace(namespace) .withAnnotations(mergeAnnotations(deploymentAnnotations, templateDeploymentAnnotations)) .withOwnerReferences(createOwnerReference()) .endMetadata() .withNewSpec() .withStrategy(updateStrategy)
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 protected Deployment resource() { return new DeploymentBuilder().withNewMetadata().withNamespace(NAMESPACE).withName(RESOURCE_NAME).endMetadata().build(); }
@Override protected ObjectMeta getOrCreateMetadata(DeploymentBuilder item) { return item.hasMetadata() ? item.buildMetadata() : item.withNewMetadata().endMetadata().buildMetadata(); } }
@Override public void visit(DeploymentBuilder resource) { DeploymentFluent.MetadataNested<DeploymentBuilder> metadata = resource.editMetadata(); if (metadata == null) { resource.withNewMetadata().withName(defaultName).endMetadata(); } else { if (StringUtils.isBlank(metadata.getName())) { metadata.withName(defaultName).endMetadata(); } } } });
Deployment deployment = new DeploymentBuilder() .withNewMetadata() .withName("nginx") .endMetadata() .withNewSpec() .withReplicas(1)