wangyang0918 commented on a change in pull request #13644:
URL: https://github.com/apache/flink/pull/13644#discussion_r507421985
##########
File path:
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/kubeclient/TestingFlinkKubeClient.java
##########
@@ -103,6 +121,52 @@ public KubernetesWatch watchPodsAndDoCallback(Map<String,
String> labels, WatchC
return watchPodsAndDoCallbackFunction.apply(labels,
podCallbackHandler);
}
+ @Override
+ public CompletableFuture<Void> createConfigMap(KubernetesConfigMap
configMap) {
+ configMapStore.putIfAbsent(configMap.getName(), configMap);
+ return CompletableFuture.completedFuture(null);
+ }
+
+ @Override
+ public Optional<KubernetesConfigMap> getConfigMap(String name) {
+ final KubernetesConfigMap configMap = configMapStore.get(name);
+ if (configMap == null) {
+ return Optional.empty();
+ }
+ return Optional.of(new
MockKubernetesConfigMap(configMap.getName(), new
HashMap<>(configMap.getData())));
+ }
+
+ @Override
+ public CompletableFuture<Boolean> checkAndUpdateConfigMap(
+ String configMapName,
+ Predicate<KubernetesConfigMap> checker,
+ FunctionWithException<KubernetesConfigMap,
KubernetesConfigMap, ?> function) {
+ return
getConfigMap(configMapName).map(FunctionUtils.uncheckedFunction(
+ configMap -> {
+ final boolean shouldUpdate =
checker.test(configMap);
+ if (shouldUpdate) {
+ configMapStore.put(configMap.getName(),
function.apply(configMap));
+ }
+ return
CompletableFuture.completedFuture(shouldUpdate);
+ }))
+ .orElseThrow(() -> new FlinkRuntimeException("ConfigMap
" + configMapName + " not exists."));
+ }
Review comment:
Since all the new introduced operations are ConfigMap related. So I add
a new field `configMapStore` to manage the state. It is more natural to
create/update/read/delete the ConfigMap state.
Just like you say, if we want to delete a ConfigMap externally. We just need
to call `configMapStore#remove(name)`. And the `configMapStore` in
`TestingFlinkKubeClient#Builder` could be passed externally.
If you insist, I could add several `Function`s instead.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]