wangyang0918 commented on a change in pull request #13644:
URL: https://github.com/apache/flink/pull/13644#discussion_r508994167
##########
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:
If we agree to not handle the externally deletion/update, then we do not
need to retry if the ConfigMap not exists.
----------------------------------------------------------------
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]