Skip to content

Commit 2ea8c45

Browse files
committed
feat: e2e test to demonstrate namespace deletion problem
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 1ed539b commit 2ea8c45

9 files changed

+190
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>io.javaoperatorsdk</groupId>
7+
<artifactId>sample-operators</artifactId>
8+
<version>5.0.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>sample-controller-namespace-deletion</artifactId>
12+
<packaging>jar</packaging>
13+
<name>Operator SDK - Samples - Controller Namespace Deletion</name>
14+
<description>Deleting namespace with controller and custom resources</description>
15+
16+
<dependencyManagement>
17+
<dependencies>
18+
<dependency>
19+
<groupId>io.javaoperatorsdk</groupId>
20+
<artifactId>operator-framework-bom</artifactId>
21+
<version>${project.version}</version>
22+
<type>pom</type>
23+
<scope>import</scope>
24+
</dependency>
25+
</dependencies>
26+
</dependencyManagement>
27+
28+
<dependencies>
29+
<dependency>
30+
<groupId>io.javaoperatorsdk</groupId>
31+
<artifactId>operator-framework</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>io.fabric8</groupId>
35+
<artifactId>crd-generator-apt</artifactId>
36+
<scope>provided</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.apache.logging.log4j</groupId>
40+
<artifactId>log4j-slf4j2-impl</artifactId>
41+
<scope>compile</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.apache.logging.log4j</groupId>
45+
<artifactId>log4j-core</artifactId>
46+
<scope>compile</scope>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.takes</groupId>
50+
<artifactId>takes</artifactId>
51+
<version>1.24.4</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.awaitility</groupId>
55+
<artifactId>awaitility</artifactId>
56+
<scope>compile</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>io.javaoperatorsdk</groupId>
60+
<artifactId>operator-framework-junit-5</artifactId>
61+
<scope>test</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.junit.jupiter</groupId>
65+
<artifactId>junit-jupiter-params</artifactId>
66+
<scope>test</scope>
67+
</dependency>
68+
</dependencies>
69+
<build>
70+
<plugins>
71+
<plugin>
72+
<groupId>com.google.cloud.tools</groupId>
73+
<artifactId>jib-maven-plugin</artifactId>
74+
<version>${jib-maven-plugin.version}</version>
75+
<configuration>
76+
<from>
77+
<image>gcr.io/distroless/java17-debian11</image>
78+
</from>
79+
<to>
80+
<image>leader-election-operator</image>
81+
</to>
82+
</configuration>
83+
</plugin>
84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-compiler-plugin</artifactId>
87+
<version>3.12.1</version>
88+
</plugin>
89+
</plugins>
90+
</build>
91+
92+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.javaoperatorsdk.operator.sample;
2+
3+
import io.fabric8.kubernetes.client.CustomResource;
4+
5+
public class ControllerNamespaceDeletionCustomResource extends CustomResource<ControllerNamespaceDeletionSpec, ControllerNamespaceDeletionStatus> {
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.javaoperatorsdk.operator.sample;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
import io.javaoperatorsdk.operator.Operator;
7+
import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration;
8+
9+
public class ControllerNamespaceDeletionOperator {
10+
11+
private static final Logger log = LoggerFactory.getLogger(ControllerNamespaceDeletionOperator.class);
12+
13+
public static void main(String[] args) {
14+
Operator operator = new Operator();
15+
16+
operator.register(new ControllerNamespaceDeletionReconciler());
17+
operator.start();
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package io.javaoperatorsdk.operator.sample;
2+
3+
import io.javaoperatorsdk.operator.api.reconciler.Cleaner;
4+
import io.javaoperatorsdk.operator.api.reconciler.Context;
5+
import io.javaoperatorsdk.operator.api.reconciler.DeleteControl;
6+
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
7+
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
8+
9+
import java.time.Duration;
10+
11+
public class ControllerNamespaceDeletionReconciler implements Reconciler<ControllerNamespaceDeletionCustomResource>,
12+
Cleaner<ControllerNamespaceDeletionCustomResource> {
13+
14+
@Override
15+
public UpdateControl<ControllerNamespaceDeletionCustomResource> reconcile(ControllerNamespaceDeletionCustomResource resource,
16+
Context<ControllerNamespaceDeletionCustomResource> context) {
17+
18+
19+
return null;
20+
}
21+
22+
23+
@Override
24+
public DeleteControl cleanup(ControllerNamespaceDeletionCustomResource resource,
25+
Context<ControllerNamespaceDeletionCustomResource> context) {
26+
try {
27+
Thread.sleep(Duration.ofSeconds(10).toMillis());
28+
return DeleteControl.defaultDelete();
29+
} catch (InterruptedException e) {
30+
throw new RuntimeException(e);
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.javaoperatorsdk.operator.sample;
2+
3+
import io.fabric8.kubernetes.client.CustomResource;
4+
5+
public class ControllerNamespaceDeletionSpec {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.javaoperatorsdk.operator.sample;
2+
3+
import io.fabric8.kubernetes.client.CustomResource;
4+
5+
public class ControllerNamespaceDeletionStatus {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Appenders>
4+
<Console name="Console" target="SYSTEM_OUT">
5+
<PatternLayout pattern="%d %-30c{1.} [%-5level] %msg%n%throwable"/>
6+
</Console>
7+
</Appenders>
8+
<Loggers>
9+
<Root level="debug">
10+
<AppenderRef ref="Console"/>
11+
</Root>
12+
</Loggers>
13+
</Configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Configuration status="WARN">
3+
<Appenders>
4+
<Console name="Console" target="SYSTEM_OUT">
5+
<PatternLayout pattern="%style{%d}{yellow} %style{%-30c{1.}}{cyan} %highlight{[%-5level] %msg%n%throwable}{INFO=white}"/>
6+
</Console>
7+
</Appenders>
8+
<Loggers>
9+
<Root level="debug">
10+
<AppenderRef ref="Console"/>
11+
</Root>
12+
</Loggers>
13+
</Configuration>

sample-operators/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
<module>webpage</module>
1818
<module>mysql-schema</module>
1919
<module>leader-election</module>
20+
<module>controller-namespace-deletion</module>
2021
</modules>
2122
</project>

0 commit comments

Comments
 (0)