tillrohrmann commented on a change in pull request #13644:
URL: https://github.com/apache/flink/pull/13644#discussion_r509057766



##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/kubeclient/Fabric8FlinkKubeClient.java
##########
@@ -219,6 +230,71 @@ public KubernetesWatch watchPodsAndDoCallback(
                                .watch(new 
KubernetesPodsWatcher(podCallbackHandler)));
        }
 
+       @Override
+       public CompletableFuture<Void> createConfigMap(KubernetesConfigMap 
configMap) {
+               final String configMapName = configMap.getName();
+               return CompletableFuture.runAsync(
+                       () -> 
this.internalClient.configMaps().inNamespace(namespace).create(configMap.getInternalResource()),
+                       kubeClientExecutorService)
+                       .whenComplete((ignored, throwable) -> {
+                               if (throwable != null) {
+                                       throw new FlinkRuntimeException("Failed 
to create ConfigMap " + configMapName, throwable);
+                               }
+                       });
+       }
+
+       @Override
+       public Optional<KubernetesConfigMap> getConfigMap(String name) {
+               final ConfigMap configMap = 
this.internalClient.configMaps().inNamespace(namespace).withName(name).get();
+               return configMap == null ? Optional.empty() : Optional.of(new 
KubernetesConfigMap(configMap));
+       }
+
+       @Override
+       public CompletableFuture<Boolean> checkAndUpdateConfigMap(
+                       String configMapName,
+                       FunctionWithException<KubernetesConfigMap, 
Optional<KubernetesConfigMap>, ?> function) {
+               return FutureUtils.retry(
+                       () -> CompletableFuture.supplyAsync(
+                               () -> getConfigMap(configMapName)
+                                       
.map(FunctionUtils.uncheckedFunction(configMap -> {
+                                               final boolean updated = 
function.apply(configMap).map(
+                                                       updatedConfigMap -> {
+                                                               
this.internalClient.configMaps()
+                                                                       
.inNamespace(namespace)
+                                                                       
.createOrReplace(updatedConfigMap.getInternalResource());
+                                                               return true;
+                                                       }).orElse(false);
+                                               if (!updated) {
+                                                       LOG.warn("Trying to 
update ConfigMap {} to {} without checking pass, ignoring.",
+                                                               
configMap.getName(), configMap.getData());
+                                               }
+                                               return updated;
+                                       }))
+                                       .orElseThrow(
+                                               () -> new 
FlinkRuntimeException("ConfigMap " + configMapName + " not exists.")),

Review comment:
       I think this is independent of this question because 
`checkAndUpdateConfigMap` should never create a non-existing config map 
according to the code. If `getConfigMap()` returns `Optional.empty()` then we 
will throw the `FlinkRuntimeException`, retry and end up again receiving an 
`Optional.empty()`.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to