Skip to content

feat: use jenvtest in special ITs #1831

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 4 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ jobs:
strategy:
matrix:
java: [ 11, 17 ]
kubernetes: [ 'v1.23.15', 'v1.24.9', 'v1.25.5' ]
steps:
- uses: actions/checkout@v3
- name: Set up Java and Maven
Expand All @@ -68,13 +67,5 @@ jobs:
distribution: temurin
java-version: ${{ matrix.java }}
cache: 'maven'
- name: Minikube Min Request Timeout Setting
uses: manusa/actions-setup-minikube@v2.7.2
with:
minikube version: 'v1.28.0'
kubernetes version: ${{ matrix.kubernetes }}
driver: 'docker'
start args: '--extra-config=apiserver.min-request-timeout=3'
github token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Special Integration Tests
run: ./mvnw ${MAVEN_ARGS} -B package -P minimal-watch-timeout-dependent-it --file pom.xml
11 changes: 11 additions & 0 deletions operator-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<groupId>com.google.testing.compile</groupId>
<artifactId>compile-testing</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
Expand All @@ -79,6 +85,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>jenvtest</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil;
import io.javaoperatorsdk.jenvtest.junit.EnableKubeAPIServer;
import io.javaoperatorsdk.operator.api.config.ConfigurationServiceProvider;
import io.javaoperatorsdk.operator.health.InformerHealthIndicator;
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension;
Expand All @@ -30,7 +31,8 @@

/**
* The test relies on a special api server configuration: "min-request-timeout" to have a very low
* value, use: "minikube start --extra-config=apiserver.min-request-timeout=3"
* value (in case want to try with minikube use: "minikube start
* --extra-config=apiserver.min-request-timeout=3")
*
* <p>
* This is important when tests are affected by permission changes, since the watch permissions are
Expand All @@ -41,14 +43,16 @@
* The test ends with "ITS" (Special) since it needs to run separately from other ITs
* </p>
*/
@EnableKubeAPIServer(apiServerFlags = {"--min-request-timeout", "3"})
class InformerRelatedBehaviorITS {

public static final String TEST_RESOURCE_NAME = "test1";
public static final String ADDITIONAL_NAMESPACE_NAME = "additionalns";
public static final String ADDITIONAL_NAMESPACE_SUFFIX = "-additional";

KubernetesClient adminClient = new KubernetesClientBuilder().build();
InformerRelatedBehaviorTestReconciler reconciler;
String actualNamespace;
String additionalNamespace;
volatile boolean replacementStopHandlerCalled = false;

@BeforeEach
Expand All @@ -57,6 +61,7 @@ void beforeEach(TestInfo testInfo) {
adminClient);
testInfo.getTestMethod().ifPresent(method -> {
actualNamespace = KubernetesResourceUtil.sanitizeName(method.getName());
additionalNamespace = actualNamespace + ADDITIONAL_NAMESPACE_SUFFIX;
adminClient.resource(namespace()).createOrReplace();
});
// cleans up binding before test, not all test cases use cluster role
Expand All @@ -66,7 +71,6 @@ void beforeEach(TestInfo testInfo) {
@AfterEach
void cleanup() {
adminClient.resource(testCustomResource()).delete();
adminClient.resource(namespace()).delete();
}

@Test
Expand Down Expand Up @@ -110,24 +114,15 @@ void startsUpWhenNoPermissionToSecondaryResource() {

@Test
void startsUpIfNoPermissionToOneOfTwoNamespaces() {
var otherNamespace =
adminClient.resource(namespace(ADDITIONAL_NAMESPACE_NAME)).createOrReplace();
try {
addRoleBindingsToTestNamespaces();
var operator = startOperator(false, false, actualNamespace, ADDITIONAL_NAMESPACE_NAME);
assertInformerNotWatchingForAdditionalNamespace(operator);

adminClient.resource(testCustomResource()).createOrReplace();
waitForWatchReconnect();
assertReconciled();

} finally {
adminClient.resource(otherNamespace).delete();
await().untilAsserted(() -> {
var ns = adminClient.namespaces().resource(otherNamespace).fromServer().get();
assertThat(ns).isNull();
});
}
adminClient.resource(namespace(additionalNamespace)).createOrReplace();

addRoleBindingsToTestNamespaces();
var operator = startOperator(false, false, actualNamespace, additionalNamespace);
assertInformerNotWatchingForAdditionalNamespace(operator);

adminClient.resource(testCustomResource()).createOrReplace();
waitForWatchReconnect();
assertReconciled();
}

private void assertInformerNotWatchingForAdditionalNamespace(Operator operator) {
Expand All @@ -139,17 +134,17 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator)
InformerHealthIndicator controllerHealthIndicator =
(InformerHealthIndicator) unhealthyEventSources
.get(ControllerResourceEventSource.class.getSimpleName())
.informerHealthIndicators().get(ADDITIONAL_NAMESPACE_NAME);
.informerHealthIndicators().get(additionalNamespace);
assertThat(controllerHealthIndicator).isNotNull();
assertThat(controllerHealthIndicator.getTargetNamespace()).isEqualTo(ADDITIONAL_NAMESPACE_NAME);
assertThat(controllerHealthIndicator.getTargetNamespace()).isEqualTo(additionalNamespace);
assertThat(controllerHealthIndicator.isWatching()).isFalse();

InformerHealthIndicator configMapHealthIndicator =
(InformerHealthIndicator) unhealthyEventSources
.get(ConfigMapDependentResource.class.getSimpleName())
.informerHealthIndicators().get(ADDITIONAL_NAMESPACE_NAME);
.informerHealthIndicators().get(additionalNamespace);
assertThat(configMapHealthIndicator).isNotNull();
assertThat(configMapHealthIndicator.getTargetNamespace()).isEqualTo(ADDITIONAL_NAMESPACE_NAME);
assertThat(configMapHealthIndicator.getTargetNamespace()).isEqualTo(additionalNamespace);
assertThat(configMapHealthIndicator.isWatching()).isFalse();
}

Expand Down
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<directory-maven-plugin.version>1.0</directory-maven-plugin.version>
<impsort-maven-plugin.version>1.8.0</impsort-maven-plugin.version>
<okhttp.version>4.10.0</okhttp.version>
<jenvtest.version>0.4.0</jenvtest.version>
</properties>

<modules>
Expand Down Expand Up @@ -193,6 +194,12 @@
<artifactId>mockwebserver</artifactId>
<version>${okhttp.version}</version>
</dependency>
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>jenvtest</artifactId>
<version>${jenvtest.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down