use of com.marcnuri.yakc.model.io.k8s.api.core.v1.ConfigMap in project yakc by manusa.
the class WipIT method configMaps.
@Test
void configMaps() throws Exception {
final String configMapName = "test";
final CountDownLatch cdl = new CountDownLatch(1);
KC.create(CoreV1Api.class).listConfigMapForAllNamespaces().watch().subscribeOn(Schedulers.newThread()).filter(we -> Stream.of(Type.ADDED, Type.DELETED).anyMatch(t -> we.getType() == t)).filter(we -> we.getObject().getMetadata().getName().equals(configMapName)).subscribe(we -> {
cdl.countDown();
System.out.printf("++ ConfigMap Watch %-15s - %s/%s%n", we.getType(), we.getObject().getMetadata().getNamespace(), we.getObject().getMetadata().getName());
});
try {
KC.create(CoreV1Api.class).deleteNamespacedConfigMap(configMapName, "default").get();
System.out.println("Existing ConfigMap was deleted");
} catch (NotFoundException ex) {
System.out.println("ConfigMap not found, deletion not needed");
}
KC.create(CoreV1Api.class).createNamespacedConfigMap("default", ConfigMap.builder().metadata(ObjectMeta.builder().name(configMapName).putInAnnotations("one-annotation-key", "annotation-value").build()).data(Collections.singletonMap("some", "to-keep")).putInData("test-key", "test-value").build()).get();
KC.create(CoreV1Api.class).patchNamespacedConfigMap(configMapName, "default", ConfigMap.builder().metadata(ObjectMeta.builder().putInLabels("other", "label").build()).build()).get();
cdl.await(5, TimeUnit.SECONDS);
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.ConfigMap in project yakc by manusa.
the class ConfigMapIT method readNamespacedConfigMap.
@Test
@DisplayName("readNamespacedConfigMap, should retrieve newly created ConfigMap")
void readNamespacedConfigMap() throws IOException {
// When
final ConfigMap result = KC.create(CoreV1Api.class).readNamespacedConfigMap(configMapName, NAMESPACE).get();
// Then
assertAll("Reads expected configMap", () -> assertThat(result).isNotNull(), () -> assertThat(result.getKind()).isEqualTo("ConfigMap"), () -> assertThat(result.getMetadata().getCreationTimestamp()).isNotNull(), () -> assertThat(result.getMetadata().getResourceVersion()).isNotNull(), () -> assertThat(result.getData()).containsEntry("VAR_1", "VAR_1_VALUE"));
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.ConfigMap in project yakc by manusa.
the class ConfigMapIT method awaitCreateWatch.
@Test
@DisplayName("listNamespacedConfigMap.watch, should await for notification of newly created ConfigMap")
void awaitCreateWatch() throws IOException {
// Given
final AtomicBoolean hasError = new AtomicBoolean(false);
final AtomicBoolean hasCompleted = new AtomicBoolean(false);
// When
final Disposable d = KC.create(CoreV1Api.class).listNamespacedConfigMap(NAMESPACE).watch().filter(we -> we.getObject().getMetadata().getName().equals(configMapName)).takeUntil(we -> we.getType() == Type.ADDED).timeout(20, TimeUnit.SECONDS).subscribe(we -> hasCompleted.set(true), we -> hasError.set(true));
// Then
assertAll("Watch completed", () -> assertThat(d).isNotNull(), () -> assertThat(hasError.get()).as("Watch subscribe ended with an error").isFalse(), () -> assertThat(hasCompleted.get()).as("Watch subscribe did not complete").isTrue());
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.ConfigMap in project yakc by manusa.
the class ConfigMapIT method replaceNamespacedConfigMap.
@Test
@DisplayName("replaceNamespacedConfigMap, should replace existing ConfigMap data")
void replaceNamespacedConfigMap() throws IOException {
// Given
final ConfigMap existingConfigMap = KC.create(CoreV1Api.class).readNamespacedConfigMap(configMapName, NAMESPACE).get();
final String priorResourceVersion = existingConfigMap.getMetadata().getResourceVersion();
existingConfigMap.getMetadata().setResourceVersion(null);
existingConfigMap.setData(Collections.singletonMap("VAR_Z", "VAR_Z_VALUE"));
// When
final ConfigMap result = KC.create(CoreV1Api.class).replaceNamespacedConfigMap(configMapName, NAMESPACE, existingConfigMap).get();
// Then
assertAll("Replaced ConfigMap is as expected", () -> assertThat(result).isNotNull(), () -> assertThat(result.getMetadata().getResourceVersion()).isNotNull(), () -> assertThat(result.getMetadata().getResourceVersion()).isNotEqualTo(priorResourceVersion), () -> assertThat(result.getData()).hasSize(1), () -> assertThat(result.getData()).containsEntry("VAR_Z", "VAR_Z_VALUE"));
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.ConfigMap in project yakc by manusa.
the class ConfigMapIT method patchNamespacedConfigMap.
@Test
@DisplayName("patchNamespacedConfigMap, should patch labels of ConfigMap")
void patchNamespacedConfigMap() throws IOException {
// When
final ConfigMap result = KC.create(CoreV1Api.class).patchNamespacedConfigMap(configMapName, NAMESPACE, ConfigMap.builder().metadata(ObjectMeta.builder().putInLabels("patched", "label").build()).putInData("VAR_2", "VAR_2_VALUE_CHANGED").putInData("VAR_3", "VAR_3_VALUE").build()).get();
// Then
assertAll("Patched ConfigMap is as expected", () -> assertThat(result).isNotNull(), () -> assertThat(result.getMetadata().getLabels()).containsEntry("patched", "label"), () -> assertThat(result.getData()).containsEntry("VAR_1", "VAR_1_VALUE"), () -> assertThat(result.getData()).containsEntry("VAR_2", "VAR_2_VALUE_CHANGED"), () -> assertThat(result.getData()).containsEntry("VAR_3", "VAR_3_VALUE"));
}
Aggregations