diff --git a/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/DruidK8sConstants.java b/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/DruidK8sConstants.java index 5a7ead08aaa..0a0beba7daa 100644 --- a/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/DruidK8sConstants.java +++ b/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/DruidK8sConstants.java @@ -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 IS_TRANSIENT = e -> e instanceof KubernetesResourceNotFoundException; } diff --git a/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/PodTemplateTaskAdapter.java b/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/PodTemplateTaskAdapter.java index 8aae3b39dda..ed671106c37 100644 --- a/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/PodTemplateTaskAdapter.java +++ b/extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/PodTemplateTaskAdapter.java @@ -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 getPodLabels(KubernetesTaskRunnerConfig config) + private Map getPodLabels(KubernetesTaskRunnerConfig config, Task task) { - return getJobLabels(config); + return getJobLabels(config, task); } private Map getPodTemplateAnnotations(Task task) throws IOException @@ -241,11 +241,15 @@ public class PodTemplateTaskAdapter implements TaskAdapter .build(); } - private Map getJobLabels(KubernetesTaskRunnerConfig config) + private Map getJobLabels(KubernetesTaskRunnerConfig config, Task task) { return ImmutableMap.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; + } } diff --git a/extensions-contrib/kubernetes-overlord-extensions/src/test/resources/expectedNoopJob.yaml b/extensions-contrib/kubernetes-overlord-extensions/src/test/resources/expectedNoopJob.yaml index f72dbd46659..b131b286527 100644 --- a/extensions-contrib/kubernetes-overlord-extensions/src/test/resources/expectedNoopJob.yaml +++ b/extensions-contrib/kubernetes-overlord-extensions/src/test/resources/expectedNoopJob.yaml @@ -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" diff --git a/extensions-contrib/kubernetes-overlord-extensions/src/test/resources/expectedNoopJobTlsEnabled.yaml b/extensions-contrib/kubernetes-overlord-extensions/src/test/resources/expectedNoopJobTlsEnabled.yaml index 167022b7d06..da7691870c8 100644 --- a/extensions-contrib/kubernetes-overlord-extensions/src/test/resources/expectedNoopJobTlsEnabled.yaml +++ b/extensions-contrib/kubernetes-overlord-extensions/src/test/resources/expectedNoopJobTlsEnabled.yaml @@ -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"