diff --git a/docs/docs/en/guide/task/kubernetes.md b/docs/docs/en/guide/task/kubernetes.md index f5b06d3bc8..316a82adf7 100644 --- a/docs/docs/en/guide/task/kubernetes.md +++ b/docs/docs/en/guide/task/kubernetes.md @@ -16,17 +16,17 @@ K8S task type used to execute a batch task. In this task, the worker submits the - Please refer to [DolphinScheduler Task Parameters Appendix](appendix.md) `Default Task Parameters` section for default parameters. -| **Parameter** | **Description** | -|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| Namespace | The namespace for running k8s task. | -| Min CPU | Minimum CPU requirement for running k8s task. | -| Min Memory | Minimum memory requirement for running k8s task. | -| Image | The registry url for image. | -| Command | The container execution command (yaml-style array), for example: ["printenv"] | -| Args | The args of execution command (yaml-style array), for example: ["HOSTNAME", "KUBERNETES_PORT"] | -| Custom label | The customized labels for k8s Job. | -| Node selector | The label selectors for running k8s pod. Different value in value set should be seperated by command, for example: `value1,value2`. You can refer to https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/node-selector-requirement/ for configuration of different operators. | -| Custom parameter | It is a local user-defined parameter for K8S task, these params will pass to container as environment variables. | +| **Parameter** | **Description** | +|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Namespace | The namespace for running k8s task. | +| Min CPU | Minimum CPU requirement for running k8s task. | +| Min Memory | Minimum memory requirement for running k8s task. | +| Image | The registry url for image. | +| Command | The container execution command (yaml-style array), for example: ["printenv"] | +| Args | The args of execution command (yaml-style array), for example: ["HOSTNAME", "KUBERNETES_PORT"] | +| Custom label | The customized labels for k8s Job. | +| Node selector | The label selectors for running k8s pod. Different value in value set should be seperated by comma, for example: `value1,value2`. You can refer to https://kubernetes.io/docs/reference/kubernetes-api/common-definitions/node-selector-requirement/ for configuration of different operators. | +| Custom parameter | It is a local user-defined parameter for K8S task, these params will pass to container as environment variables. | ## Task Example diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/main/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/main/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTask.java index d95864d662..d35c1999cf 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/main/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/main/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTask.java @@ -18,7 +18,6 @@ package org.apache.dolphinscheduler.plugin.task.k8s; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.CLUSTER; -import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.COMMA; import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.NAMESPACE_NAME; import org.apache.dolphinscheduler.common.utils.JSONUtils; @@ -110,7 +109,7 @@ public class K8sTask extends AbstractK8sTask { expression.getKey(), expression.getOperator(), StringUtils.isEmpty(expression.getValues()) ? Collections.emptyList() - : Arrays.asList(expression.getValues().trim().split(COMMA)))) + : Arrays.asList(expression.getValues().trim().split("\\s*,\\s*")))) .collect(Collectors.toList()); } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTaskTest.java index 199203a4ef..a0fda89e33 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-k8s/src/test/java/org/apache/dolphinscheduler/plugin/task/k8s/K8sTaskTest.java @@ -26,6 +26,7 @@ import org.apache.dolphinscheduler.plugin.task.api.model.NodeSelectorExpression; import org.apache.dolphinscheduler.plugin.task.api.model.Property; import org.apache.dolphinscheduler.plugin.task.api.parameters.K8sTaskParameters; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -35,6 +36,8 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import io.fabric8.kubernetes.api.model.NodeSelectorRequirement; + public class K8sTaskTest { private K8sTaskParameters k8sTaskParameters = null; @@ -107,4 +110,19 @@ public class K8sTaskTest { Assertions.assertEquals(expectedStr, result); } + @Test + public void testConvertToNodeSelectorRequirements() { + NodeSelectorExpression expression = new NodeSelectorExpression(); + expression.setKey("key"); + expression.setOperator("In"); + expression.setValues("123, 1234"); + List nodeSelectorRequirements = + k8sTask.convertToNodeSelectorRequirements(Arrays.asList(expression)); + Assertions.assertEquals(1, nodeSelectorRequirements.size()); + List expectedList = new ArrayList<>(); + expectedList.add("123"); + expectedList.add("1234"); + Assertions.assertEquals(expectedList, nodeSelectorRequirements.get(0).getValues()); + } + }