uds5501 commented on code in PR #18413:
URL: https://github.com/apache/druid/pull/18413#discussion_r2293368983


##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/k8s/K3sClusterWithOperatorResource.java:
##########
@@ -0,0 +1,313 @@
+/*
+ * 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 io.fabric8.kubernetes.client.Config;
+import io.fabric8.kubernetes.client.KubernetesClientBuilder;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.druid.java.util.common.StringUtils;
+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.docker.DruidContainerResource;
+import org.apache.druid.testing.embedded.indexing.Resources;
+import org.testcontainers.containers.Container;
+import org.testcontainers.utility.MountableFile;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Files;
+import java.nio.file.attribute.PosixFilePermission;
+import java.time.Duration;
+import java.util.Properties;
+import java.util.Set;
+import java.util.zip.GZIPInputStream;
+
+public class K3sClusterWithOperatorResource extends K3sClusterResource
+{
+  private static final Logger log = new 
Logger(K3sClusterWithOperatorResource.class);
+  private static final String RBAC_MANIFEST = 
"manifests/druid-operator-rbac.yaml";
+  private static final String OPERATOR_NAMESPACE_MANIFEST = 
"manifests/druid-operator-namespace.yaml";
+  private static final String OPERATOR_NAMESPACE = "druid-operator-system";
+  private static final String HELM_RELEASE_NAME = "druid-operator";
+  private static final String HELM_REPO_NAME = "datainfra";
+  private static final String HELM_REPO_URL = "https://charts.datainfra.io";;
+  private static final String HELM_CHART_NAME = "datainfra/druid-operator";
+  private static final String HELM_VERSION = "v3.13.1";
+  private static final String HELM_PLATFORM = "linux-amd64";
+  private static final String HELM_MOUNT_PATH = "/usr/local/bin/helm";
+
+
+  public K3sClusterWithOperatorResource()
+  {
+    super();
+    manifestFiles.add(Resources.getFileForResource(RBAC_MANIFEST));
+    
manifestFiles.add(Resources.getFileForResource(OPERATOR_NAMESPACE_MANIFEST));
+  }
+
+  @Override
+  public K3sClusterWithOperatorResource usingTestImage()
+  {
+    return usingDruidImage(DruidContainerResource.getTestDruidImageName());
+  }
+
+  @Override
+  public K3sClusterWithOperatorResource usingDruidImage(String druidImageName)
+  {
+    this.druidImageName = druidImageName;
+    return this;
+  }
+
+  @Override
+  public K3sClusterWithOperatorResource addService(K3sDruidService service)
+  {
+    services.add(service);
+    return this;
+  }
+
+  @Override
+  public void onStarted(EmbeddedDruidCluster cluster)
+  {
+    client = new KubernetesClientBuilder()
+        .withConfig(Config.fromKubeconfig(getContainer().getKubeConfigYaml()))
+        .build();
+    closer.register(client);
+
+    loadLocalDockerImageIntoContainer(druidImageName, cluster.getTestFolder());
+
+    manifestFiles.forEach(this::applyManifest);
+
+    installHelm(cluster);
+    setupOperatorWithHelm();
+
+    
client.pods().inNamespace(OPERATOR_NAMESPACE).resources().forEach(this::waitUntilPodIsReady);
+
+    final Properties commonProperties = new Properties();
+    commonProperties.putAll(cluster.getCommonProperties());
+    commonProperties.remove("druid.extensions.modulesForEmbeddedTests");
+    applyConfigMap(
+        newConfigMap(COMMON_CONFIG_MAP, commonProperties, 
"common.runtime.properties")
+    );
+
+    initializeDruidTestFolders(cluster.getTestFolder());
+
+    String commonPropertiesString = 
prepareCommonPropertiesString(commonProperties, cluster.getTestFolder());
+    
+    for (K3sDruidService druidService : services) {
+      applyManifest(druidService.withCommonProperties(commonPropertiesString));
+    }
+
+    
client.pods().inNamespace(DRUID_NAMESPACE).resources().forEach(this::waitUntilPodIsReady);
+    services.forEach(this::waitUntilServiceIsHealthy);
+  }
+
+  private void initializeDruidTestFolders(TestFolder testFolder) {
+    testFolder.getOrCreateFolder("druid-storage");
+    testFolder.getOrCreateFolder("druid-storage/segments");
+    testFolder.getOrCreateFolder("druid-storage/segment-cache");
+    testFolder.getOrCreateFolder("druid-storage/metadata");
+    testFolder.getOrCreateFolder("druid-storage/indexing-logs");
+  }

Review Comment:
   ack, purging and checking.



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