Search in sources :

Example 66 with DefaultKubernetesClient

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

the class KubernetesHolder method getClient.

public static synchronized KubernetesClient getClient() {
    if (client != null) {
        return client;
    }
    BeanManager beanManager = getBeanManager();
    if (beanManager != null) {
        Set<Bean<?>> beans = beanManager.getBeans(KubernetesClient.class);
        if (beans.isEmpty()) {
            throw new IllegalStateException("Could not find client beans!");
        } else {
            CreationalContext ctx = beanManager.createCreationalContext(null);
            client = (KubernetesClient) beanManager.getReference(beans.iterator().next(), KubernetesClient.class, ctx);
        }
    } else {
        client = new DefaultKubernetesClient();
    }
    return client;
}
Also used : CreationalContext(javax.enterprise.context.spi.CreationalContext) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) BeanManager(javax.enterprise.inject.spi.BeanManager) Bean(javax.enterprise.inject.spi.Bean)

Example 67 with DefaultKubernetesClient

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

the class ConfigurationTest method testEnvironmentKeyButNoConfigMapLocalOnly.

@Ignore
public void testEnvironmentKeyButNoConfigMapLocalOnly() {
    String devNamespace = "myproject";
    String environmentKey = "testing";
    String testNamespace = devNamespace;
    Map<String, String> data = new HashMap<>();
    data.put("staging", "    name: Staging\n" + "    namespace: myproject-staging\n" + "    order: 0");
    server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(404, "Not found").once();
    Map<String, String> map = new HashMap<>();
    map.put(FABRIC8_ENVIRONMENT, environmentKey);
    KubernetesClient kubernetesClient = getKubernetesClient();
    Config config = new Config();
    config.setNamespace(devNamespace);
    config.setMasterUrl(kubernetesClient.getMasterUrl().toString());
    DefaultKubernetesClient clientWithDefaultNamespace = new DefaultKubernetesClient(config);
    Configuration configuration = Configuration.fromMap(map, clientWithDefaultNamespace);
    assertEquals(testNamespace, configuration.getNamespace());
    assertTrue(configuration.isAnsiLoggerEnabled());
    assertTrue(configuration.isEnvironmentInitEnabled());
    assertTrue(configuration.isNamespaceLazyCreateEnabled());
    assertFalse(configuration.isNamespaceCleanupEnabled());
    assertFalse(configuration.isCreateNamespaceForTest());
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HashMap(java.util.HashMap) Config(io.fabric8.kubernetes.client.Config) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Ignore(org.junit.Ignore)

Example 68 with DefaultKubernetesClient

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

the class ConfigurationTest method testEnvironmentKeyButNoConfigMap.

@Test
public void testEnvironmentKeyButNoConfigMap() {
    String devNamespace = "myproject";
    String environmentKey = "testing";
    String testNamespace = devNamespace;
    Map<String, String> data = new HashMap<>();
    data.put("staging", "    name: Staging\n" + "    namespace: myproject-staging\n" + "    order: 0");
    server.expect().withPath("/api/v1/namespaces/" + devNamespace + "/configmaps/fabric8-environments").andReturn(404, "Not found").once();
    Map<String, String> map = new HashMap<>();
    map.put(FABRIC8_ENVIRONMENT, environmentKey);
    map.put(DEVELOPMENT_NAMESPACE, devNamespace);
    KubernetesClient kubernetesClient = getKubernetesClient();
    Config config = new Config();
    config.setNamespace(devNamespace);
    config.setMasterUrl(kubernetesClient.getMasterUrl().toString());
    DefaultKubernetesClient clientWithDefaultNamespace = new DefaultKubernetesClient(config);
    Configuration configuration = Configuration.fromMap(map, clientWithDefaultNamespace);
    assertEquals(testNamespace, configuration.getNamespace());
    assertTrue(configuration.isAnsiLoggerEnabled());
    assertTrue(configuration.isEnvironmentInitEnabled());
    assertTrue(configuration.isNamespaceLazyCreateEnabled());
    assertFalse(configuration.isNamespaceCleanupEnabled());
    assertFalse(configuration.isCreateNamespaceForTest());
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HashMap(java.util.HashMap) Config(io.fabric8.kubernetes.client.Config) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Test(org.junit.Test)

Example 69 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 projectName = "admin-beer";
    if (args.length > 0) {
        projectName = args[0];
    }
    try {
        KubernetesClient kubernetes = new DefaultKubernetesClient();
        TaigaClient taiga = TaigaKubernetes.createTaiga(kubernetes, KubernetesHelper.defaultNamespace());
        System.out.println("Connecting to taiga on: " + taiga.getAddress());
        ProjectDTO myProject = taiga.getProjectBySlug(projectName);
        System.out.println("Found project: " + myProject + " by slug: " + projectName);
        System.out.println("Project id for slug: " + myProject + " is: " + taiga.getProjectIdForSlug(projectName));
        ProjectDTO notExist = taiga.getProjectBySlug("does-not-exist");
        System.out.println("Found non existing project: " + notExist);
        Map<String, ModuleDTO> modules = taiga.getModulesForProject(projectName);
        System.out.println("Available modules for " + projectName + " are: " + modules.keySet());
        // lets try find the module for gogs
        ModuleDTO gogsModule = taiga.moduleForProject(projectName, TaigaModule.GOGS);
        System.out.println("Gogs module for " + projectName + " is " + gogsModule);
        ProjectDTO autoCreateProject = taiga.getOrCreateProject("thingy");
        System.out.println("getOrCreateProject: " + autoCreateProject);
        List<ProjectDTO> projects = taiga.getProjects();
        for (ProjectDTO project : projects) {
            System.out.println("Project " + project.getId() + " has slug: " + project.getSlug() + " name " + project.getName());
        }
    } 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 70 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)

Aggregations

DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)79 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)55 HashMap (java.util.HashMap)13 Config (io.fabric8.kubernetes.client.Config)11 ConfigBuilder (io.fabric8.kubernetes.client.ConfigBuilder)7 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)7 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)6 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)6 TaskAction (org.gradle.api.tasks.TaskAction)6 Pod (io.fabric8.kubernetes.api.model.Pod)5 IOException (java.io.IOException)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 File (java.io.File)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 Service (io.fabric8.kubernetes.api.model.Service)3 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)3 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)3