public static void main(String[] args) { try { OpenShiftClient client = new DefaultOpenShiftClient(); if (!client.supportsOpenShiftAPIGroup(OpenShiftAPIGroups.APPS)) { System.out.println("WARNING this cluster does not support the API Group " + OpenShiftAPIGroups.APPS); return; } DeploymentConfigList list = client.deploymentConfigs().list(); if (list == null) { System.out.println("ERROR no list returned!"); return; } List<DeploymentConfig> items = list.getItems(); for (DeploymentConfig item : items) { System.out.println("DeploymentConfig " + item.getMetadata().getName() + " has version: " + item.getApiVersion()); } if (items.size() > 0) { // lets check .get() too DeploymentConfig deploymentConfig = items.get(0); String name = deploymentConfig.getMetadata().getName(); deploymentConfig = client.deploymentConfigs().withName(name).get(); assertNotNull("No DeploymentConfig found for name " + name, deploymentConfig); System.out.println("get() DeploymentConfig " + name + " has version: " + deploymentConfig.getApiVersion()); } } catch (KubernetesClientException e) { System.out.println("Failed: " + e); e.printStackTrace(); } }
return; DeployableScalableResource<DeploymentConfig, DoneableDeploymentConfig> resource = client.deploymentConfigs().withName(name); DeploymentConfig deploymentConfig = resource.get(); if (deploymentConfig == null) { DeploymentConfigList list = client.deploymentConfigs().list(); assertNotNull("No DeploymentConfigList returned", list); List<DeploymentConfig> items = list.getItems();
@Override protected MixedOperation<DeploymentConfig, DeploymentConfigList, DoneableDeploymentConfig, DeployableScalableResource<DeploymentConfig, DoneableDeploymentConfig>> operation() { return client.deploymentConfigs(); }
@Override protected void mocker(OpenShiftClient mockClient, MixedOperation op) { /*ExtensionsAPIGroupDSL mockExt = mock(ExtensionsAPIGroupDSL.class); when(mockExt.deployments()).thenReturn(op); when(mockClient.extensions()).thenReturn(mockExt);*/ when(mockClient.deploymentConfigs()).thenReturn(op); }
log("Created deployment", client.deploymentConfigs().inNamespace("thisisatest").createOrReplaceWithNew() .withNewMetadata() .withName("nginx") client.deploymentConfigs().inNamespace("thisisatest").withName("nginx").scale(2, true); log("Created pods:", client.pods().inNamespace("thisisatest").list().getItems()); client.deploymentConfigs().inNamespace("thisisatest").withName("nginx").delete(); log("Pods:", client.pods().inNamespace("thisisatest").list().getItems()); log("Replication Controllers:", client.replicationControllers().inNamespace("thisisatest").list().getItems());
@Override public Boolean call() { return client.deploymentConfigs().inNamespace(namespace).withName(deployment).get() == null; }
@Override public Boolean call() { DeploymentConfig dc = client.deploymentConfigs().inNamespace(namespace).withName(deploymentName).get(); DeploymentConfigStatus status = (dc == null) ? null : dc.getStatus(); Integer replicas = (status == null) ? null : status.getAvailableReplicas(); return replicas != null && replicas.intValue() == replicas; }
private DeployableScalableResource<DeploymentConfig, DoneableDeploymentConfig> getDeploymentConfigResource(Service service) { if (service != null) { String prjName = service.getMetadata().getNamespace(); Map<String, String> selector = service.getSpec().getSelector(); String dcName = selector.get("deploymentconfig"); if (dcName == null) { dcName = selector.get("deploymentConfig"); } if (dcName != null) { return delegate.deploymentConfigs().inNamespace(prjName).withName(dcName); } } return null; }
@Override public String getFailureMessage() { DeploymentConfig dc = client.deploymentConfigs().inNamespace(namespace).withName(deploymentName).get(); DeploymentConfigStatus status = (dc == null) ? null : dc.getStatus(); return "Namespace=" + namespace + "; deploymentName= " + deploymentName + "; Deployment=" + dc + "; status=" + status; } };
@Override protected void undeploy(final String namespace, final String deployment, final String pod) { client.deploymentConfigs().inNamespace(namespace).withName(deployment).delete(); ExitCondition exitCondition = new ExitCondition() { @Override public Boolean call() { return client.deploymentConfigs().inNamespace(namespace).withName(deployment).get() == null; } @Override public String getFailureMessage() { return "No deployment with namespace=" + namespace + ", deployment=" + deployment; } }; waitForExitCondition(exitCondition); }
@Override protected boolean isNamespaceEmpty(String namespace) { return client.deploymentConfigs().inNamespace(namespace).list().getItems().isEmpty() && client.services().inNamespace(namespace).list().getItems().isEmpty() && client.secrets().inNamespace(namespace).list().getItems().isEmpty(); }
if (openShiftClient != null) { try { openShiftClient.deploymentConfigs().inNamespace(sessionNamespace).delete(); } catch (KubernetesClientException e) { errors.add(e);
@Override protected boolean handleResourceDelete(String resourceType, String resourceName, String namespace) { if (super.handleResourceDelete(resourceType, resourceName, namespace)) { return true; } try { switch (resourceType) { case OpenShiftResource.DEPLOYMENT_CONFIG: return client.deploymentConfigs().inNamespace(namespace).withName(resourceName).delete(); case OpenShiftResource.PROJECT: return client.projects().withName(resourceName).delete(); case OpenShiftResource.TEMPLATE: return client.templates().inNamespace(namespace).withName(resourceName).delete(); case OpenShiftResource.BUILD_CONFIG: return client.buildConfigs().inNamespace(namespace).withName(resourceName).delete(); } } catch (KubernetesClientException kce) { LOG.warn("Error deleting resource {}: {}", resourceName, kce); } return false; }
addClient(client.adapt(OpenShiftClient.class).deploymentConfigs().watch(new WatcherSupport<DeploymentConfig>() { @Override public void eventReceived(Action action, DeploymentConfig deploymentConfig) {
continue; openshiftClient.deploymentConfigs().inNamespace(namespace).withName(name).replace(resource);
public static void resizeApp(KubernetesClient kubernetes, String namespace, Set<HasMetadata> entities, int replicas, Logger log) { for (HasMetadata entity : entities) { String name = KubernetesHelper.getName(entity); Scaleable<?> scalable = null; if (entity instanceof Deployment) { scalable = kubernetes.extensions().deployments().inNamespace(namespace).withName(name); } else if (entity instanceof ReplicaSet) { scalable = kubernetes.extensions().replicaSets().inNamespace(namespace).withName(name); } else if (entity instanceof ReplicationController) { scalable = kubernetes.replicationControllers().inNamespace(namespace).withName(name); } else if (entity instanceof DeploymentConfig) { OpenShiftClient openshiftClient = OpenshiftHelper.asOpenShiftClient(kubernetes); if (openshiftClient == null) { log.warn("Ignoring DeploymentConfig %s as not connected to an OpenShift cluster", name); continue; } scalable = openshiftClient.deploymentConfigs().inNamespace(namespace).withName(name); } if (scalable != null) { log.info("Scaling " + KubernetesHelper.getKind(entity) + " " + namespace + "/" + name + " to replicas: " + replicas); scalable.scale(replicas, true); } } }
.endSpec() .build(); client.deploymentConfigs().inNamespace(namespace).create(deployment); ExitCondition exitCondition = new ExitCondition() { @Override
delegate.deploymentConfigs().inNamespace(prjName).withName(svcName).cascading(true).delete(); if (appName != null) { delegate.services().inNamespace(prjName).withLabel(APP_LABEL, appName).delete();
log.warn("Ignoring DeploymentConfig %s as not connected to an OpenShift cluster", name); openshiftClient.deploymentConfigs().inNamespace(namespace).withName(name).replace(resource);
List<DeploymentConfig> deploymentConfigs = oClient.deploymentConfigs().inNamespace(session.getNamespace()).list().getItems(); if (deploymentConfigs == null) { throw new MultiException("No deployment configs found in namespace" + session.getNamespace());