Hisoka-X commented on code in PR #5594:
URL: https://github.com/apache/seatunnel/pull/5594#discussion_r1379508827


##########
seatunnel-e2e/seatunnel-engine-e2e/seatunnel-engine-k8s-e2e/src/test/java/org/apache/seatunnel/engine/e2e/k8s/KubernetesIT.java:
##########
@@ -0,0 +1,249 @@
+/*
+ * 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.seatunnel.engine.e2e.k8s;
+
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.testcontainers.DockerClientFactory;
+
+import com.github.dockerjava.api.DockerClient;
+import com.github.dockerjava.api.command.BuildImageCmd;
+import com.github.dockerjava.api.model.Info;
+import io.kubernetes.client.openapi.ApiClient;
+import io.kubernetes.client.openapi.ApiException;
+import io.kubernetes.client.openapi.Configuration;
+import io.kubernetes.client.openapi.apis.AppsV1Api;
+import io.kubernetes.client.openapi.apis.CoreV1Api;
+import io.kubernetes.client.openapi.models.V1Service;
+import io.kubernetes.client.openapi.models.V1StatefulSet;
+import io.kubernetes.client.util.Config;
+import io.kubernetes.client.util.Yaml;
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.regex.Pattern;
+
+import static 
org.apache.seatunnel.e2e.common.util.ContainerUtil.PROJECT_ROOT_PATH;
+
+@Slf4j
+public class KubernetesIT {
+
+    @Test
+    public void test()
+            throws IOException, XmlPullParserException, ApiException, 
InterruptedException {
+        String targetPath =
+                PROJECT_ROOT_PATH
+                        + 
"/seatunnel-e2e/seatunnel-engine-e2e/seatunnel-engine-k8s-e2e/src/test/resources";
+        // If the Docker BaseDirectory is set as the root directory of the 
project, the image
+        // created is too large, so choose to copy the files that need to be 
created as images
+        // to the same level as the dockerfile. After completing the image 
creation, delete
+        // these files locally
+        copyFileToCurrentResources(targetPath);
+        DockerClient dockerClient = DockerClientFactory.lazyClient();
+        String pomPath = PROJECT_ROOT_PATH + "/pom.xml";
+        ApiClient client = Config.defaultClient();
+        AppsV1Api appsV1Api = new AppsV1Api(client);
+        CoreV1Api coreV1Api = new CoreV1Api(client);
+        MavenXpp3Reader pomReader = new MavenXpp3Reader();
+        Model model = pomReader.read(new FileReader(pomPath), true);
+        String artifactId = model.getArtifactId();
+        String tag = artifactId + ":lastest";
+        Info info = dockerClient.infoCmd().exec();
+        log.info("Docker's environmental information");
+        log.info(info.toString());
+        if 
(dockerClient.listImagesCmd().withImageNameFilter(tag).exec().size() > 0) {
+            dockerClient.removeImageCmd(tag).exec();
+        }
+        File file =
+                new File(
+                        PROJECT_ROOT_PATH
+                                + 
"/seatunnel-e2e/seatunnel-engine-e2e/seatunnel-engine-k8s-e2e/src/test/resources/seatunnel_dockerfile");
+        BuildImageCmd buildImageCmd = dockerClient.buildImageCmd(file);
+        buildImageCmd.withTag(tag);
+        String imageId = buildImageCmd.start().awaitImageId();
+        Assertions.assertNotNull(imageId);
+        Configuration.setDefaultApiClient(client);
+        V1Service yamlSvc =
+                (V1Service)
+                        Yaml.load(
+                                new File(
+                                        PROJECT_ROOT_PATH
+                                                + 
"/seatunnel-e2e/seatunnel-engine-e2e/seatunnel-engine-k8s-e2e/src/test/resources/seatunnel-service.yaml"));
+        V1StatefulSet yamlStatefulSet =
+                (V1StatefulSet)
+                        Yaml.load(
+                                new File(
+                                        PROJECT_ROOT_PATH
+                                                + 
"/seatunnel-e2e/seatunnel-engine-e2e/seatunnel-engine-k8s-e2e/src/test/resources/seatunnel-statefulset.yaml"));
+        String podName = "seatunnel-0";
+        String namespace = "default";
+        coreV1Api.createNamespacedService(namespace, yamlSvc, null, null, 
null, null);
+        appsV1Api.createNamespacedStatefulSet(namespace, yamlStatefulSet, 
null, null, null, null);
+        Thread.sleep(5000);
+        V1StatefulSet v1StatefulSet =
+                appsV1Api.readNamespacedStatefulSet("seatunnel", "default", 
null);
+        // assert ready replicas
+        Assertions.assertNotNull(v1StatefulSet.getStatus().getReadyReplicas());
+        Assertions.assertEquals(v1StatefulSet.getStatus().getReadyReplicas(), 
2);
+        log.info(v1StatefulSet.toString());
+        // submit job
+        String command =
+                "sh /opt/seatunnel/bin/seatunnel.sh --config 
/opt/seatunnel/config/v2.batch.config.template";

Review Comment:
   I think we should add a negative case too.



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

Reply via email to