KubernetesHelper#removeConfigMapEntry
This commit is contained in:
committed by
Ioannis Canellos
parent
fa91910cee
commit
cf243070c4
@@ -79,15 +79,27 @@ public class KubernetesHelper {
|
||||
.create(newConfigMap);
|
||||
}
|
||||
|
||||
public void updateConfigMap(ConfigMap configMap, Map<String, String> newData) {
|
||||
public void updateConfigMapEntry(ConfigMap configMap, Map<String, String> newData) {
|
||||
ConfigMap newConfigMap = new ConfigMapBuilder(configMap)
|
||||
.addToData(newData)
|
||||
.build();
|
||||
|
||||
updateConfigMap(configMap, newConfigMap);
|
||||
}
|
||||
|
||||
public void removeConfigMapEntry(ConfigMap configMap, String key) {
|
||||
ConfigMap newConfigMap = new ConfigMapBuilder(configMap)
|
||||
.removeFromData(key)
|
||||
.build();
|
||||
|
||||
updateConfigMap(configMap, newConfigMap);
|
||||
}
|
||||
|
||||
private void updateConfigMap(ConfigMap oldConfigMap, ConfigMap newConfigMap) {
|
||||
kubernetesClient.configMaps()
|
||||
.inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace()))
|
||||
.withName(leaderProperties.getConfigMapName())
|
||||
.lockResourceVersion(configMap.getMetadata().getResourceVersion())
|
||||
.lockResourceVersion(oldConfigMap.getMetadata().getResourceVersion())
|
||||
.replace(newConfigMap);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ public class KubernetesHelperTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateConfigMap() {
|
||||
public void shouldUpdateConfigMapEntry() {
|
||||
given(mockConfigMap.getMetadata()).willReturn(mockObjectMeta);
|
||||
given(mockObjectMeta.getResourceVersion()).willReturn("test-version");
|
||||
|
||||
@@ -153,7 +153,7 @@ public class KubernetesHelperTest {
|
||||
given(configMapResource.lockResourceVersion("test-version")).willReturn(configMapReplaceable);
|
||||
|
||||
Map<String, String> data = Collections.singletonMap("test-key", "test-value");
|
||||
kubernetesHelper.updateConfigMap(mockConfigMap, data);
|
||||
kubernetesHelper.updateConfigMapEntry(mockConfigMap, data);
|
||||
|
||||
ArgumentCaptor<ConfigMap> configMapCaptor = ArgumentCaptor.forClass(ConfigMap.class);
|
||||
verify(configMapReplaceable).replace(configMapCaptor.capture());
|
||||
@@ -162,4 +162,25 @@ public class KubernetesHelperTest {
|
||||
assertThat(configMap.getData()).containsEntry("test-key", "test-value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveConfigMapEntry() {
|
||||
Map<String, String> data = Collections.singletonMap("test-key", "test-value");
|
||||
given(mockConfigMap.getData()).willReturn(data);
|
||||
given(mockConfigMap.getMetadata()).willReturn(mockObjectMeta);
|
||||
given(mockObjectMeta.getResourceVersion()).willReturn("test-version");
|
||||
|
||||
given(mockKubernetesClient.configMaps()).willReturn(configMapMixedOperation);
|
||||
given(configMapMixedOperation.inNamespace(NAMESPACE)).willReturn(configMapNonNamespaceOperation);
|
||||
given(configMapNonNamespaceOperation.withName(NAME)).willReturn(configMapResource);
|
||||
given(configMapResource.lockResourceVersion("test-version")).willReturn(configMapReplaceable);
|
||||
|
||||
kubernetesHelper.removeConfigMapEntry(mockConfigMap, "test-key");
|
||||
|
||||
ArgumentCaptor<ConfigMap> configMapCaptor = ArgumentCaptor.forClass(ConfigMap.class);
|
||||
verify(configMapReplaceable).replace(configMapCaptor.capture());
|
||||
|
||||
ConfigMap configMap = configMapCaptor.getValue();
|
||||
assertThat(configMap.getData()).doesNotContainKeys("test-key");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user