Search in sources :

Example 36 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class IsOpenShift method main.

public static void main(String... args) {
    KubernetesClient client = new DefaultKubernetesClient();
    try {
        boolean openShift = KubernetesHelper.isOpenShift(client);
        System.out.println("OpenShift: " + openShift);
    } catch (Exception e) {
        System.out.println("FAILED: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 37 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class PodIdToReplicationControllerIDExample method main.

public static void main(String[] args) {
    if (args.length < 3) {
        System.out.println("Arguments: kuberneteMasterUrl namespace podID");
        return;
    }
    String kuberneteMasterUrl = args[0];
    String namespace = args[1];
    String podID = args[2];
    System.out.println("Looking up ReplicationController for pod ID: " + podID);
    KubernetesClient client = new DefaultKubernetesClient(new ConfigBuilder().withMasterUrl(kuberneteMasterUrl).build());
    Pod pod = (Pod) client.pods().inNamespace(namespace).withName(podID);
    pod.getMetadata().getLabels();
    List<ReplicationController> replicationControllers = client.replicationControllers().inNamespace(namespace).withLabels(pod.getMetadata().getLabels()).list().getItems();
    if (replicationControllers.size() == 1) {
        ReplicationController replicationController = replicationControllers.get(0);
        String id = KubernetesHelper.getName(replicationController);
        System.out.println("Found replication controller: " + id);
    } else {
        System.out.println("Could not find replication controller!");
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Pod(io.fabric8.kubernetes.api.model.Pod) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 38 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class ListEnvironments method main.

public static void main(String[] args) {
    KubernetesClient kubernetesClient = new DefaultKubernetesClient();
    Environments environments;
    if (args.length > 0) {
        String namespace = args[0];
        System.out.println("Listing environments for namespace: " + namespace);
        environments = Environments.load(namespace);
    } else {
        environments = Environments.load();
    }
    String environmentKey = "testing";
    if (args.length > 1) {
        environmentKey = args[1];
    }
    System.out.println("Space namespace: " + environments.getNamespace());
    SortedSet<Environment> set = environments.getEnvironmentSet();
    for (Environment environment : set) {
        String onCluster = "";
        String clusterAPiServer = environment.getClusterAPiServer();
        if (Strings.isNotBlank(clusterAPiServer)) {
            onCluster += " on API server: " + clusterAPiServer;
        }
        System.out.println("Environment " + environment.getName() + " maps to namespace: " + environment.getNamespace() + onCluster);
    }
    System.out.println("Namespace for environment key: " + environmentKey + " is " + Environments.namespaceForEnvironment(environmentKey));
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 39 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class ViewEndpoints method main.

public static void main(String... args) {
    System.out.println("Usage: [serviceId] [namespace]");
    KubernetesClient client = new DefaultKubernetesClient();
    try {
        String service = null;
        String namespace = null;
        if (args.length > 0) {
            service = args[0];
        }
        if (args.length > 1) {
            namespace = args[1];
        }
        listEndpoints(client, service, namespace);
    } catch (Exception e) {
        System.out.println("FAILED: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 40 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by fabric8io.

the class WatchServicesExample method main.

public static void main(String... args) throws Exception {
    KubernetesClient client = new DefaultKubernetesClient();
    client.services().watch(new io.fabric8.kubernetes.client.Watcher<Service>() {

        @Override
        public void eventReceived(Action action, Service service) {
            System.out.println(action + ": " + service);
        }

        @Override
        public void onClose(KubernetesClientException e) {
            System.out.println("Closed: " + e);
        }
    });
    client.close();
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Service(io.fabric8.kubernetes.api.model.Service) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)101 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)77 File (java.io.File)27 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)22 FileInputStream (java.io.FileInputStream)22 HashMap (java.util.HashMap)13 Test (org.testng.annotations.Test)12 Config (io.fabric8.kubernetes.client.Config)11 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)11 BeforeClass (org.testng.annotations.BeforeClass)10 Service (io.fabric8.kubernetes.api.model.Service)8 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)7 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)6 TaskAction (org.gradle.api.tasks.TaskAction)6 Pod (io.fabric8.kubernetes.api.model.Pod)5 Map (java.util.Map)5 Test (org.junit.Test)5 KubernetesModelGenerator (com.github.isdream.chameleon.container.kubernetes.KubernetesModelGenerator)4 ImmutableMap (com.google.common.collect.ImmutableMap)4