tillrohrmann commented on a change in pull request #13644: URL: https://github.com/apache/flink/pull/13644#discussion_r509059229
########## 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 method is also lacking test coverage for exactly a case where `getConfigMap` returns `Optional.empty` or where ``` this.internalClient.configMaps() .inNamespace(namespace) .createOrReplace(updatedConfigMap.getInternalResource()); ``` fails. ---------------------------------------------------------------- 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