@Override public NonNamespaceOperation<Namespace, NamespaceList, DoneableNamespace, Resource<Namespace, DoneableNamespace>> namespaces() { return delegate.namespaces(); }
client.namespaces().list() ); client.namespaces().withLabel("this", "works").list() );
public static void main(String[] args) { String master = "https://localhost:8443/"; if (args.length == 1) { master = args[0]; } Config config = new ConfigBuilder().withMasterUrl(master).build(); KubernetesClient client = new DefaultKubernetesClient(config); try { log("Create namespace:", client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName("thisisatest").endMetadata().build())); log("Deleted namespace:", client.namespaces().withName("test").delete()); log("Deleted testPod:", client.pods().inNamespace("thisisatest").withName("testpod").delete()); log("Deleted pod by label:", client.pods().withLabel("this", "works").delete()); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } finally { client.namespaces().withName("thisisatest").delete(); client.close(); } }
@Override Namespace createResource(Namespace current) { return client .namespaces() .create(current); }
try (KubernetesClient client = new DefaultKubernetesClient(config)) { try { log("Create namespace:", client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName("thisisatest").endMetadata().build())); logger.error(e.getMessage(), e); } finally { client.namespaces().withName("thisisatest").delete();
public void deleteNamespace(String namespace) { log.info("Following namespace will be removed - {}", namespace); client.namespaces().withName(namespace).delete(); }
public Set<String> listNamespaces() { return client.namespaces().list().getItems().stream() .map(ns -> ns.getMetadata().getName()) .collect(Collectors.toSet()); }
protected void doGetNamespace(Exchange exchange, String operation) { String namespaceName = exchange.getIn().getHeader( KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Get a specific namespace require specify a namespace name"); throw new IllegalArgumentException( "Get a specific namespace require specify a namespace name"); } Namespace namespace = getEndpoint().getKubernetesClient().namespaces() .withName(namespaceName).get(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(namespace); }
protected void doList(Exchange exchange, String operation) throws Exception { NamespaceList namespacesList = getEndpoint().getKubernetesClient() .namespaces().list(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(namespacesList.getItems()); }
log("Created namespace", client.namespaces().createOrReplace(ns)); client.namespaces().withName("thisisatest").delete(); client.close();
private List<String> getNamespacesInternal(KubernetesClient kubeClient) { List<String> returnList = new ArrayList<>(); for (Namespace namespace: kubeClient.namespaces().list().getItems() ) { returnList.add(namespace.getMetadata().getName() ); } return returnList; } }
@Override public String getFailureMessage() { Namespace actualNamespace = client.namespaces().withName(name).get(); return "Namespace for " + name + " " + (actualNamespace == null ? "absent" : " status " + actualNamespace.getStatus()); } };
@Override public Boolean call() { Namespace actualNamespace = client.namespaces().withName(name).get(); return actualNamespace != null && actualNamespace.getStatus().getPhase().equals(PHASE_ACTIVE); }
@Override Namespace getCurrentResource() { return client .namespaces() .withName(getName()) .get(); }
static void createNamespace(AccountDeploymentDetails<KubernetesAccount> details, String namespace) { KubernetesClient client = getClient(details); if (client.namespaces().withName(namespace).get() == null) { client.namespaces().create(new NamespaceBuilder() .withNewMetadata() .withName(namespace) .endMetadata() .build()); } }
static void createNamespace(AccountDeploymentDetails<KubernetesAccount> details, String namespace) { KubernetesClient client = getClient(details); if (client.namespaces().withName(namespace).get() == null) { client.namespaces().create(new NamespaceBuilder() .withNewMetadata() .withName(namespace) .endMetadata() .build()); } }
public void scanNamespaces() { getKubernetesClient().namespaces().list().getItems().forEach(it -> { scanNamespace(it); }); getNeoRxClient().execCypher( "match (n:KubeNamespace {clusterId:{clusterId}}), (c:KubeCluster {clusterId:{clusterId}}) merge (c)-[x:CONTAINS]->(n)", "clusterId", getClusterId()); }
log("Created namespace", client.namespaces().create(ns)); log("Get namespace by name", client.namespaces().withName("thisisatest").get()); log("Get namespace by label", client.namespaces().withLabel("this", "rocks").list()); client.namespaces().withName("thisisatest").delete(); log("Deleted namespace");
public boolean deleteNamespace(String namespaceName) { if (!checkNamespace(namespaceName)) { return false; } OpenShiftClient openshiftClient = getOpenShiftClient(); if (openshiftClient != null) { return openshiftClient.projects().withName(namespaceName).delete(); } else { return kubernetesClient.namespaces().withName(namespaceName).delete(); } }
@Override Namespace applyResource(Namespace original, Namespace current) { return client .namespaces() .withName(getName()) .edit() .withMetadata(current.getMetadata()) .withSpec(current.getSpec()) .done(); }