Skip to content

Commit 4019703

Browse files
committed
plain spring boot example
1 parent 538bbfd commit 4019703

File tree

9 files changed

+125
-3
lines changed

9 files changed

+125
-3
lines changed

samples/basic/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
<modules>
1818
<module>common</module>
1919
<module>pure-java</module>
20-
<module>spring-boot</module>
20+
<module>spring-boot-plain</module>
21+
<module>spring-boot-auto-config</module>
2122
</modules>
2223

2324
</project>

samples/basic/spring-boot/pom.xml renamed to samples/basic/spring-boot-auto-config/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<version>1.1.1-SNAPSHOT</version>
1010
</parent>
1111

12-
<artifactId>operator-framework-samples-spring-boot</artifactId>
13-
<name>Operator SDK - Samples - Basic - Spring Boot</name>
12+
<artifactId>operator-framework-samples-spring-boot-auto-configuration</artifactId>
13+
<name>Operator SDK - Samples - Basic - Spring Boot - Auto Configuration</name>
1414
<description>Sample usage with Spring Boot</description>
1515
<packaging>jar</packaging>
1616

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>com.github.containersolutions</groupId>
8+
<artifactId>java-operator-sdk-basic-sample</artifactId>
9+
<version>1.1.1-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>operator-framework-samples-spring-boot-plain</artifactId>
13+
<name>Operator SDK - Samples - Basic - Spring Boot - Plain</name>
14+
<description>Sample usage with Spring Boot</description>
15+
<packaging>jar</packaging>
16+
17+
<properties>
18+
<java.version>8</java.version>
19+
<maven.compiler.source>1.8</maven.compiler.source>
20+
<maven.compiler.target>1.8</maven.compiler.target>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>com.github.containersolutions</groupId>
26+
<artifactId>operator-framework-samples-common</artifactId>
27+
<version>${project.version}</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter</artifactId>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-test</artifactId>
36+
<scope>test</scope>
37+
<exclusions>
38+
<exclusion>
39+
<groupId>junit</groupId>
40+
<artifactId>junit</artifactId>
41+
</exclusion>
42+
</exclusions>
43+
</dependency>
44+
</dependencies>
45+
46+
<dependencyManagement>
47+
<dependencies>
48+
<dependency>
49+
<groupId>org.springframework.boot</groupId>
50+
<artifactId>spring-boot-dependencies</artifactId>
51+
<version>2.2.6.RELEASE</version>
52+
<type>pom</type>
53+
<scope>import</scope>
54+
</dependency>
55+
</dependencies>
56+
</dependencyManagement>
57+
58+
<build>
59+
<plugins>
60+
<plugin>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-maven-plugin</artifactId>
63+
<version>2.2.6.RELEASE</version>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
</project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.github.containersolutions.operator.sample;
2+
3+
import com.github.containersolutions.operator.Operator;
4+
import com.github.containersolutions.operator.api.ResourceController;
5+
import com.github.containersolutions.operator.processing.retry.GenericRetry;
6+
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
7+
import io.fabric8.kubernetes.client.KubernetesClient;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.context.annotation.Configuration;
10+
11+
import java.util.List;
12+
13+
@Configuration
14+
public class Config {
15+
16+
@Bean
17+
public KubernetesClient kubernetesClient() {
18+
return new DefaultKubernetesClient();
19+
}
20+
21+
@Bean
22+
public CustomServiceController customServiceController(KubernetesClient client) {
23+
return new CustomServiceController(client);
24+
}
25+
26+
// Register all controller beans
27+
@Bean
28+
public Operator operator(KubernetesClient client, List<ResourceController> controllers) {
29+
Operator operator = new Operator(client);
30+
controllers.forEach(c -> operator.registerControllerForAllNamespaces(c,
31+
GenericRetry.defaultLimitedExponentialRetry()));
32+
return operator;
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.github.containersolutions.operator.sample;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
/**
7+
* Note that we have multiple options here either we can add this component scan as seen below. Or annotate controllers
8+
* with @Component or @Service annotation or just register the bean within a spring "@Configuration".
9+
*/
10+
@SpringBootApplication
11+
public class SpringBootStarterSampleApplication {
12+
13+
public static void main(String[] args) {
14+
SpringApplication.run(SpringBootStarterSampleApplication.class, args);
15+
}
16+
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
operator.controller.retry:
2+
maxAttempts: 3

0 commit comments

Comments
 (0)