zentol commented on a change in pull request #15056:
URL: https://github.com/apache/flink/pull/15056#discussion_r585531516



##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/utils/Constants.java
##########
@@ -105,4 +103,10 @@
     public static final String POD_TEMPLATE_DIR_IN_POD = 
"/opt/flink/pod-template";
     public static final String POD_TEMPLATE_CONFIG_MAP_PREFIX = 
"pod-template-";
     public static final String POD_TEMPLATE_VOLUME = "pod-template-volume";
+
+    // Kubernetes start scripts
+    public static final String KUBERNETES_JOB_MANAGER_SCRIPT_PATH =
+            "$FLINK_HOME/bin/kubernetes-jobmanager.sh";

Review comment:
       ```suggestion
               "kubernetes-jobmanager.sh";
   ```
   This _should_ work because `$FLINK_HOME/bin` is added to `PATH` 
(https://github.com/apache/flink-docker/blob/master/1.12/scala_2.11-java11-debian/Dockerfile#L54).

##########
File path: 
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/kubeclient/decorators/CmdJobManagerDecoratorTest.java
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.kubeclient.decorators;
+
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.core.testutils.FlinkMatchers;
+import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
+import org.apache.flink.kubernetes.configuration.KubernetesDeploymentTarget;
+import org.apache.flink.kubernetes.kubeclient.FlinkPod;
+import org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerTestBase;
+import org.apache.flink.kubernetes.utils.Constants;
+import org.apache.flink.kubernetes.utils.KubernetesUtils;
+
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/** General tests for the {@link CmdJobManagerDecorator}. */
+public class CmdJobManagerDecoratorTest extends KubernetesJobManagerTestBase {
+
+    private CmdJobManagerDecorator cmdJobManagerDecorator;
+
+    @Override
+    protected void onSetup() throws Exception {
+        super.onSetup();
+
+        this.cmdJobManagerDecorator = new 
CmdJobManagerDecorator(kubernetesJobManagerParameters);
+    }
+
+    @Test
+    public void testContainerIsDecorated() {
+        flinkConfig.set(DeploymentOptions.TARGET, 
KubernetesDeploymentTarget.SESSION.getName());
+        final FlinkPod resultFlinkPod = 
cmdJobManagerDecorator.decorateFlinkPod(baseFlinkPod);
+        assertThat(
+                resultFlinkPod.getPodWithoutMainContainer(),
+                is(equalTo(baseFlinkPod.getPodWithoutMainContainer())));
+        assertThat(
+                resultFlinkPod.getMainContainer(), 
not(equalTo(baseFlinkPod.getMainContainer())));
+    }
+
+    @Test
+    public void testSessionClusterCommandsAndArgs() {
+        
testJobManagerCommandsAndArgs(KubernetesDeploymentTarget.SESSION.getName());
+    }
+
+    @Test
+    public void testApplicationClusterCommandsAndArgs() {
+        
testJobManagerCommandsAndArgs(KubernetesDeploymentTarget.APPLICATION.getName());
+    }
+
+    @Test
+    public void testUnsupportedDeploymentTargetShouldFail() {
+        try {
+            testJobManagerCommandsAndArgs("unsupported-deployment-target");
+            fail("Decorator should fail when unsupported deployment target is 
set.");
+        } catch (Exception ex) {
+            assertThat(ex, 
FlinkMatchers.containsCause(IllegalArgumentException.class));
+        }
+    }
+
+    private void testJobManagerCommandsAndArgs(String target) {
+        flinkConfig.set(DeploymentOptions.TARGET, target);
+        final FlinkPod resultFlinkPod = 
cmdJobManagerDecorator.decorateFlinkPod(baseFlinkPod);
+        final String entryCommand = 
flinkConfig.get(KubernetesConfigOptions.KUBERNETES_ENTRY_PATH);
+        assertThat(
+                resultFlinkPod.getMainContainer().getCommand(), 
containsInAnyOrder(entryCommand));
+        List<String> flinkCommands =
+                KubernetesUtils.getStartCommandWithBashWrapper(
+                        Constants.KUBERNETES_JOB_MANAGER_SCRIPT_PATH + " " + 
target);
+        assertThat(
+                resultFlinkPod.getMainContainer().getArgs(),
+                containsInAnyOrder(flinkCommands.toArray()));

Review comment:
       isn't the order somewhat important?

##########
File path: 
flink-kubernetes/src/main/java/org/apache/flink/kubernetes/utils/Constants.java
##########
@@ -105,4 +103,10 @@
     public static final String POD_TEMPLATE_DIR_IN_POD = 
"/opt/flink/pod-template";
     public static final String POD_TEMPLATE_CONFIG_MAP_PREFIX = 
"pod-template-";
     public static final String POD_TEMPLATE_VOLUME = "pod-template-volume";
+
+    // Kubernetes start scripts
+    public static final String KUBERNETES_JOB_MANAGER_SCRIPT_PATH =
+            "$FLINK_HOME/bin/kubernetes-jobmanager.sh";
+    public static final String KUBERNETES_TASK_MANAGER_SCRIPT_PATH =
+            "$FLINK_HOME/bin/kubernetes-taskmanager.sh";

Review comment:
       ```suggestion
               "kubernetes-taskmanager.sh";
   ```
   see above

##########
File path: flink-dist/src/main/flink-bin/bin/config.sh
##########
@@ -545,6 +545,34 @@ $FLINK_INHERITED_LOGS
 
 JM_RESOURCE_PARAMS extraction logs:
 jvm_params: $jvm_params
+dynamic_configs: $DYNAMIC_PARAMETERS
+logs: $logging_output
+"
+}
+
+parseTmArgsAndExportLogs() {
+  java_utils_output=$(runBashJavaUtilsCmd GET_TM_RESOURCE_PARAMS 
"${FLINK_CONF_DIR}" "$FLINK_BIN_DIR/bash-java-utils.jar:$(findFlinkDistJar)" 
"${ARGS[@]}")

Review comment:
       Can we deduplicate this a bit?
   the only differences appear to be `GET_TM_RESOURCE_PARAMS` and `"$@"` vs 
`"${ARGS[@]}"`

##########
File path: 
flink-kubernetes/src/test/java/org/apache/flink/kubernetes/kubeclient/decorators/CmdJobManagerDecoratorTest.java
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.kubeclient.decorators;
+
+import org.apache.flink.configuration.DeploymentOptions;
+import org.apache.flink.core.testutils.FlinkMatchers;
+import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
+import org.apache.flink.kubernetes.configuration.KubernetesDeploymentTarget;
+import org.apache.flink.kubernetes.kubeclient.FlinkPod;
+import org.apache.flink.kubernetes.kubeclient.KubernetesJobManagerTestBase;
+import org.apache.flink.kubernetes.utils.Constants;
+import org.apache.flink.kubernetes.utils.KubernetesUtils;
+
+import org.junit.Test;
+
+import java.util.List;
+
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+/** General tests for the {@link CmdJobManagerDecorator}. */
+public class CmdJobManagerDecoratorTest extends KubernetesJobManagerTestBase {
+
+    private CmdJobManagerDecorator cmdJobManagerDecorator;
+
+    @Override
+    protected void onSetup() throws Exception {
+        super.onSetup();
+
+        this.cmdJobManagerDecorator = new 
CmdJobManagerDecorator(kubernetesJobManagerParameters);
+    }
+
+    @Test
+    public void testContainerIsDecorated() {
+        flinkConfig.set(DeploymentOptions.TARGET, 
KubernetesDeploymentTarget.SESSION.getName());
+        final FlinkPod resultFlinkPod = 
cmdJobManagerDecorator.decorateFlinkPod(baseFlinkPod);
+        assertThat(
+                resultFlinkPod.getPodWithoutMainContainer(),
+                is(equalTo(baseFlinkPod.getPodWithoutMainContainer())));
+        assertThat(
+                resultFlinkPod.getMainContainer(), 
not(equalTo(baseFlinkPod.getMainContainer())));
+    }
+
+    @Test
+    public void testSessionClusterCommandsAndArgs() {
+        
testJobManagerCommandsAndArgs(KubernetesDeploymentTarget.SESSION.getName());
+    }
+
+    @Test
+    public void testApplicationClusterCommandsAndArgs() {
+        
testJobManagerCommandsAndArgs(KubernetesDeploymentTarget.APPLICATION.getName());
+    }
+
+    @Test
+    public void testUnsupportedDeploymentTargetShouldFail() {
+        try {
+            testJobManagerCommandsAndArgs("unsupported-deployment-target");
+            fail("Decorator should fail when unsupported deployment target is 
set.");
+        } catch (Exception ex) {
+            assertThat(ex, 
FlinkMatchers.containsCause(IllegalArgumentException.class));
+        }
+    }

Review comment:
       ```suggestion
       @Test(expected = IllegalArgumentException.class)
       public void testUnsupportedDeploymentTargetShouldFail() {
           testJobManagerCommandsAndArgs("unsupported-deployment-target");
       }
   ```




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