@Test public void testCreateDeployment_WithNullDeployment_ThrowsVmidcException() throws Exception { this.exception.expect(IllegalArgumentException.class); this.deploymentApi.createDeployment(null); }
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; }