-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathNamespaceListDemo.java
34 lines (27 loc) · 1.01 KB
/
NamespaceListDemo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package io.fabric8;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.KubernetesClientException;
import java.util.logging.Level;
import java.util.logging.Logger;
/*
* Creates Kubernetes Client and queries for all namespaces in cluster.
*/
public class NamespaceListDemo {
private static final Logger logger = Logger.getLogger(NamespaceListDemo.class
.getName());
public static void main(String[] args) {
logger.log(Level.INFO, "Creating Kuberntes client");
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
logger.log(Level.INFO, "Kubernetes client successfully created");
// List all namespaces
client.namespaces()
.list()
.getItems()
.forEach(n -> logger.log(Level.INFO, n.getMetadata().getName()));
} catch (KubernetesClientException aException) {
logger.log(Level.SEVERE, "Problem encountered in Kubernetes Client");
aException.printStackTrace();
}
}
}