use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Pod 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"));
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Pod in project yakc by manusa.
the class PodQuickstart method main.
public static void main(String[] args) {
System.out.println("Complete POD example:\n" + " - Creates a namespace\n" + " - Deletes POD if exists\n" + " - Creates POD\n" + " - Patches POD's labels\n" + " - Updates POD removing annotations and adding another label\n" + "Starting...\n");
try (KubernetesClient kc = new KubernetesClient()) {
final CoreV1Api api = kc.create(CoreV1Api.class);
final Disposable podMonitor = monitorPods(api);
createNamespace(api);
deletePodIfExists(api);
createPod(api);
final Pod patchedPod = patchPodLabels(api);
System.out.printf("POD labels patched [%s]%n", patchedPod.getMetadata().getLabels());
final Pod updatedPod = replacePod(patchedPod, api);
System.out.printf("POD replaced: annotations removed, labels modified [%s]%n", updatedPod.getMetadata().getLabels());
podMonitor.dispose();
System.out.println("Pod demo concluded successfully!");
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Pod in project yakc by manusa.
the class PodIT method patchNamespacedPod.
@Test
@DisplayName("patchNamespacedPod, should patch labels of Pod")
void patchNamespacedPod() throws IOException {
// When
final Pod result = KC.create(CoreV1Api.class).patchNamespacedPod(podName, NAMESPACE, Pod.builder().metadata(ObjectMeta.builder().putInLabels("patched", "label").build()).build()).get();
// Then
assertThat(result).isNotNull().hasFieldOrPropertyWithValue("metadata.name", podName).extracting(Pod::getMetadata).hasFieldOrPropertyWithValue("name", podName).extracting(ObjectMeta::getLabels).asInstanceOf(InstanceOfAssertFactories.MAP).hasSize(2).containsEntry("patched", "label");
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Pod in project yakc by manusa.
the class PodIT method replaceNamespacedPod.
@Test
@DisplayName("replaceNamespacedPod, should replace existing Pod's image")
void replaceNamespacedPod() throws IOException {
// Given
awaitPodReady();
final Pod existingPod = KC.create(CoreV1Api.class).readNamespacedPod(podName, NAMESPACE).get();
existingPod.getMetadata().setResourceVersion(null);
existingPod.getSpec().getContainers().get(0).setImage("nginxdemos/hello");
// When
final Pod result = KC.create(CoreV1Api.class).replaceNamespacedPod(podName, NAMESPACE, existingPod).get();
// Then
assertThat(result).isNotNull().hasFieldOrPropertyWithValue("metadata.name", podName).extracting(Pod::getSpec).extracting(PodSpec::getContainers).asList().hasSize(1).element(0).hasFieldOrPropertyWithValue("image", "nginxdemos/hello");
}
Aggregations