@Test public void testCreateDeployment_WithValidDeployment_DeploymentCreated() throws Exception { KubernetesDeployment deployment = new KubernetesDeployment("name", "namespace", "uid", 2, "imageName", null); String deploymentUid = UUID.randomUUID().toString(); Deployment createdDeployment = new Deployment(); ObjectMeta metadata = new ObjectMeta(); metadata.setUid(deploymentUid); createdDeployment.setMetadata(metadata); when( this.extensionsApiMock .deployments() .inNamespace(deployment.getNamespace())) .thenReturn(this.nonNamespaceOperationMock); when( this.nonNamespaceOperationMock .create(Mockito.argThat( new DeploymentMatcher( deployment.getName(), deployment.getDesiredReplicaCount(), deployment.getContainerImageName())))) .thenReturn(createdDeployment); String uid = this.deploymentApi.createDeployment(deployment); assertEquals("The returned uid was different than expected.", deploymentUid, uid); }
public String createDeployment(KubernetesDeployment deployment) throws VmidcException { if (deployment == null) { throw new IllegalArgumentException("The deployment should not be null"); } try { Deployment newDeployment = new DeploymentBuilder() .withKind("Deployment") .withNewMetadata() .withName(deployment.getName()) .endMetadata() .withNewSpec() .withReplicas(deployment.getDesiredReplicaCount()) .withNewTemplate() .withNewMetadata() .addToLabels(OSC_DEPLOYMENT_LABEL_NAME, deployment.getName()) .endMetadata() .withNewSpec() .addNewContainer() .withName(deployment.getName()).withImage(deployment.getContainerImageName()) .endContainer() .endSpec() .endTemplate() .endSpec() .build(); Deployment result = getKubernetesClient().extensions().deployments().inNamespace(deployment.getNamespace()).create(newDeployment); return result.getMetadata().getUid(); } catch (KubernetesClientException e) { throw new VmidcException(String.format("Failed to create a deployment %s", e)); } }
KubernetesDeploymentApi extends KubernetesApi { public String createDeployment(KubernetesDeployment deployment) throws VmidcException { if (deployment == null) { throw new IllegalArgumentException("The deployment should not be null"); } try { Deployment newDeployment = new DeploymentBuilder() .withKind("Deployment") .withNewMetadata() .withName(deployment.getName()) .endMetadata() .withNewSpec() .withReplicas(deployment.getDesiredReplicaCount()) .withNewTemplate() .withNewMetadata() .addToLabels(OSC_DEPLOYMENT_LABEL_NAME, deployment.getName()) .endMetadata() .withNewSpec() .addNewContainer() .withName(deployment.getName()).withImage(deployment.getContainerImageName()) .endContainer() .endSpec() .endTemplate() .endSpec() .build(); Deployment result = getKubernetesClient().extensions().deployments().inNamespace(deployment.getNamespace()).create(newDeployment); return result.getMetadata().getUid(); } catch (KubernetesClientException e) { throw new VmidcException(String.format("Failed to create a deployment %s", e)); } } }
KubernetesDeploymentApi extends KubernetesApi { public String createDeployment(KubernetesDeployment deployment) throws VmidcException { if (deployment == null) { throw new IllegalArgumentException("The deployment should not be null"); } try { Deployment newDeployment = new DeploymentBuilder() .withKind("Deployment") .withNewMetadata() .withName(deployment.getName()) .endMetadata() .withNewSpec() .withReplicas(deployment.getDesiredReplicaCount()) .withNewTemplate() .withNewMetadata() .addToLabels(OSC_DEPLOYMENT_LABEL_NAME, deployment.getName()) .endMetadata() .withNewSpec() .addNewContainer() .withName(deployment.getName()).withImage(deployment.getContainerImageName()) .endContainer() .endSpec() .endTemplate() .endSpec() .build(); Deployment result = getKubernetesClient().extensions().deployments().inNamespace(deployment.getNamespace()).create(newDeployment); return result.getMetadata().getUid(); } catch (KubernetesClientException e) { throw new VmidcException(String.format("Failed to create a deployment %s", e)); } } KubernetesDeploymentApi(KubernetesClient client); }
KubernetesDeploymentApi extends KubernetesApi { public String createDeployment(KubernetesDeployment deployment) throws VmidcException { if (deployment == null) { throw new IllegalArgumentException("The deployment should not be null"); } try { Deployment newDeployment = new DeploymentBuilder() .withKind("Deployment") .withNewMetadata() .withName(deployment.getName()) .endMetadata() .withNewSpec() .withReplicas(deployment.getDesiredReplicaCount()) .withNewTemplate() .withNewMetadata() .addToLabels(OSC_DEPLOYMENT_LABEL_NAME, deployment.getName()) .endMetadata() .withNewSpec() .addNewContainer() .withName(deployment.getName()).withImage(deployment.getContainerImageName()) .endContainer() .endSpec() .endTemplate() .endSpec() .build(); Deployment result = getKubernetesClient().extensions().deployments().inNamespace(deployment.getNamespace()).create(newDeployment); return result.getMetadata().getUid(); } catch (KubernetesClientException e) { throw new VmidcException(String.format("Failed to create a deployment %s", e)); } } KubernetesDeploymentApi(KubernetesClient client); KubernetesDeployment getDeploymentById(String uid, String namespace, String name); void deleteDeployment(String uid, String namespace, String name); void updateDeploymentReplicaCount(String uid, String namespace, String name, int replicaCount); String createDeployment(KubernetesDeployment deployment); }
KubernetesDeploymentApi extends KubernetesApi { public String createDeployment(KubernetesDeployment deployment) throws VmidcException { if (deployment == null) { throw new IllegalArgumentException("The deployment should not be null"); } try { Deployment newDeployment = new DeploymentBuilder() .withKind("Deployment") .withNewMetadata() .withName(deployment.getName()) .endMetadata() .withNewSpec() .withReplicas(deployment.getDesiredReplicaCount()) .withNewTemplate() .withNewMetadata() .addToLabels(OSC_DEPLOYMENT_LABEL_NAME, deployment.getName()) .endMetadata() .withNewSpec() .addNewContainer() .withName(deployment.getName()).withImage(deployment.getContainerImageName()) .endContainer() .endSpec() .endTemplate() .endSpec() .build(); Deployment result = getKubernetesClient().extensions().deployments().inNamespace(deployment.getNamespace()).create(newDeployment); return result.getMetadata().getUid(); } catch (KubernetesClientException e) { throw new VmidcException(String.format("Failed to create a deployment %s", e)); } } KubernetesDeploymentApi(KubernetesClient client); KubernetesDeployment getDeploymentById(String uid, String namespace, String name); void deleteDeployment(String uid, String namespace, String name); void updateDeploymentReplicaCount(String uid, String namespace, String name, int replicaCount); String createDeployment(KubernetesDeployment deployment); final static String OSC_DEPLOYMENT_LABEL_NAME; }