From 2a5628b4e3a6f03c3f5351d5b5f23d7e899ee244 Mon Sep 17 00:00:00 2001 From: Ikhun Um Date: Wed, 6 Dec 2023 22:50:07 +0900 Subject: [PATCH] Check chaos mesh namespace instead of minikube status --- .../armeria/kubernetes/it/ChaosIT.java | 3 +- .../it/ChaosMeshAvailableCondition.java | 46 +++++++++++++++++++ .../it/EnableIfMinikubeIsRunning.java | 30 ------------ .../it/MinikubeAvailableCondition.java | 42 ----------------- 4 files changed, 48 insertions(+), 73 deletions(-) create mode 100644 it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/ChaosMeshAvailableCondition.java delete mode 100644 it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/EnableIfMinikubeIsRunning.java delete mode 100644 it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/MinikubeAvailableCondition.java diff --git a/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/ChaosIT.java b/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/ChaosIT.java index 516f8614597..5d10b1bdb9f 100644 --- a/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/ChaosIT.java +++ b/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/ChaosIT.java @@ -45,6 +45,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.condition.EnabledIf; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,7 +60,7 @@ @KubernetesTest @LoadKubernetesManifests({ "checker-infra.yaml", "control-infra.yaml" }) -@EnableIfMinikubeIsRunning +@EnabledIf("com.linecorp.armeria.kubernetes.it.ChaosMeshAvailableCondition#isRunning") class ChaosIT { // Forked from https://github.com/fabric8io/kubernetes-client/blob/56a6c2c4f336cc6f64c19029a55c2d3d0289344f/chaos-tests/src/test/java/ChaosIT.java#L42-L42 diff --git a/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/ChaosMeshAvailableCondition.java b/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/ChaosMeshAvailableCondition.java new file mode 100644 index 00000000000..9824123f16c --- /dev/null +++ b/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/ChaosMeshAvailableCondition.java @@ -0,0 +1,46 @@ +/* + * Copyright 2023 LINE Corporation + * + * LINE Corporation 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: + * + * https://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 com.linecorp.armeria.kubernetes.it; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.linecorp.armeria.client.kubernetes.ArmeriaHttpClient; + +import io.fabric8.kubernetes.api.model.Namespace; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.KubernetesClientBuilder; + +final class ChaosMeshAvailableCondition { + + private static final Logger logger = LoggerFactory.getLogger(ChaosMeshAvailableCondition.class); + + static boolean isRunning() { + try (KubernetesClient client = new KubernetesClientBuilder().build()) { + assertThat(client.getHttpClient()).isInstanceOf(ArmeriaHttpClient.class); + final Namespace namespace = client.namespaces().withName("chaos-mesh").get(); + return "Active".equals(namespace.getStatus().getPhase()); + } catch (Exception cause) { + logger.trace("Chaos Mesh is not running in Kubernetes", cause); + return false; + } + } + + private ChaosMeshAvailableCondition() {} +} diff --git a/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/EnableIfMinikubeIsRunning.java b/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/EnableIfMinikubeIsRunning.java deleted file mode 100644 index 4bb785e042e..00000000000 --- a/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/EnableIfMinikubeIsRunning.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2023 LINE Corporation - * - * LINE Corporation 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: - * - * https://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 com.linecorp.armeria.kubernetes.it; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import org.junit.jupiter.api.condition.EnabledIf; - -@Target({ ElementType.TYPE, ElementType.METHOD }) -@Retention(RetentionPolicy.RUNTIME) -@EnabledIf("com.linecorp.armeria.kubernetes.it.MinikubeAvailableCondition#isMinikubeRunning") -@interface EnableIfMinikubeIsRunning { -} diff --git a/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/MinikubeAvailableCondition.java b/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/MinikubeAvailableCondition.java deleted file mode 100644 index 9ded3ad8c0c..00000000000 --- a/it/kubernetes-chaos-tests/src/test/java/com/linecorp/armeria/kubernetes/it/MinikubeAvailableCondition.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2023 LINE Corporation - * - * LINE Corporation 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: - * - * https://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 com.linecorp.armeria.kubernetes.it; - -import java.io.BufferedReader; -import java.io.InputStreamReader; - -final class MinikubeAvailableCondition { - - static boolean isMinikubeRunning() { - try { - final ProcessBuilder pb = new ProcessBuilder("minikube", "status"); - final Process p = pb.start(); - - String line; - final BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); - while ((line = reader.readLine()) != null) { - if (line.toLowerCase().startsWith("host: running")) { - return true; - } - } - } catch (Exception ignore) { - } - return false; - } - - private MinikubeAvailableCondition() {} -}