Fix k8sTaskExecutionContext setting configYaml (#15116)
* fixed the issue of obtaining kubeConfig of k8s tasks * removed excess files * removed excess files * formatted the code --------- Co-authored-by: xiangzihao <460888207@qq.com> Co-authored-by: Aaron Wang <wangweirao16@gmail.com>
This commit is contained in:
parent
159179ac95
commit
ce11674668
|
|
@ -22,7 +22,6 @@ import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.UNIQUE_L
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.common.enums.ResourceManagerType;
|
import org.apache.dolphinscheduler.common.enums.ResourceManagerType;
|
||||||
import org.apache.dolphinscheduler.common.thread.ThreadUtils;
|
import org.apache.dolphinscheduler.common.thread.ThreadUtils;
|
||||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.K8sTaskExecutionContext;
|
import org.apache.dolphinscheduler.plugin.task.api.K8sTaskExecutionContext;
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.TaskException;
|
import org.apache.dolphinscheduler.plugin.task.api.TaskException;
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
|
import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus;
|
||||||
|
|
@ -132,8 +131,6 @@ public class KubernetesApplicationManager implements ApplicationManager {
|
||||||
private KubernetesClient getClient(KubernetesApplicationManagerContext kubernetesApplicationManagerContext) {
|
private KubernetesClient getClient(KubernetesApplicationManagerContext kubernetesApplicationManagerContext) {
|
||||||
K8sTaskExecutionContext k8sTaskExecutionContext =
|
K8sTaskExecutionContext k8sTaskExecutionContext =
|
||||||
kubernetesApplicationManagerContext.getK8sTaskExecutionContext();
|
kubernetesApplicationManagerContext.getK8sTaskExecutionContext();
|
||||||
k8sTaskExecutionContext
|
|
||||||
.setConfigYaml(JSONUtils.getNodeString(k8sTaskExecutionContext.getConnectionParams(), "kubeConfig"));
|
|
||||||
return cacheClientMap.computeIfAbsent(kubernetesApplicationManagerContext.getLabelValue(),
|
return cacheClientMap.computeIfAbsent(kubernetesApplicationManagerContext.getLabelValue(),
|
||||||
key -> new KubernetesClientBuilder()
|
key -> new KubernetesClientBuilder()
|
||||||
.withConfig(Config.fromKubeconfig(k8sTaskExecutionContext.getConfigYaml())).build());
|
.withConfig(Config.fromKubeconfig(k8sTaskExecutionContext.getConfigYaml())).build());
|
||||||
|
|
|
||||||
|
|
@ -293,9 +293,7 @@ public class K8sTaskExecutor extends AbstractK8sTaskExecutor {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
K8sTaskExecutionContext k8sTaskExecutionContext = taskRequest.getK8sTaskExecutionContext();
|
K8sTaskExecutionContext k8sTaskExecutionContext = taskRequest.getK8sTaskExecutionContext();
|
||||||
String connectionParams = k8sTaskExecutionContext.getConnectionParams();
|
String configYaml = k8sTaskExecutionContext.getConfigYaml();
|
||||||
String kubeConfig = JSONUtils.getNodeString(connectionParams, "kubeConfig");
|
|
||||||
String configYaml = kubeConfig;
|
|
||||||
k8sUtils.buildClient(configYaml);
|
k8sUtils.buildClient(configYaml);
|
||||||
submitJob2k8s(k8sParameterStr);
|
submitJob2k8s(k8sParameterStr);
|
||||||
parsePodLogOutput();
|
parsePodLogOutput();
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,12 @@
|
||||||
package org.apache.dolphinscheduler.plugin.task.api.parameters;
|
package org.apache.dolphinscheduler.plugin.task.api.parameters;
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||||
|
import org.apache.dolphinscheduler.plugin.task.api.K8sTaskExecutionContext;
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
|
import org.apache.dolphinscheduler.plugin.task.api.enums.Direct;
|
||||||
|
import org.apache.dolphinscheduler.plugin.task.api.enums.ResourceType;
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
|
import org.apache.dolphinscheduler.plugin.task.api.model.Property;
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
|
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
|
||||||
|
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.DataSourceParameters;
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper;
|
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper;
|
||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
|
@ -86,6 +89,16 @@ public abstract class AbstractParameters implements IParameters {
|
||||||
return localParametersMaps;
|
return localParametersMaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public K8sTaskExecutionContext generateK8sTaskExecutionContext(ResourceParametersHelper parametersHelper,
|
||||||
|
int datasource) {
|
||||||
|
DataSourceParameters dataSourceParameters =
|
||||||
|
(DataSourceParameters) parametersHelper.getResourceParameters(ResourceType.DATASOURCE, datasource);
|
||||||
|
K8sTaskExecutionContext k8sTaskExecutionContext = new K8sTaskExecutionContext();
|
||||||
|
k8sTaskExecutionContext.setConnectionParams(
|
||||||
|
Objects.nonNull(dataSourceParameters) ? dataSourceParameters.getConnectionParams() : null);
|
||||||
|
return k8sTaskExecutionContext;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get input local parameters map if the param direct is IN
|
* get input local parameters map if the param direct is IN
|
||||||
* @return parameters map
|
* @return parameters map
|
||||||
|
|
|
||||||
|
|
@ -17,19 +17,16 @@
|
||||||
|
|
||||||
package org.apache.dolphinscheduler.plugin.task.api.parameters;
|
package org.apache.dolphinscheduler.plugin.task.api.parameters;
|
||||||
|
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.K8sTaskExecutionContext;
|
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.enums.ResourceType;
|
import org.apache.dolphinscheduler.plugin.task.api.enums.ResourceType;
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.model.Label;
|
import org.apache.dolphinscheduler.plugin.task.api.model.Label;
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.model.NodeSelectorExpression;
|
import org.apache.dolphinscheduler.plugin.task.api.model.NodeSelectorExpression;
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
|
import org.apache.dolphinscheduler.plugin.task.api.model.ResourceInfo;
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.DataSourceParameters;
|
|
||||||
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper;
|
import org.apache.dolphinscheduler.plugin.task.api.parameters.resource.ResourceParametersHelper;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -58,18 +55,12 @@ public class K8sTaskParameters extends AbstractParameters {
|
||||||
public boolean checkParameters() {
|
public boolean checkParameters() {
|
||||||
return StringUtils.isNotEmpty(image);
|
return StringUtils.isNotEmpty(image);
|
||||||
}
|
}
|
||||||
public K8sTaskExecutionContext generateExtendedContext(ResourceParametersHelper parametersHelper) {
|
|
||||||
DataSourceParameters dataSourceParameters =
|
|
||||||
(DataSourceParameters) parametersHelper.getResourceParameters(ResourceType.DATASOURCE, datasource);
|
|
||||||
K8sTaskExecutionContext k8sTaskExecutionContext = new K8sTaskExecutionContext();
|
|
||||||
k8sTaskExecutionContext.setConnectionParams(
|
|
||||||
Objects.nonNull(dataSourceParameters) ? dataSourceParameters.getConnectionParams() : null);
|
|
||||||
return k8sTaskExecutionContext;
|
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
public List<ResourceInfo> getResourceFilesList() {
|
public List<ResourceInfo> getResourceFilesList() {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceParametersHelper getResources() {
|
public ResourceParametersHelper getResources() {
|
||||||
ResourceParametersHelper resources = super.getResources();
|
ResourceParametersHelper resources = super.getResources();
|
||||||
|
|
|
||||||
|
|
@ -70,14 +70,16 @@ public class K8sTask extends AbstractK8sTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
k8sTaskExecutionContext =
|
k8sTaskExecutionContext =
|
||||||
k8sTaskParameters.generateExtendedContext(taskExecutionContext.getResourceParametersHelper());
|
k8sTaskParameters.generateK8sTaskExecutionContext(taskExecutionContext.getResourceParametersHelper(),
|
||||||
taskRequest.setK8sTaskExecutionContext(k8sTaskExecutionContext);
|
k8sTaskParameters.getDatasource());
|
||||||
k8sConnectionParam =
|
k8sConnectionParam =
|
||||||
(K8sConnectionParam) DataSourceUtils.buildConnectionParams(DbType.valueOf(k8sTaskParameters.getType()),
|
(K8sConnectionParam) DataSourceUtils.buildConnectionParams(DbType.valueOf(k8sTaskParameters.getType()),
|
||||||
k8sTaskExecutionContext.getConnectionParams());
|
k8sTaskExecutionContext.getConnectionParams());
|
||||||
String kubeConfig = k8sConnectionParam.getKubeConfig();
|
String kubeConfig = k8sConnectionParam.getKubeConfig();
|
||||||
k8sTaskParameters.setNamespace(k8sConnectionParam.getNamespace());
|
k8sTaskParameters.setNamespace(k8sConnectionParam.getNamespace());
|
||||||
k8sTaskParameters.setKubeConfig(kubeConfig);
|
k8sTaskParameters.setKubeConfig(kubeConfig);
|
||||||
|
k8sTaskExecutionContext.setConfigYaml(kubeConfig);
|
||||||
|
taskRequest.setK8sTaskExecutionContext(k8sTaskExecutionContext);
|
||||||
log.info("Initialize k8s task params:{}", JSONUtils.toPrettyJsonString(k8sTaskParameters));
|
log.info("Initialize k8s task params:{}", JSONUtils.toPrettyJsonString(k8sTaskParameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue