Search in sources :

Example 1 with PodMetrics

use of com.marcnuri.yakc.model.io.k8s.metrics.pkg.apis.metrics.v1beta1.PodMetrics in project kubernetes-client by fabric8io.

the class MetricsTest method testPodMetricsNamespaceWithName.

@Test
void testPodMetricsNamespaceWithName() throws Exception {
    server.expect().get().withPath("/apis/metrics.k8s.io/v1beta1/namespaces/test/pods/test-pod").andReturn(200, getPodMetric()).once();
    PodMetrics podMetrics = client.top().pods().metrics("test", "test-pod");
    assertEquals("foo", podMetrics.getMetadata().getName());
}
Also used : PodMetrics(io.fabric8.kubernetes.api.model.metrics.v1beta1.PodMetrics) Test(org.junit.jupiter.api.Test)

Example 2 with PodMetrics

use of com.marcnuri.yakc.model.io.k8s.metrics.pkg.apis.metrics.v1beta1.PodMetrics in project yakc by manusa.

the class MetricsV1beta1ApiIT method readNamespacedPodMetrics.

@Test
@DisplayName("readNamespacedPodMetrics, cluster contains a Pod with some metrics")
void readNamespacedPodMetrics() throws IOException, InterruptedException {
    // Given
    final Pod pod = KC.create(CoreV1Api.class).listPodForAllNamespaces(new CoreV1Api.ListPodForAllNamespaces().labelSelector("k8s-app=metrics-server")).stream().findFirst().orElseThrow(() -> new AssertionError("No Pod found for metrics-server"));
    // When
    final PodMetrics result = getWithRetry(() -> KC.create(MetricsV1beta1Api.class).readNamespacedPodMetrics(pod.getMetadata().getName(), pod.getMetadata().getNamespace()).get());
    // Then
    assertThat(result).hasFieldOrProperty("apiVersion").hasFieldOrProperty("kind").hasFieldOrPropertyWithValue("metadata.name", pod.getMetadata().getName()).hasFieldOrPropertyWithValue("metadata.namespace", pod.getMetadata().getNamespace()).hasFieldOrProperty("window").hasFieldOrProperty("timestamp").extracting(PodMetrics::getContainers).asList().hasSizeGreaterThanOrEqualTo(1).allSatisfy(c -> assertThat(c).hasFieldOrProperty("usage.cpu").hasFieldOrProperty("usage.memory"));
}
Also used : Pod(com.marcnuri.yakc.model.io.k8s.api.core.v1.Pod) PodMetrics(com.marcnuri.yakc.model.io.k8s.metrics.pkg.apis.metrics.v1beta1.PodMetrics) MetricsV1beta1Api(com.marcnuri.yakc.api.metrics.v1beta1.MetricsV1beta1Api) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Test (org.junit.jupiter.api.Test)2 CoreV1Api (com.marcnuri.yakc.api.core.v1.CoreV1Api)1 MetricsV1beta1Api (com.marcnuri.yakc.api.metrics.v1beta1.MetricsV1beta1Api)1 Pod (com.marcnuri.yakc.model.io.k8s.api.core.v1.Pod)1 PodMetrics (com.marcnuri.yakc.model.io.k8s.metrics.pkg.apis.metrics.v1beta1.PodMetrics)1 PodMetrics (io.fabric8.kubernetes.api.model.metrics.v1beta1.PodMetrics)1 DisplayName (org.junit.jupiter.api.DisplayName)1