Search in sources :

Example 41 with DefaultKubernetesClient

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

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

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

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

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

the class DevOpsConnector method getKubernetes.

public KubernetesClient getKubernetes() {
    if (kubernetes == null) {
        Config config = new ConfigBuilder().withNamespace(namespace).build();
        kubernetes = new DefaultKubernetesClient(config);
    }
    return kubernetes;
}
Also used : Config(io.fabric8.kubernetes.client.Config) ProjectConfig(io.fabric8.devops.ProjectConfig) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) ConfigBuilder(io.fabric8.kubernetes.client.ConfigBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 44 with DefaultKubernetesClient

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

the class UpdateEnviromentConfigMap method main.

public static void main(String... args) {
    try {
        KubernetesClient kube = new DefaultKubernetesClient();
        System.out.println("Using namespace " + kube.getNamespace() + " on master: " + kube.getMasterUrl());
        Map<String, String> environments = new HashMap<>();
        environments.put("Testing2", "default-testing");
        environments.put("Staging2", "default-staging");
        DevOpsConnector connector = new DevOpsConnector();
        String consoleUrl = "http://fabric8.vagrant.f8/";
        Map<String, String> annotations = new HashMap<>();
        System.out.println("Starting to create/update the environment ConfigMap with " + environments);
        connector.updateEnvironmentConfigMap(environments, kube, annotations, consoleUrl);
        System.out.println("Now trying a second time!");
        connector.updateEnvironmentConfigMap(environments, kube, annotations, consoleUrl);
        System.out.println("Worked!!!");
    } catch (Exception e) {
        System.out.println("FAILED: " + e);
        e.printStackTrace();
    }
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) HashMap(java.util.HashMap) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 45 with DefaultKubernetesClient

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

the class NoNamespaceTest method testServiceInjection.

@Test
public void testServiceInjection() {
    KubernetesClient client = new DefaultKubernetesClient();
    String namespace = client.getNamespace();
    // If namespace not null or empty then don't fail if the result is unexpected.
    Assume.assumeTrue(Strings.isNullOrBlank(namespace));
    expectedException.expect(ThrowableMessageMatcher.hasMessage(CoreMatchers.equalTo("No kubernetes service could be found for name: notfound in namespace: null")));
    createInstance(MyBean.class);
}
Also used : KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) Test(org.junit.Test)

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