mateczagany commented on code in PR #677:
URL: 
https://github.com/apache/flink-kubernetes-operator/pull/677#discussion_r1341955135


##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/reconciler/deployment/AbstractFlinkResourceReconciler.java:
##########
@@ -174,6 +182,32 @@ public void reconcile(FlinkResourceContext<CR> ctx) throws 
Exception {
         }
     }
 
+    private void scaling(FlinkResourceContext<CR> ctx) throws Exception {
+        KubernetesJobAutoScalerContext autoScalerContext = 
ctx.getJobAutoScalerContext();
+
+        if (autoscalerDisabled(ctx)) {
+            autoScalerContext.getConfiguration().set(AUTOSCALER_ENABLED, 
false);
+            resourceScaler.scale(autoScalerContext);
+            return;
+        }
+        if (waitingForRunning(ctx.getResource().getStatus())) {
+            LOG.info("Autoscaler is waiting for  stable, running state");
+            resourceScaler.cleanup(autoScalerContext.getJobKey());
+            return;

Review Comment:
   Previously the logic was to still apply the parallelism overrides to the 
resource even though the resource is not running, but that's not the case here 
anymore. 
   
   This will cause the in-place scaling to fail because during the next 
reconciliation the spec will not contain the parallelism overrides as the job 
is not in a running state.



##########
flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/autoscaler/ConfigMapStore.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.kubernetes.operator.autoscaler;
+
+import org.apache.flink.annotation.VisibleForTesting;
+import org.apache.flink.kubernetes.utils.Constants;
+import org.apache.flink.util.Preconditions;
+
+import io.fabric8.kubernetes.api.model.ConfigMap;
+import io.fabric8.kubernetes.api.model.HasMetadata;
+import io.fabric8.kubernetes.api.model.ObjectMeta;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.javaoperatorsdk.operator.processing.event.ResourceID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nonnull;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+/** The config map store, it's responsible for store/get/remove the state with 
String type. */
+public class ConfigMapStore {
+
+    private static final Logger LOG = 
LoggerFactory.getLogger(KubernetesAutoScalerStateStore.class);
+
+    private static final String LABEL_COMPONENT_AUTOSCALER = "autoscaler";
+
+    private final KubernetesClient kubernetesClient;
+
+    /**
+     * The cache for each resourceId may be in three situations: 1. The 
resourceId isn't exist :
+     * ConfigMap isn't loaded from kubernetes, or it's removed. 2. The 
resourceId is exist, and
+     * value is the Optional.empty() : We have loaded the ConfigMap from 
kubernetes, but the
+     * ConfigMap isn't created at kubernetes side. 3. The resourceId is exist, 
and the Optional
+     * isn't empty : We have loaded the ConfigMap from kubernetes, it may be 
not same with
+     * kubernetes side due to it's not flushed after updating.
+     */
+    private final ConcurrentHashMap<ResourceID, Optional<ConfigMap>> cache =
+            new ConcurrentHashMap<>();
+
+    public ConfigMapStore(KubernetesClient kubernetesClient) {
+        this.kubernetesClient = kubernetesClient;
+    }
+
+    protected void putSerializedState(
+            KubernetesJobAutoScalerContext jobContext, String key, String 
value) {
+        getOrCreateState(jobContext).put(key, value);
+    }
+
+    protected Optional<String> getSerializedState(
+            KubernetesJobAutoScalerContext jobContext, String key) {
+        return getConfigMap(jobContext).map(configMap -> 
configMap.getData().get(key));
+    }
+
+    protected void removeSerializedState(KubernetesJobAutoScalerContext 
jobContext, String key) {
+        getConfigMap(jobContext)
+                .ifPresentOrElse(
+                        configMap -> configMap.getData().remove(key),
+                        () -> {
+                            throw new IllegalStateException(
+                                    "The configMap isn't created, so the 
remove is unavailable.");
+                        });
+    }
+
+    public void flush(KubernetesJobAutoScalerContext jobContext) {
+        Optional<ConfigMap> configMapOpt = cache.get(jobContext.getJobKey());
+        Preconditions.checkState(

Review Comment:
   This will fail during the autoscale stabilization period as we won't collect 
any metrics there. I think we could just simply log here and not throw an error.



-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to