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());
}
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;
}
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;
}
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();
}
}
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);
}
Aggregations