-
Notifications
You must be signed in to change notification settings - Fork 988
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3aa4d3f
add a istio test harness
jrhee17 fa9bfc8
address ai comments
jrhee17 904f801
compilation errro
jrhee17 18b0f6b
Merge branch 'main' into poc/istio-step2
jrhee17 34b5549
ordering
jrhee17 6864f84
Merge branch 'main' into poc/istio-step2
jrhee17 7c2dc42
address comments by @ikhoon
jrhee17 ea5aa17
Merge branch 'main' into poc/istio-step2
jrhee17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| dependencies { | ||
| implementation project(':junit5') | ||
| implementation project(':kubernetes') | ||
| implementation libs.junit5.platform.launcher | ||
| implementation libs.testcontainers.k3s | ||
| implementation libs.testcontainers.junit.jupiter | ||
| } | ||
|
|
||
| def kubeconfigEnvValue = | ||
| layout.buildDirectory.file('kubeconfig/kubeconfig.yaml').get().asFile.absolutePath | ||
| 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 | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
...s-istio/src/main/java/com/linecorp/armeria/it/istio/testing/DockerAvailableCondition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...s-istio/src/main/java/com/linecorp/armeria/it/istio/testing/EnabledIfDockerAvailable.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 {} |
60 changes: 60 additions & 0 deletions
60
it/xds-istio/src/main/java/com/linecorp/armeria/it/istio/testing/HostOnlyExtension.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 {} | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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) Where does this file come from?
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.
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.