wangyang0918 commented on a change in pull request #13644:
URL: https://github.com/apache/flink/pull/13644#discussion_r509856352
##########
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:
What I mean is the ConfigMap could be created in the
`KubernetesLeaderElectionService#Watcher`. So even the first we get a
`Optional.empty()`, we could a get correct ConfigMap by retrying.
I will add a two tests here.
* ConfigMap always does not exists and retry failed
* ConfigMap exists at the very begging and retry successfully
----------------------------------------------------------------
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]