use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.
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);
}
use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.
the class PipelineConfigurationParseTest method loadTestConfigMap.
public static ConfigMap loadTestConfigMap() throws IOException {
String path = FABRIC8_PIPELINES + ".yml";
URL resource = PipelineConfigurationParseTest.class.getClassLoader().getResource(path);
assertNotNull("Could not load resource: " + path, resource);
try (InputStream in = resource.openStream()) {
assertNotNull("Could not open stream for resource: " + resource, in);
ConfigMap configMap = KubernetesHelper.loadYaml(in, ConfigMap.class);
assertNotNull("Should have loaded " + resource, configMap);
return configMap;
}
}
use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.
the class SpacesTest method testLoadSpaces.
@Test
public void testLoadSpaces() {
String namespace = "myproject";
String resourceName = "fabric8-spaces.yml";
KubernetesClient client = getKubernetesClient();
URL resource = getClass().getClassLoader().getResource(resourceName);
assertNotNull("Failed to load resource from classpath: " + resourceName, resourceName);
InputStream inputStream = null;
try {
inputStream = resource.openStream();
} catch (IOException e) {
fail("Failed to open " + resourceName + ". " + e);
}
assertNotNull("Failed to open resource from classpath: " + resourceName, resourceName);
ConfigMap configMap = null;
try {
configMap = KubernetesHelper.loadYaml(inputStream, ConfigMap.class);
} catch (IOException e) {
fail("Failed to parse YAML: " + resourceName + ". " + e);
}
server.expect().withPath("/api/v1/namespaces/" + namespace + "/configmaps/" + FABRIC8_SPACES).andReturn(200, configMap).once();
Spaces spaces = Spaces.load(kubernetesClient, namespace);
List<Space> spaceList = new ArrayList<>(spaces.getSpaceSet());
assertEquals("Size of spaceList: " + spaceList, 3, spaceList.size());
Space space0 = spaceList.get(0);
assertEquals("space0.name", "Foo", space0.getName());
}
use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.
the class PodResourceProvider method lookup.
@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
KubernetesClient client = this.clientInstance.get();
Session session = sessionInstance.get();
String name = getPodName(qualifiers);
if (name != null) {
return client.pods().inNamespace(session.getNamespace()).withName(name).get();
}
// Gets the first pod found that matches the labels.
Map<String, String> labels = getLabels(qualifiers);
PodList list = client.pods().inNamespace(session.getNamespace()).withLabels(labels).list();
List<Pod> pods = notNullList(list.getItems());
if (!pods.isEmpty()) {
return pods.get(0);
}
return null;
}
use of io.fabric8.kubernetes.client.dsl.Resource in project fabric8 by jboss-fuse.
the class ReplicationControllerResourceProvider method lookup.
@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
KubernetesClient client = this.clientInstance.get();
Session session = sessionInstance.get();
String name = getReplicationControllerName(qualifiers);
return client.replicationControllers().inNamespace(session.getNamespace()).withName(name).get();
}
Aggregations