kfaraz commented on code in PR #18425:
URL: https://github.com/apache/druid/pull/18425#discussion_r2289835939


##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/k8s/K3sClusterResource.java:
##########
@@ -0,0 +1,369 @@
+/*
+ * 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.testing.embedded.k8s;
+
+import com.github.dockerjava.api.DockerClient;
+import com.github.dockerjava.api.exception.NotFoundException;
+import com.github.dockerjava.core.DefaultDockerClientConfig;
+import com.github.dockerjava.core.DockerClientImpl;
+import com.github.dockerjava.httpclient5.ApacheDockerHttpClient;
+import io.fabric8.kubernetes.api.model.ConfigMap;
+import io.fabric8.kubernetes.api.model.ObjectMeta;
+import io.fabric8.kubernetes.client.Config;
+import io.fabric8.kubernetes.client.KubernetesClient;
+import io.fabric8.kubernetes.client.KubernetesClientBuilder;
+import io.fabric8.kubernetes.client.KubernetesClientTimeoutException;
+import io.fabric8.kubernetes.client.dsl.PodResource;
+import io.fabric8.kubernetes.client.utils.Serialization;
+import org.apache.druid.error.InvalidInput;
+import org.apache.druid.java.util.common.FileUtils;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.testing.embedded.EmbeddedDruidCluster;
+import org.apache.druid.testing.embedded.TestFolder;
+import org.apache.druid.testing.embedded.TestcontainerResource;
+import org.apache.druid.testing.embedded.docker.DruidContainerResource;
+import org.apache.druid.testing.embedded.indexing.Resources;
+import org.apache.druid.testing.tools.ITRetryUtil;
+import org.testcontainers.k3s.K3sContainer;
+import org.testcontainers.utility.DockerImageName;
+import org.testcontainers.utility.MountableFile;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+public class K3sClusterResource extends TestcontainerResource<K3sContainer>
+{
+  private static final Logger log = new Logger(K3sClusterResource.class);
+
+  private static final String K3S_IMAGE_NAME = "rancher/k3s:v1.28.8-k3s1";
+
+  public static final String DRUID_NAMESPACE = "druid";
+  private static final String NAMESPACE_MANIFEST = 
"manifests/druid-namespace.yaml";
+
+  private static final String COMMON_CONFIG_MAP = "druid-common-props";
+  private static final String SERVICE_CONFIG_MAP = "druid-%s-props";
+
+  public static final long POD_READY_TIMEOUT_SECONDS = 300;
+
+  private final List<File> manifestFiles = new ArrayList<>();
+  private final List<K3sDruidService> services = new ArrayList<>();
+
+  private KubernetesClient client;
+  private String druidImageName;
+
+  private final Closer closer = Closer.create();
+
+  public K3sClusterResource()
+  {
+    // Add the namespace manifest
+    manifestFiles.add(Resources.getFileForResource(NAMESPACE_MANIFEST));
+  }
+
+  public K3sClusterResource addService(K3sDruidService service)
+  {
+    services.add(service);
+    return this;
+  }
+
+  public K3sClusterResource usingDruidImage(String druidImageName)
+  {
+    this.druidImageName = druidImageName;
+    return this;
+  }
+
+  /**
+   * Uses the Docker test image specified by the system property
+   * {@link DruidContainerResource#PROPERTY_TEST_IMAGE} for this container.
+   */
+  public K3sClusterResource usingTestImage()
+  {
+    final String imageName = 
System.getProperty(DruidContainerResource.PROPERTY_TEST_IMAGE);
+    InvalidInput.conditionalException(
+        imageName != null,
+        StringUtils.format(
+            "System property[%s] must be set while running Docker tests 
locally"
+            + " to specify which Druid image to use. Update your run 
configuration"
+            + " to include '-D%s=<your-test-image>'.",
+            DruidContainerResource.PROPERTY_TEST_IMAGE,
+            DruidContainerResource.PROPERTY_TEST_IMAGE
+        )
+    );
+    return usingDruidImage(imageName);
+  }
+
+  @Override
+  protected K3sContainer createContainer()
+  {
+    Objects.requireNonNull(druidImageName, "No Druid image specified");

Review Comment:
   Yeah, I considered that, but this made the test more readable and aligned 
with what `DruidContainerResource` is doing.



-- 
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