use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by fabric8io.
the class Util method cleanupAllMatching.
public static void cleanupAllMatching(KubernetesClient client, Session session, List<Throwable> errors, List<KubernetesList> kubeConfigs) throws MultiException {
String sessionNamespace = session.getNamespace();
session.getLogger().info("Removing provisioned resources in namespace " + sessionNamespace);
/**
* Lets use a loop to ensure we really do delete all the matching resources
*/
for (int i = 0; i < 10; i++) {
for (KubernetesList list : kubeConfigs) {
List<HasMetadata> items = list.getItems();
if (items != null) {
for (HasMetadata item : items) {
cleanupItem(client, session, item, errors);
}
}
}
}
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by fabric8io.
the class Util method displaySessionStatus.
public static void displaySessionStatus(KubernetesClient client, Session session) throws MultiException {
if (client == null) {
session.getLogger().warn("No KubernetesClient for session: " + session.getId());
return;
}
if (client.isAdaptable(OpenShiftClient.class)) {
OpenShiftClient oClient = client.adapt(OpenShiftClient.class);
List<DeploymentConfig> deploymentConfigs = oClient.deploymentConfigs().inNamespace(session.getNamespace()).list().getItems();
if (deploymentConfigs == null) {
throw new MultiException("No deployment configs found in namespace" + session.getNamespace());
}
for (DeploymentConfig deploymentConfig : deploymentConfigs) {
session.getLogger().info("Deployment config:" + KubernetesHelper.getName(deploymentConfig));
}
} else {
List<Deployment> deployments = client.extensions().deployments().inNamespace(session.getNamespace()).list().getItems();
if (deployments == null) {
throw new MultiException("No deployments found in namespace" + session.getNamespace());
}
for (Deployment deployment : deployments) {
session.getLogger().info("Deployment:" + KubernetesHelper.getName(deployment));
}
}
List<Pod> pods = client.pods().inNamespace(session.getNamespace()).list().getItems();
if (pods == null) {
throw new MultiException("No pods found in namespace" + session.getNamespace());
}
for (Pod pod : pods) {
session.getLogger().info("Pod:" + KubernetesHelper.getName(pod) + " Status:" + pod.getStatus());
}
List<Service> svcs = client.services().inNamespace(session.getNamespace()).list().getItems();
if (svcs == null) {
throw new MultiException("No services found in namespace" + session.getNamespace());
}
for (Service service : svcs) {
session.getLogger().info("Service:" + KubernetesHelper.getName(service) + " IP:" + getPortalIP(service) + " Port:" + getPorts(service));
}
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by fabric8io.
the class Util method cleanupAllResources.
public static void cleanupAllResources(KubernetesClient client, Session session, List<Throwable> errors) throws MultiException {
String sessionNamespace = session.getNamespace();
session.getLogger().info("Removing all resources in namespace " + sessionNamespace);
/**
* Lets use a loop to ensure we really do delete all the matching resources
*/
for (int i = 0; i < 10; i++) {
OpenShiftClient openShiftClient = new Controller(client).getOpenShiftClientOrNull();
if (openShiftClient != null) {
try {
openShiftClient.deploymentConfigs().inNamespace(sessionNamespace).delete();
} catch (KubernetesClientException e) {
errors.add(e);
}
try {
openShiftClient.routes().inNamespace(sessionNamespace).delete();
} catch (KubernetesClientException e) {
errors.add(e);
}
}
try {
client.extensions().deployments().inNamespace(sessionNamespace).delete();
} catch (KubernetesClientException e) {
errors.add(e);
}
try {
client.extensions().replicaSets().inNamespace(sessionNamespace).delete();
} catch (KubernetesClientException e) {
errors.add(e);
}
try {
client.replicationControllers().inNamespace(sessionNamespace).delete();
} catch (KubernetesClientException e) {
errors.add(e);
}
try {
client.pods().inNamespace(sessionNamespace).delete();
} catch (KubernetesClientException e) {
errors.add(e);
}
try {
client.extensions().ingresses().inNamespace(sessionNamespace).delete();
} catch (KubernetesClientException e) {
errors.add(e);
}
try {
client.services().inNamespace(sessionNamespace).delete();
} catch (KubernetesClientException e) {
errors.add(e);
}
try {
client.securityContextConstraints().withName(sessionNamespace).delete();
} catch (KubernetesClientException e) {
errors.add(e);
}
// lets see if there are any matching podList left
List<Pod> filteredPods = notNullList(client.pods().inNamespace(sessionNamespace).list().getItems());
if (filteredPods.isEmpty()) {
return;
} else {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by fabric8io.
the class SessionListener method preprocessEnvironment.
protected void preprocessEnvironment(KubernetesClient client, Controller controller, Configuration configuration, Session session) {
if (configuration.isUseGoFabric8()) {
// lets invoke gofabric8 to configure the security and secrets
Logger logger = session.getLogger();
Commands.assertCommand(logger, "oc", "project", session.getNamespace());
Commands.assertCommand(logger, "gofabric8", "deploy", "-y", "--console=false", "--templates=false");
Commands.assertCommand(logger, "gofabric8", "secrets", "-y");
}
}
use of io.fabric8.arquillian.kubernetes.Session in project fabric8 by fabric8io.
the class SessionListener method enhance.
private KubernetesList enhance(final Session session, Configuration configuration, KubernetesList kubernetesList) {
if (configuration == null || configuration.getProperties() == null || !configuration.getProperties().containsKey(Constants.KUBERNETES_MODEL_PROCESSOR_CLASS)) {
return kubernetesList;
}
String processorClassName = configuration.getProperties().get(Constants.KUBERNETES_MODEL_PROCESSOR_CLASS);
try {
final Object instance = SessionListener.class.getClassLoader().loadClass(processorClassName).newInstance();
KubernetesListBuilder builder = new KubernetesListBuilder(kubernetesList);
((Visitable) builder).accept(new Visitor() {
@Override
public void visit(Object o) {
for (Method m : findMethods(instance, o.getClass())) {
Named named = m.getAnnotation(Named.class);
if (named != null && !Strings.isNullOrBlank(named.value())) {
String objectName = o instanceof ObjectMeta ? getName((ObjectMeta) o) : getName((HasMetadata) o);
// If a name has been explicitly specified check if there is a match
if (!named.value().equals(objectName)) {
session.getLogger().warn("Named method:" + m.getName() + " with name:" + named.value() + " doesn't match: " + objectName + ", ignoring");
return;
}
}
try {
m.invoke(instance, o);
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
session.getLogger().error("Error invoking visitor method:" + m.getName() + " on:" + instance + "with argument:" + o);
}
}
}
});
return builder.build();
} catch (Exception e) {
session.getLogger().warn("Failed to load processor class:" + processorClassName + ". Ignoring");
return kubernetesList;
}
}
Aggregations