@Override public boolean reap() { oper.scale(0, true); return false; } }
@Override public Job reload(OkHttpClient client, Config config, String namespace, Job item) { return new JobOperationsImpl(client, config, null, namespace, null, true, item, null, false, -1, new TreeMap<String, String>(), new TreeMap<String, String>(), new TreeMap<String, String[]>(), new TreeMap<String, String[]>(), new TreeMap<String, String>()).fromServer().get(); }
protected void doDeleteDeployment(Exchange exchange, String operation) { String deploymentName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_DEPLOYMENT_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (ObjectHelper.isEmpty(deploymentName)) { LOG.error("Delete a specific deployment require specify a deployment name"); throw new IllegalArgumentException("Delete a specific deployment require specify a deployment name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Delete a specific deployment require specify a namespace name"); throw new IllegalArgumentException("Delete a specific deployment require specify a namespace name"); } Boolean deployment = getEndpoint().getKubernetesClient().apps().deployments().inNamespace(namespaceName).withName(deploymentName).delete(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(deployment); }
@Override public void apply(KubernetesList resources, boolean patchPersistentVolumeClaims) { for (HasMetadata resource : resources.getItems()) { try { if (resource instanceof ConfigMap) { client.configMaps().withName(resource.getMetadata().getName()).patch((ConfigMap) resource); } else if (resource instanceof Secret) { client.secrets().withName(resource.getMetadata().getName()).patch((Secret) resource); } else if (resource instanceof Deployment) { client.apps().deployments().withName(resource.getMetadata().getName()).patch((Deployment) resource); } else if (resource instanceof StatefulSet) { client.apps().statefulSets().withName(resource.getMetadata().getName()).cascading(false).patch((StatefulSet) resource); } else if (resource instanceof Service) { client.services().withName(resource.getMetadata().getName()).patch((Service) resource); } else if (resource instanceof ServiceAccount) { client.serviceAccounts().withName(resource.getMetadata().getName()).patch((ServiceAccount) resource); } else if (resource instanceof PersistentVolumeClaim && patchPersistentVolumeClaims) { client.persistentVolumeClaims().withName(resource.getMetadata().getName()).patch((PersistentVolumeClaim) resource); } } catch (KubernetesClientException e) { if (e.getCode() == 404) { // Create it if it does not exist client.resource(resource).createOrReplace(); } else { throw e; } } } }
if (spec != null) { if (enableDebugging(entity, spec.getTemplate())) { kubernetes.extensions().deployments().inNamespace(namespace).withName(name).replace(resource);
@Override Deployment applyResource(Deployment original, Deployment current) { return client .extensions() .deployments() .inNamespace(getNamespace()) .withName(current.getMetadata().getName()) .edit() .withMetadata(current.getMetadata()) .withSpec(current.getSpec()) .done(); }
protected void doGetDeployment(Exchange exchange, String operation) throws Exception { Deployment deployment = null; String deploymentName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_DEPLOYMENT_NAME, String.class); if (ObjectHelper.isEmpty(deploymentName)) { LOG.error("Get a specific Deployment require specify a Deployment name"); throw new IllegalArgumentException("Get a specific Deployment require specify a Deployment name"); } deployment = getEndpoint().getKubernetesClient().apps().deployments().withName(deploymentName).get(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(deployment); }
protected void doDeleteJob(Exchange exchange, String operation) throws Exception { String jobName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_JOB_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (ObjectHelper.isEmpty(jobName)) { LOG.error("Delete a specific job require specify a job name"); throw new IllegalArgumentException("Delete a specific job require specify a job name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Delete a specific job require specify a namespace name"); throw new IllegalArgumentException("Delete a specific job require specify a namespace name"); } getEndpoint().getKubernetesClient().batch().jobs().inNamespace(namespaceName).withName(jobName).delete(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); } }
client.secrets().withName(resource.getMetadata().getName()).patch((Secret) resource); } else if (resource instanceof Deployment) { client.apps().deployments().withName(resource.getMetadata().getName()).patch((Deployment) resource); } else if (resource instanceof StatefulSet) { client.apps().statefulSets().withName(resource.getMetadata().getName()).cascading(false).patch((StatefulSet) resource);
if (spec != null) { if (updateImageName(entity, spec.getTemplate(), imagePrefix, imageName)) { kubernetes.extensions().deployments().inNamespace(namespace).withName(name).replace(resource);
@Override Job applyResource(Job original, Job current) { return client .extensions() .jobs() .inNamespace(getNamespace()) .withName(current.getMetadata().getName()) .edit() .withMetadata(current.getMetadata()) .withSpec(current.getSpec()) .done(); }
protected void doScaleDeployment(Exchange exchange, String operation) throws Exception { String deploymentName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_DEPLOYMENT_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); Integer replicasNumber = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_DEPLOYMENT_REPLICAS, Integer.class); if (ObjectHelper.isEmpty(deploymentName)) { LOG.error("Scale a specific deployment require specify a deployment name"); throw new IllegalArgumentException("Scale a specific deployment require specify a deployment name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Scale a specific deployment require specify a namespace name"); throw new IllegalArgumentException("Scale a specific deployment require specify a namespace name"); } if (ObjectHelper.isEmpty(replicasNumber)) { LOG.error("Scale a specific deployment require specify a replicas number"); throw new IllegalArgumentException("Scale a specific deployment require specify a replicas number"); } Deployment deploymentScaled = getEndpoint().getKubernetesClient().apps().deployments().inNamespace(namespaceName).withName(deploymentName).scale(replicasNumber, false); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(deploymentScaled.getStatus().getReplicas()); } }
protected void doGetJob(Exchange exchange, String operation) throws Exception { Job job = null; String jobName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_JOB_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (ObjectHelper.isEmpty(jobName)) { LOG.error("Get a specific job require specify a job name"); throw new IllegalArgumentException("Get a specific job require specify a job name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Get a specific job require specify a namespace name"); throw new IllegalArgumentException("Get a specific job require specify a namespace name"); } job = getEndpoint().getKubernetesClient().batch().jobs().inNamespace(namespaceName).withName(jobName).get(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(job); }
/*** * Deletes deployment by name * @param namespace * @param appName */ public void deleteDeployment(String namespace, String appName) { client.apps().deployments().inNamespace(namespace).withName(appName).delete(); log.info("Deployment {} removed", appName); }
client.apps().deployments().inNamespace("thisisatest").withName("nginx").scale(2, true); log("Created replica sets:", client.apps().replicaSets().inNamespace("thisisatest").list().getItems()); System.err.println("Deleting:" + deployment.getMetadata().getName());
@Override Job getCurrentResource() { return client .extensions() .jobs() .inNamespace(getNamespace()) .withName(getName()) .get(); }
public void setDeploymentReplicas(String name, int numReplicas) { client.apps().deployments().inNamespace(globalNamespace).withName(name).scale(numReplicas, true); }
@Override Deployment getCurrentResource() { return client .extensions() .deployments() .inNamespace(getNamespace()) .withName(getName()) .get(); }
if (currentScale != null && currentScale < scaleTo) { log.info("Scaling up to {} replicas", scaleTo); resource(namespace, name).scale(scaleTo, true); currentScale = scaleTo;
if (resource instanceof Deployment) { if (client.extensions().deployments().inNamespace(namespace).withName(deploymentName).get() == null) { log.debug("Deploying in CMS type: {} and the Deployment resource definition: {} ", cmsType, deploymentTemplate);