use of io.fabric8.kubernetes.client.KubernetesClient 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();
}
use of io.fabric8.kubernetes.client.KubernetesClient 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.KubernetesClient in project fabric8 by fabric8io.
the class ConfigurationTest method testNamespaceNotFoundFromConfigMap.
@Ignore
public void testNamespaceNotFoundFromConfigMap() {
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(200, new ConfigMapBuilder().withNewMetadata().withName("fabric8-environments").endMetadata().withData(data).build()).once();
Map<String, String> map = new HashMap<>();
map.put(FABRIC8_ENVIRONMENT, environmentKey);
map.put(DEVELOPMENT_NAMESPACE, devNamespace);
Configuration configuration = Configuration.fromMap(map, kubernetesClient);
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.KubernetesClient 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.KubernetesClient in project fabric8 by fabric8io.
the class SessionListener method generateSecrets.
private Set<Secret> generateSecrets(KubernetesClient client, Session session, ObjectMeta meta) {
Set<Secret> secrets = new HashSet<>();
Map<String, String> annotations = meta.getAnnotations();
if (annotations != null && !annotations.isEmpty()) {
for (Map.Entry<String, String> entry : annotations.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (SecretKeys.isSecretKey(key)) {
SecretKeys keyType = SecretKeys.fromValue(key);
for (String name : Secrets.getNames(value)) {
Map<String, String> data = new HashMap<>();
Secret secret = null;
try {
secret = client.secrets().inNamespace(session.getNamespace()).withName(name).get();
} catch (Exception e) {
// ignore - probably doesn't exist
}
if (secret == null) {
for (String c : Secrets.getContents(value, name)) {
data.put(c, keyType.generate());
}
secret = client.secrets().inNamespace(session.getNamespace()).createNew().withNewMetadata().withName(name).endMetadata().withData(data).done();
secrets.add(secret);
}
}
}
}
}
return secrets;
}
Aggregations