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