-
Notifications
You must be signed in to change notification settings - Fork 992
Introduce an Istio test harness #6706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
3aa4d3f
fa9bfc8
904f801
18b0f6b
34b5549
6864f84
7c2dc42
ea5aa17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| dependencies { | ||
| implementation project(':junit5') | ||
| implementation libs.junit5.platform.launcher | ||
| implementation libs.kubernetes.client.api | ||
| implementation libs.kubernetes.client.impl | ||
| implementation libs.kubernetes.httpclient.okhttp | ||
| implementation libs.testcontainers.k3s | ||
| implementation libs.testcontainers.junit.jupiter | ||
|
|
||
| runtimeOnly libs.logback15 | ||
|
|
||
|
jrhee17 marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| def kubeconfigEnvValue = | ||
| layout.buildDirectory.file('kubeconfig/kubeconfig.yaml').get().asFile.absolutePath | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question) Where does this file come from?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is written here: https://github.com/jrhee17/armeria/blob/7c2dc4282cf46a1207757a707334a2ee6d83892c/it/xds-istio/src/main/java/com/linecorp/armeria/it/istio/testing/IstioState.java#L91 The config is written so that each test has the option of reusing the existing k8s cluster since starting a new container takes > 1min. |
||
| def istioVersion = libs.versions.istio.get() | ||
| def istioProfile = 'minimal' | ||
| def istioWorkDir = layout.buildDirectory.dir('istio').get().asFile | ||
| def istioOs = detectIstioOs() | ||
| def istioArch = detectIstioArch() | ||
| def istioSupported = istioOs != null && istioArch != null | ||
| if (!istioSupported) { | ||
| def osDetector = requireOsDetector() | ||
| def osValue = osDetector.os | ||
| def archValue = osDetector.arch | ||
| logger.warn("Istio is not supported on ${osValue}/${archValue}; skipping :it:xds-istio tasks.") | ||
| tasks.configureEach { | ||
| enabled = false | ||
| } | ||
| return | ||
| } | ||
| def istioArchive = file("${istioWorkDir}/istio-${istioVersion}-${istioOs}-${istioArch}.tar.gz") | ||
| def istioHomeDir = file("${istioWorkDir}/istio-${istioVersion}") | ||
| def istioctlPath = new File(istioHomeDir, 'bin/istioctl').absolutePath | ||
| def istioEnv = [ | ||
| 'KUBECONFIG_PATH': kubeconfigEnvValue, | ||
| 'ISTIO_VERSION': istioVersion, | ||
| 'ISTIO_PROFILE': istioProfile, | ||
| 'ISTIOCTL_PATH': istioctlPath | ||
| ] | ||
|
|
||
| tasks.register('downloadIstioctl') { | ||
| outputs.file istioArchive | ||
| inputs.property 'istioVersion', istioVersion | ||
| inputs.property 'istioOs', istioOs | ||
| inputs.property 'istioArch', istioArch | ||
| doLast { | ||
| istioArchive.parentFile.mkdirs() | ||
| def url = "https://github.com/istio/istio/releases/download/${istioVersion}/" + | ||
| "istio-${istioVersion}-${istioOs}-${istioArch}.tar.gz" | ||
| ant.get(src: url, dest: istioArchive, skipexisting: true) | ||
| } | ||
| } | ||
|
|
||
| tasks.register('extractIstioctl', Copy) { | ||
| dependsOn tasks.named('downloadIstioctl') | ||
| from tarTree(istioArchive) | ||
| into istioWorkDir | ||
| outputs.dir istioHomeDir | ||
| } | ||
|
|
||
| tasks.register('prepareIstioctl') { | ||
| dependsOn tasks.named('extractIstioctl') | ||
| outputs.file istioctlPath | ||
| doLast { | ||
| def istioctlFile = file(istioctlPath) | ||
| if (!istioctlFile.exists()) { | ||
| throw new GradleException("istioctl was not found at ${istioctlPath}") | ||
| } | ||
| istioctlFile.setExecutable(true) | ||
| } | ||
| } | ||
|
|
||
| def testRuntimeDir = new File(istioWorkDir, 'test-runtime-jars') | ||
| def dockerImagesDir = new File(istioWorkDir, 'docker-images') | ||
| istioEnv['ISTIO_TEST_RUNTIME_DIR'] = testRuntimeDir.absolutePath | ||
| istioEnv['ISTIO_DOCKER_IMAGES_DIR'] = dockerImagesDir.absolutePath | ||
|
|
||
| tasks.register('prepareIstioWorkdir') { | ||
| outputs.dirs testRuntimeDir, dockerImagesDir | ||
| doLast { | ||
| testRuntimeDir.mkdirs() | ||
| dockerImagesDir.mkdirs() | ||
| } | ||
| } | ||
|
|
||
| tasks.register('copyTestRuntimeJars', Sync) { | ||
| dependsOn tasks.named('prepareIstioWorkdir') | ||
| from(sourceSets.test.runtimeClasspath) | ||
| into(testRuntimeDir) | ||
| } | ||
|
|
||
| tasks.withType(Test).configureEach { | ||
| dependsOn tasks.named('copyTestRuntimeJars') | ||
| dependsOn tasks.named('prepareIstioctl') | ||
| environment istioEnv | ||
| systemProperty 'junit.jupiter.execution.parallel.enabled', 'false' | ||
| maxParallelForks = 1 | ||
| doFirst { | ||
| def allArgs = (jvmArgs ?: []).join(' ') | ||
| if (allArgs) { | ||
| environment 'ISTIO_POD_JVM_ARGS', allArgs | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // For LocalDevClusterMain | ||
| tasks.withType(JavaExec).configureEach { | ||
| dependsOn tasks.named('prepareIstioctl') | ||
| environment istioEnv | ||
| } | ||
|
|
||
| def detectIstioOs() { | ||
| def osDetector = requireOsDetector() | ||
| def os = osDetector.os | ||
| if (os == 'osx') { | ||
| return 'osx' | ||
| } | ||
| if (os == 'linux') { | ||
| return 'linux' | ||
| } | ||
| logger.warn("Unsupported OS for Istio: {}", os) | ||
| return null | ||
| } | ||
|
|
||
| def detectIstioArch() { | ||
| def osDetector = requireOsDetector() | ||
| def arch = String.valueOf(osDetector.arch).toLowerCase(Locale.ROOT) | ||
| if (arch == 'x86_64' || arch == 'amd64') { | ||
| return 'amd64' | ||
| } | ||
| if (arch == 'aarch64' || arch == 'arm64' || arch == 'aarch_64' || arch == 'arm_64') { | ||
| return 'arm64' | ||
| } | ||
| if (arch.startsWith('armv7') || arch == 'armv7' || arch == 'arm_32') { | ||
| return 'armv7' | ||
| } | ||
| logger.warn("Unsupported architecture for Istio: {}", arch) | ||
| return null | ||
| } | ||
|
|
||
| def requireOsDetector() { | ||
| def osDetector = rootProject.extensions.findByName('osdetector') | ||
| if (osDetector == null) { | ||
| throw new GradleException("osdetector extension is required for :it:xds-istio") | ||
| } | ||
| return osDetector | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Copyright 2025 LY Corporation | ||
| * | ||
| * LY 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.it.istio.testing; | ||
|
|
||
| import org.junit.jupiter.api.extension.ConditionEvaluationResult; | ||
| import org.junit.jupiter.api.extension.ExecutionCondition; | ||
| import org.junit.jupiter.api.extension.ExtensionContext; | ||
| import org.testcontainers.DockerClientFactory; | ||
|
|
||
| final class DockerAvailableCondition implements ExecutionCondition { | ||
| @Override | ||
| public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { | ||
| // When running inside a K8s pod, Docker is not available but the test should still run. | ||
| if (HostOnlyExtension.isRunningInPod()) { | ||
| return ConditionEvaluationResult.enabled("Running inside K8s pod"); | ||
| } | ||
| final boolean available = DockerClientFactory.instance().isDockerAvailable(); | ||
| return available ? | ||
| ConditionEvaluationResult.enabled("Docker is available") | ||
| : ConditionEvaluationResult.disabled("Docker daemon is not running"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright 2025 LY Corporation | ||
| * | ||
| * LY 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.it.istio.testing; | ||
|
|
||
| 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.extension.ExtendWith; | ||
|
|
||
| /** | ||
| * Enables the annotated test class or method only when the Docker daemon is available, | ||
| * or when running inside a Kubernetes pod (where Docker is not needed). | ||
| */ | ||
| @Target({ElementType.TYPE, ElementType.METHOD}) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @ExtendWith(DockerAvailableCondition.class) | ||
| public @interface EnabledIfDockerAvailable {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright 2025 LY Corporation | ||
| * | ||
| * LY 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.it.istio.testing; | ||
|
|
||
| import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
|
||
| import com.linecorp.armeria.testing.junit5.common.AbstractAllOrEachExtension; | ||
|
|
||
| /** | ||
| * Base class for JUnit extensions that must only run when executing on the host, | ||
| * not inside a Kubernetes pod. Subclass this instead of {@link AbstractAllOrEachExtension} | ||
| * when the extension manages host-side infrastructure (cluster lifecycle, container | ||
| * management, etc.) that must not execute inside the in-cluster test job. | ||
| * | ||
| * <p>Implement {@link #setUp} and optionally {@link #tearDown}. Both are no-ops | ||
| * when {@code RUNNING_IN_K8S_POD=true}. | ||
| */ | ||
| abstract class HostOnlyExtension extends AbstractAllOrEachExtension { | ||
|
|
||
| static final String RUNNING_IN_K8S_POD_ENV = "RUNNING_IN_K8S_POD"; | ||
|
|
||
| static boolean isRunningInPod() { | ||
| return Boolean.parseBoolean(System.getenv(RUNNING_IN_K8S_POD_ENV)); | ||
| } | ||
|
|
||
| static boolean notRunningInPod() { | ||
| return !isRunningInPod(); | ||
| } | ||
|
|
||
| @Override | ||
| protected final void before(ExtensionContext context) throws Exception { | ||
| if (notRunningInPod()) { | ||
| setUp(context); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected final void after(ExtensionContext context) throws Exception { | ||
| if (notRunningInPod()) { | ||
| tearDown(context); | ||
| } | ||
| } | ||
|
|
||
| abstract void setUp(ExtensionContext context) throws Exception; | ||
|
|
||
| void tearDown(ExtensionContext context) throws Exception {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question) Could we use Armeria Kubernetes client implementation? If not, is there any reason we can't use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason in particular, done