Skip to content

Commit 2ed4894

Browse files
authored
feat: use jenvtest in special ITs (#1831)
* feat: use jenvtest in special ITs * don't run minikube * test refactor for jenvtest * removing kub api
1 parent 7117537 commit 2ed4894

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

.github/workflows/pr.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ jobs:
5959
strategy:
6060
matrix:
6161
java: [ 11, 17 ]
62-
kubernetes: [ 'v1.23.15', 'v1.24.9', 'v1.25.5' ]
6362
steps:
6463
- uses: actions/checkout@v3
6564
- name: Set up Java and Maven
@@ -68,13 +67,5 @@ jobs:
6867
distribution: temurin
6968
java-version: ${{ matrix.java }}
7069
cache: 'maven'
71-
- name: Minikube Min Request Timeout Setting
72-
uses: manusa/actions-setup-minikube@v2.7.2
73-
with:
74-
minikube version: 'v1.28.0'
75-
kubernetes version: ${{ matrix.kubernetes }}
76-
driver: 'docker'
77-
start args: '--extra-config=apiserver.min-request-timeout=3'
78-
github token: ${{ secrets.GITHUB_TOKEN }}
7970
- name: Run Special Integration Tests
8071
run: ./mvnw ${MAVEN_ARGS} -B package -P minimal-watch-timeout-dependent-it --file pom.xml

operator-framework/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
<groupId>com.google.testing.compile</groupId>
5656
<artifactId>compile-testing</artifactId>
5757
<scope>test</scope>
58+
<exclusions>
59+
<exclusion>
60+
<groupId>com.google.guava</groupId>
61+
<artifactId>guava</artifactId>
62+
</exclusion>
63+
</exclusions>
5864
</dependency>
5965
<dependency>
6066
<groupId>io.fabric8</groupId>
@@ -79,6 +85,11 @@
7985
<version>${project.version}</version>
8086
<scope>test</scope>
8187
</dependency>
88+
<dependency>
89+
<groupId>io.javaoperatorsdk</groupId>
90+
<artifactId>jenvtest</artifactId>
91+
<scope>test</scope>
92+
</dependency>
8293
</dependencies>
8394

8495
<build>

operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.fabric8.kubernetes.client.KubernetesClient;
1515
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
1616
import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil;
17+
import io.javaoperatorsdk.jenvtest.junit.EnableKubeAPIServer;
1718
import io.javaoperatorsdk.operator.api.config.ConfigurationServiceProvider;
1819
import io.javaoperatorsdk.operator.health.InformerHealthIndicator;
1920
import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension;
@@ -30,7 +31,8 @@
3031

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

4649
public static final String TEST_RESOURCE_NAME = "test1";
47-
public static final String ADDITIONAL_NAMESPACE_NAME = "additionalns";
50+
public static final String ADDITIONAL_NAMESPACE_SUFFIX = "-additional";
4851

4952
KubernetesClient adminClient = new KubernetesClientBuilder().build();
5053
InformerRelatedBehaviorTestReconciler reconciler;
5154
String actualNamespace;
55+
String additionalNamespace;
5256
volatile boolean replacementStopHandlerCalled = false;
5357

5458
@BeforeEach
@@ -57,6 +61,7 @@ void beforeEach(TestInfo testInfo) {
5761
adminClient);
5862
testInfo.getTestMethod().ifPresent(method -> {
5963
actualNamespace = KubernetesResourceUtil.sanitizeName(method.getName());
64+
additionalNamespace = actualNamespace + ADDITIONAL_NAMESPACE_SUFFIX;
6065
adminClient.resource(namespace()).createOrReplace();
6166
});
6267
// cleans up binding before test, not all test cases use cluster role
@@ -66,7 +71,6 @@ void beforeEach(TestInfo testInfo) {
6671
@AfterEach
6772
void cleanup() {
6873
adminClient.resource(testCustomResource()).delete();
69-
adminClient.resource(namespace()).delete();
7074
}
7175

7276
@Test
@@ -110,24 +114,15 @@ void startsUpWhenNoPermissionToSecondaryResource() {
110114

111115
@Test
112116
void startsUpIfNoPermissionToOneOfTwoNamespaces() {
113-
var otherNamespace =
114-
adminClient.resource(namespace(ADDITIONAL_NAMESPACE_NAME)).createOrReplace();
115-
try {
116-
addRoleBindingsToTestNamespaces();
117-
var operator = startOperator(false, false, actualNamespace, ADDITIONAL_NAMESPACE_NAME);
118-
assertInformerNotWatchingForAdditionalNamespace(operator);
119-
120-
adminClient.resource(testCustomResource()).createOrReplace();
121-
waitForWatchReconnect();
122-
assertReconciled();
123-
124-
} finally {
125-
adminClient.resource(otherNamespace).delete();
126-
await().untilAsserted(() -> {
127-
var ns = adminClient.namespaces().resource(otherNamespace).fromServer().get();
128-
assertThat(ns).isNull();
129-
});
130-
}
117+
adminClient.resource(namespace(additionalNamespace)).createOrReplace();
118+
119+
addRoleBindingsToTestNamespaces();
120+
var operator = startOperator(false, false, actualNamespace, additionalNamespace);
121+
assertInformerNotWatchingForAdditionalNamespace(operator);
122+
123+
adminClient.resource(testCustomResource()).createOrReplace();
124+
waitForWatchReconnect();
125+
assertReconciled();
131126
}
132127

133128
private void assertInformerNotWatchingForAdditionalNamespace(Operator operator) {
@@ -139,17 +134,17 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator)
139134
InformerHealthIndicator controllerHealthIndicator =
140135
(InformerHealthIndicator) unhealthyEventSources
141136
.get(ControllerResourceEventSource.class.getSimpleName())
142-
.informerHealthIndicators().get(ADDITIONAL_NAMESPACE_NAME);
137+
.informerHealthIndicators().get(additionalNamespace);
143138
assertThat(controllerHealthIndicator).isNotNull();
144-
assertThat(controllerHealthIndicator.getTargetNamespace()).isEqualTo(ADDITIONAL_NAMESPACE_NAME);
139+
assertThat(controllerHealthIndicator.getTargetNamespace()).isEqualTo(additionalNamespace);
145140
assertThat(controllerHealthIndicator.isWatching()).isFalse();
146141

147142
InformerHealthIndicator configMapHealthIndicator =
148143
(InformerHealthIndicator) unhealthyEventSources
149144
.get(ConfigMapDependentResource.class.getSimpleName())
150-
.informerHealthIndicators().get(ADDITIONAL_NAMESPACE_NAME);
145+
.informerHealthIndicators().get(additionalNamespace);
151146
assertThat(configMapHealthIndicator).isNotNull();
152-
assertThat(configMapHealthIndicator.getTargetNamespace()).isEqualTo(ADDITIONAL_NAMESPACE_NAME);
147+
assertThat(configMapHealthIndicator.getTargetNamespace()).isEqualTo(additionalNamespace);
153148
assertThat(configMapHealthIndicator.isWatching()).isFalse();
154149
}
155150

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<directory-maven-plugin.version>1.0</directory-maven-plugin.version>
7373
<impsort-maven-plugin.version>1.8.0</impsort-maven-plugin.version>
7474
<okhttp.version>4.10.0</okhttp.version>
75+
<jenvtest.version>0.4.0</jenvtest.version>
7576
</properties>
7677

7778
<modules>
@@ -193,6 +194,12 @@
193194
<artifactId>mockwebserver</artifactId>
194195
<version>${okhttp.version}</version>
195196
</dependency>
197+
<dependency>
198+
<groupId>io.javaoperatorsdk</groupId>
199+
<artifactId>jenvtest</artifactId>
200+
<version>${jenvtest.version}</version>
201+
<scope>test</scope>
202+
</dependency>
196203
</dependencies>
197204
</dependencyManagement>
198205

0 commit comments

Comments
 (0)