fix: trim node selector requirement value (#14307)
(cherry picked from commit b7fb393eed)
This commit is contained in:
parent
b659f1af7a
commit
1f8a77d79d
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<NodeSelectorRequirement> nodeSelectorRequirements =
|
||||
k8sTask.convertToNodeSelectorRequirements(Arrays.asList(expression));
|
||||
Assertions.assertEquals(1, nodeSelectorRequirements.size());
|
||||
List<String> expectedList = new ArrayList<>();
|
||||
expectedList.add("123");
|
||||
expectedList.add("1234");
|
||||
Assertions.assertEquals(expectedList, nodeSelectorRequirements.get(0).getValues());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue