mirror of https://github.com/apache/druid.git
Add labels to k8s jobs for the PodTemplateTaskAdapter (#14205)
* Add labels * Add prefix * remove newline * fix syntax * Update prefix
This commit is contained in:
parent
fb38085ddb
commit
eed5f4f291
|
@ -37,6 +37,7 @@ public class DruidK8sConstants
|
|||
public static final String JAVA_OPTS = "JAVA_OPTS";
|
||||
public static final String DRUID_HOST_ENV = "druid_host";
|
||||
public static final String DRUID_HOSTNAME_ENV = "HOSTNAME";
|
||||
public static final String DRUID_LABEL_PREFIX = "druid.";
|
||||
static final String LABEL_KEY = "druid.k8s.peons";
|
||||
static final Predicate<Throwable> IS_TRANSIENT = e -> e instanceof KubernetesResourceNotFoundException;
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ public class PodTemplateTaskAdapter implements TaskAdapter
|
|||
return new JobBuilder()
|
||||
.withNewMetadata()
|
||||
.withName(new K8sTaskId(task).getK8sTaskId())
|
||||
.addToLabels(getJobLabels(taskRunnerConfig))
|
||||
.addToLabels(getJobLabels(taskRunnerConfig, task))
|
||||
.addToAnnotations(getJobAnnotations(taskRunnerConfig, task))
|
||||
.endMetadata()
|
||||
.withNewSpec()
|
||||
|
@ -129,7 +129,7 @@ public class PodTemplateTaskAdapter implements TaskAdapter
|
|||
.editTemplate()
|
||||
.editOrNewMetadata()
|
||||
.addToAnnotations(getPodTemplateAnnotations(task))
|
||||
.addToLabels(getPodLabels(taskRunnerConfig))
|
||||
.addToLabels(getPodLabels(taskRunnerConfig, task))
|
||||
.endMetadata()
|
||||
.editSpec()
|
||||
.editFirstContainer()
|
||||
|
@ -224,9 +224,9 @@ public class PodTemplateTaskAdapter implements TaskAdapter
|
|||
);
|
||||
}
|
||||
|
||||
private Map<String, String> getPodLabels(KubernetesTaskRunnerConfig config)
|
||||
private Map<String, String> getPodLabels(KubernetesTaskRunnerConfig config, Task task)
|
||||
{
|
||||
return getJobLabels(config);
|
||||
return getJobLabels(config, task);
|
||||
}
|
||||
|
||||
private Map<String, String> getPodTemplateAnnotations(Task task) throws IOException
|
||||
|
@ -241,11 +241,15 @@ public class PodTemplateTaskAdapter implements TaskAdapter
|
|||
.build();
|
||||
}
|
||||
|
||||
private Map<String, String> getJobLabels(KubernetesTaskRunnerConfig config)
|
||||
private Map<String, String> getJobLabels(KubernetesTaskRunnerConfig config, Task task)
|
||||
{
|
||||
return ImmutableMap.<String, String>builder()
|
||||
.putAll(config.labels)
|
||||
.put(DruidK8sConstants.LABEL_KEY, "true")
|
||||
.put(getDruidLabel(DruidK8sConstants.TASK_ID), task.getId())
|
||||
.put(getDruidLabel(DruidK8sConstants.TASK_TYPE), task.getType())
|
||||
.put(getDruidLabel(DruidK8sConstants.TASK_GROUP_ID), task.getGroupId())
|
||||
.put(getDruidLabel(DruidK8sConstants.TASK_DATASOURCE), task.getDataSource())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -259,4 +263,9 @@ public class PodTemplateTaskAdapter implements TaskAdapter
|
|||
.put(DruidK8sConstants.TASK_DATASOURCE, task.getDataSource())
|
||||
.build();
|
||||
}
|
||||
|
||||
private String getDruidLabel(String baseLabel)
|
||||
{
|
||||
return DruidK8sConstants.DRUID_LABEL_PREFIX + baseLabel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,10 @@ metadata:
|
|||
name: "id"
|
||||
labels:
|
||||
druid.k8s.peons: "true"
|
||||
druid.task.id: "id"
|
||||
druid.task.type: "noop"
|
||||
druid.task.group.id: "id"
|
||||
druid.task.datasource: "datasource"
|
||||
annotations:
|
||||
task.id: "id"
|
||||
task.type: "noop"
|
||||
|
@ -17,6 +21,10 @@ spec:
|
|||
metadata:
|
||||
labels:
|
||||
druid.k8s.peons: "true"
|
||||
druid.task.id: "id"
|
||||
druid.task.type: "noop"
|
||||
druid.task.group.id: "id"
|
||||
druid.task.datasource: "datasource"
|
||||
annotations:
|
||||
task: "H4sIAAAAAAAAAEVOuQ4CIRD9l6kpVhObbY0xtrs2liOMSoKAHEZC+HeHrEczmXfmVUjFE4xgnfMgQCv++Qi4Bpf94QcVJpxdDrKbO4gLEBCyPeo70+vNMHBDnAhVWag/nihmkzh72s0cuuhANxfZYrMxAqSziV6s18aN9CkfK+ATtcGzNjqVfZ/0HRTokblEbdGjZBHGVWtvT9WXlc8AAAA="
|
||||
tls.enabled: "false"
|
||||
|
|
|
@ -4,6 +4,10 @@ metadata:
|
|||
name: "id"
|
||||
labels:
|
||||
druid.k8s.peons: "true"
|
||||
druid.task.id: "id"
|
||||
druid.task.type: "noop"
|
||||
druid.task.group.id: "id"
|
||||
druid.task.datasource: "datasource"
|
||||
annotations:
|
||||
task.id: "id"
|
||||
task.type: "noop"
|
||||
|
@ -17,6 +21,10 @@ spec:
|
|||
metadata:
|
||||
labels:
|
||||
druid.k8s.peons: "true"
|
||||
druid.task.id: "id"
|
||||
druid.task.type: "noop"
|
||||
druid.task.group.id: "id"
|
||||
druid.task.datasource: "datasource"
|
||||
annotations:
|
||||
task: "H4sIAAAAAAAAAEVOuQ4CIRD9l6kpVhObbY0xtrs2liOMSoKAHEZC+HeHrEczmXfmVUjFE4xgnfMgQCv++Qi4Bpf94QcVJpxdDrKbO4gLEBCyPeo70+vNMHBDnAhVWag/nihmkzh72s0cuuhANxfZYrMxAqSziV6s18aN9CkfK+ATtcGzNjqVfZ/0HRTokblEbdGjZBHGVWtvT9WXlc8AAAA="
|
||||
tls.enabled: "true"
|
||||
|
|
Loading…
Reference in New Issue