Search in sources :

Example 81 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.

the class Example method main.

public static void main(String[] args) {
    String roomName = "fabric8_default";
    if (args.length > 0) {
        roomName = args[0];
    }
    try {
        KubernetesClient kubernetes = new DefaultKubernetesClient();
        LetsChatClient letschat = LetsChatKubernetes.createLetsChat(kubernetes);
        System.out.println("Connecting to letschat on: " + letschat.getAddress());
        List<RoomDTO> rooms = letschat.getRooms();
        for (RoomDTO room : rooms) {
            System.out.println("Room " + room.getId() + " has slug: " + room.getSlug() + " name " + room.getName());
        }
        // looking up a room
        RoomDTO myRoom = letschat.getRoom(roomName);
        System.out.println("Found room: " + myRoom + " by slug: " + roomName);
        RoomDTO notExist = letschat.getRoom("does-not-exist");
        System.out.println("Found non existing room: " + notExist);
        // lets try lazily create a room if it doesn't exist
        RoomDTO newRoom = letschat.getOrCreateRoom("my_new_room_slug");
        System.out.println("Found/created room: " + newRoom);
    } catch (Exception e) {
        System.out.println("Caught: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 82 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.

the class DeleteBuildConfig method main.

public static void main(String... args) {
    if (args.length < 1) {
        System.out.println("Usage nameOfBuildConfig");
        return;
    }
    try {
        String name = args[0];
        System.out.println("Deleting BuildConfig: " + name);
        KubernetesClient kube = new DefaultKubernetesClient();
        String namespace = kube.getNamespace();
        System.out.println("Using namespace: " + namespace);
        Controller controller = new Controller(kube);
        OpenShiftClient openshift = controller.getOpenShiftClientOrJenkinshift();
        if (openshift == null) {
            System.err.println("Cannot connect to OpenShift or Jenkinshift!");
            return;
        }
        BuildConfig buildConfig = openshift.buildConfigs().withName(name).get();
        if (buildConfig != null) {
            System.out.println("Managed to load BuildConfig with resourceVersion " + KubernetesHelper.getResourceVersion(buildConfig));
        } else {
            System.err.println("Could not find BuildConfig called: " + name);
            return;
        }
        Boolean result = openshift.buildConfigs().withName(name).delete();
        System.out.println("Deleted BuildConfig with name " + name + " result: " + result);
    } catch (Exception e) {
        System.out.println("FAILED: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 83 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.

the class GetServiceURL method main.

public static void main(String... args) {
    if (args.length < 1) {
        System.out.println("Usage nameOfService");
        return;
    }
    try {
        String name = args[0];
        KubernetesClient kube = new DefaultKubernetesClient();
        String namespace = kube.getNamespace();
        if (Strings.isNullOrBlank(namespace)) {
            namespace = "default";
        }
        String url = KubernetesHelper.getServiceURL(kube, name, namespace, "http", true);
        System.out.println("Service " + name + " has external URL: " + url);
    } 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 84 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.

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 85 with DefaultKubernetesClient

use of io.fabric8.kubernetes.client.DefaultKubernetesClient in project fabric8 by jboss-fuse.

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)

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