churromorales commented on code in PR #13896:
URL: https://github.com/apache/druid/pull/13896#discussion_r1129952031


##########
extensions-contrib/kubernetes-overlord-extensions/src/main/java/org/apache/druid/k8s/overlord/common/PodTemplateTaskAdapter.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.k8s.overlord.common;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.cfg.MapperConfig;
+import com.fasterxml.jackson.databind.introspect.AnnotatedClass;
+import com.fasterxml.jackson.databind.introspect.AnnotatedClassResolver;
+import com.fasterxml.jackson.databind.jsontype.NamedType;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import io.fabric8.kubernetes.api.model.EnvVar;
+import io.fabric8.kubernetes.api.model.EnvVarBuilder;
+import io.fabric8.kubernetes.api.model.EnvVarSourceBuilder;
+import io.fabric8.kubernetes.api.model.ObjectFieldSelector;
+import io.fabric8.kubernetes.api.model.Pod;
+import io.fabric8.kubernetes.api.model.PodTemplate;
+import io.fabric8.kubernetes.api.model.batch.v1.Job;
+import io.fabric8.kubernetes.api.model.batch.v1.JobBuilder;
+import org.apache.druid.guice.IndexingServiceModuleHelper;
+import org.apache.druid.indexing.common.config.TaskConfig;
+import org.apache.druid.indexing.common.task.Task;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.java.util.common.IOE;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.k8s.overlord.KubernetesTaskRunnerConfig;
+import org.apache.druid.server.DruidNode;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+
+public class PodTemplateTaskAdapter implements TaskAdapter
+{
+  public static String TYPE = "PodTemplate";
+
+  private static final Logger log = new Logger(PodTemplateTaskAdapter.class);
+  private static final String TASK_PROPERTY = 
IndexingServiceModuleHelper.INDEXER_RUNNER_PROPERTY_PREFIX + 
".k8s.podTemplate.%s";
+
+  private final KubernetesClientApi client;
+  private final KubernetesTaskRunnerConfig taskRunnerConfig;
+  private final TaskConfig taskConfig;
+  private final DruidNode node;
+  private final ObjectMapper mapper;
+  private final HashMap<String, PodTemplate> templates;
+
+  public PodTemplateTaskAdapter(
+      KubernetesClientApi client,
+      KubernetesTaskRunnerConfig taskRunnerConfig,
+      TaskConfig taskConfig,
+      DruidNode node,
+      ObjectMapper mapper,
+      Properties properties
+  )
+  {
+    this.client = client;
+    this.taskRunnerConfig = taskRunnerConfig;
+    this.taskConfig = taskConfig;
+    this.node = node;
+    this.mapper = mapper;
+    this.templates = initializePodTemplates(properties);
+  }
+
+  @Override
+  public Job fromTask(Task task) throws IOException
+  {
+    PodTemplate podTemplate = templates.getOrDefault(task.getType(), 
templates.get("base"));
+    if (podTemplate == null) {
+      throw new ISE("Pod template spec not found for task type [%s]", 
task.getType());
+    }
+
+    return new JobBuilder()
+        .withNewMetadata()
+        .withName(new K8sTaskId(task).getK8sTaskId())
+        .addToLabels(getJobLabels(taskRunnerConfig))
+        .addToAnnotations(getJobAnnotations(taskRunnerConfig, task))
+        .endMetadata()
+        .withNewSpec()
+        .withTemplate(podTemplate.getTemplate())

Review Comment:
   will this work with sidecars injected by a controller?  Something like istio 
for example where you have a control plane which injects a sidecar container 
into your template.  I think what would happen is your job would run and then 
never really complete....because the istio container would never shut down, you 
would only exit the main container.  I don't know an easy way to do this unless 
you can do some more templating in yaml, but maybe at the very least I would 
call this out: ```If you have a service mesh, which injects sidecars (like 
istio) this approach may not work. ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to