use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.
the class Util method waitUntilWeCanDestroyNamespace.
protected static void waitUntilWeCanDestroyNamespace(Session session) {
final Logger log = session.getLogger();
String confirmDestroy = Systems.getEnvVarOrSystemProperty(Constants.NAMESPACE_CLEANUP_CONFIRM_ENABLED, "false");
if (Objects.equal(confirmDestroy, "true")) {
showErrorsBeforePause(session);
System.out.println();
System.out.println("Waiting to destroy the namespace.");
System.out.println("Please type: [Q] to terminate the namespace.");
while (true) {
try {
int ch = System.in.read();
if (ch < 0 || ch == 'Q') {
System.out.println("\nStopping...");
break;
} else {
System.out.println("Found character: " + Character.toString((char) ch));
}
} catch (IOException e) {
log.warn("Failed to read from input. " + e);
break;
}
}
} else {
String timeoutText = Systems.getEnvVarOrSystemProperty(Constants.NAMESPACE_CLEANUP_TIMEOUT, "0");
Long timeout = null;
if (Strings.isNotBlank(timeoutText)) {
try {
timeout = Long.parseLong(timeoutText);
} catch (NumberFormatException e) {
log.warn("Failed to parse timeout value '" + timeoutText + "' for $Constants.NAMESPACE_CLEANUP_TIMEOUT. " + e);
}
}
if (timeout != null && timeout > 0L) {
showErrorsBeforePause(session);
System.out.println();
System.out.println("Sleeping for " + timeout + " seconds until destroying the namespace");
try {
Thread.sleep(timeout * 1000);
} catch (InterruptedException e) {
log.info("Interupted sleeping to GC the namespace: " + e);
}
}
}
System.out.println("Now destroying the Fabric8 Arquillian test case namespace");
}
use of io.fabric8.kubernetes.api.model.Namespace in project fabric8 by fabric8io.
the class ConfigurationTest method testNamespaceFoundFromConfigMap.
@Test
public void testNamespaceFoundFromConfigMap() {
String devNamespace = "myproject";
String environmentKey = "testing";
String testNamespace = "myproject-testing";
Map<String, String> data = new HashMap<>();
data.put(environmentKey, " name: Testing\n" + " namespace: " + testNamespace + "\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, getKubernetesClient());
assertEquals(testNamespace, configuration.getNamespace());
assertTrue(configuration.isAnsiLoggerEnabled());
assertTrue(configuration.isEnvironmentInitEnabled());
assertTrue(configuration.isNamespaceLazyCreateEnabled());
assertFalse(configuration.isNamespaceCleanupEnabled());
assertFalse(configuration.isCreateNamespaceForTest());
}
use of io.fabric8.kubernetes.api.model.Namespace 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.api.model.Namespace in project fabric8 by fabric8io.
the class ConfigurationTest method testFailIfEnvironmentNamespaceNotFoundFromConfigMap.
@Test(expected = IllegalStateException.class)
public void testFailIfEnvironmentNamespaceNotFoundFromConfigMap() {
String devNamespace = "myproject";
String environmentKey = "testing";
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);
map.put(FAIL_ON_MISSING_ENVIRONMENT_NAMESPACE, "true");
Configuration.fromMap(map, getKubernetesClient());
}
use of io.fabric8.kubernetes.api.model.Namespace 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());
}
Aggregations