use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.
the class OpenShiftAssert method buildConfigs.
public BuildConfigsAssert buildConfigs() {
BuildConfigList listObject = client.buildConfigs().list();
assertThat(listObject).describedAs("No BuildConfigsList found!").isNotNull();
List<BuildConfig> list = listObject.getItems();
assertThat(list).describedAs("No BuildConfig Items found!").isNotNull();
return new BuildConfigsAssert(list, client);
}
use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.
the class Example method main.
public static void main(String[] args) {
try {
final KubernetesClient client = new DefaultKubernetesClient();
assertThat(client).pods().runningStatus().hasSize(6);
assertThat(client).pods().runningStatus().filterLabel("provider", "fabric8").assertSize().isGreaterThan(0);
assertThat(client.services().inNamespace("default").withName("fabric8").get().getMetadata()).name().isEqualTo("fabric8");
Map<String, String> consoleLabels = new HashMap<>();
consoleLabels.put("component", "console");
consoleLabels.put("provider", "fabric8");
assertThat(client).podsForService("fabric8").runningStatus().extracting("metadata").extracting("labels").contains(consoleLabels);
assertThat(client).podsForService("fabric8").runningStatus().hasSize(1).extracting("metadata").extracting("labels").contains(consoleLabels);
assertThat(client).podsForService("fabric8").logs().doesNotContainText("Exception", "Error");
assertThat(client).pods().logs().doesNotContainText("Exception", "Error");
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
try {
assertThat(client.services().inNamespace("default").withName("doesNotExist").get().getMetadata()).name().isEqualTo("fabric8-console-controller");
} catch (KubernetesClientException e) {
if (e.getCode() != 404) {
throw e;
} else {
throw new AssertionError(e);
}
}
}
});
assertAssertionError(new Block() {
@Override
public void invoke() throws Exception {
try {
assertThat(client).pods().runningStatus().filterLabel("component", "doesNotExist").hasSize(1);
} catch (KubernetesClientException e) {
if (e.getCode() != 404) {
throw e;
} else {
throw new AssertionError(e);
}
}
}
});
System.out.println("Done!");
} catch (Throwable e) {
System.out.println("Caught: " + e);
e.printStackTrace();
}
}
use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.
the class DeploymentConfigPodsAssert method pods.
public PodSelectionAssert pods() {
spec().isNotNull().selector().isNotNull();
DeploymentConfigSpec spec = this.actual.getSpec();
Integer replicas = spec.getReplicas();
Map<String, String> matchLabels = spec.getSelector();
List<LabelSelectorRequirement> matchExpressions = new ArrayList<>();
return new PodSelectionAssert(client, replicas, matchLabels, matchExpressions, "DeploymentConfig " + KubernetesHelper.getName(actual));
}
use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.
the class KubernetesAssert method services.
public ServicesAssert services() {
ServiceList serviceList = client.services().inNamespace(namespace()).list();
assertThat(serviceList).isNotNull();
List<Service> services = serviceList.getItems();
return new ServicesAssert(client, services);
}
use of io.fabric8.kubernetes.client.Client in project fabric8 by fabric8io.
the class KubernetesAssert method deployments.
/**
* Finds all the resources that create pod selections (Deployment, DeploymentConfig, ReplicaSet, ReplicationController)
* and create a {@link HasPodSelectionAssert} to make assertions on their pods that they startup etc.
*
* @return the assertion object for the deployment
*/
public HasPodSelectionAssert deployments() {
List<HasPodSelectionAssert> asserters = new ArrayList<>();
List<HasMetadata> resources = new ArrayList<>();
try {
resources = KubernetesHelper.findKubernetesResourcesOnClasspath(new Controller(client));
} catch (IOException e) {
fail("Failed to load kubernetes resources on the classpath: " + e, e);
}
for (HasMetadata resource : resources) {
HasPodSelectionAssert asserter = createPodSelectionAssert(resource);
if (asserter != null) {
asserters.add(asserter);
}
}
String message = "No pod selection kinds found on the classpath such as Deployment, DeploymentConfig, ReplicaSet, ReplicationController";
// TODO we don't yet support size > 1
assertThat(asserters).describedAs(message).isNotEmpty();
if (asserters.size() == 1) {
return asserters.get(0);
}
return new MultiHasPodSelectionAssert(asserters);
}
Aggregations