Skip to content

Commit fb316e0

Browse files
committed
add improvements on spring boot support
1 parent 865aab5 commit fb316e0

File tree

7 files changed

+92
-20
lines changed

7 files changed

+92
-20
lines changed

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<module>samples</module>
4141
</modules>
4242

43+
4344
<dependencyManagement>
4445
<dependencies>
4546
<dependency>
@@ -77,7 +78,7 @@
7778
<dependency>
7879
<groupId>org.springframework</groupId>
7980
<artifactId>spring-core</artifactId>
80-
<version>5.1.8.RELEASE</version>
81+
<version>5.2.5.RELEASE</version>
8182
<scope>compile</scope>
8283
</dependency>
8384
</dependencies>
@@ -95,7 +96,7 @@
9596
<plugin>
9697
<groupId>org.apache.maven.plugins</groupId>
9798
<artifactId>maven-surefire-plugin</artifactId>
98-
<!--<version>2.19.1</version> -->
99+
<version>2.22.2</version>
99100
<configuration>
100101
<includes>
101102
<include>**/*IT.java</include>

samples/basic/spring-boot/src/main/java/com/github/containersolutions/operator/sample/SampleComponent.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import com.github.containersolutions.operator.Operator;
44
import io.fabric8.kubernetes.client.KubernetesClient;
5-
import io.fabric8.kubernetes.client.dsl.internal.CustomResourceOperationsImpl;
6-
import org.springframework.beans.factory.annotation.Qualifier;
75
import org.springframework.stereotype.Component;
86

97
/**
@@ -18,17 +16,10 @@ public class SampleComponent {
1816

1917
private final CustomServiceController customServiceController;
2018

21-
/**
22-
* You can use qualifier for custom resource operation in case there are more custom resources for the operator
23-
*/
24-
private final CustomResourceOperationsImpl customResourceOperations;
25-
2619
public SampleComponent(Operator operator, KubernetesClient kubernetesClient,
27-
CustomServiceController customServiceController,
28-
@Qualifier(CustomServiceController.KIND) CustomResourceOperationsImpl customResourceOperations) {
20+
CustomServiceController customServiceController) {
2921
this.operator = operator;
3022
this.kubernetesClient = kubernetesClient;
3123
this.customServiceController = customServiceController;
32-
this.customResourceOperations = customResourceOperations;
3324
}
3425
}
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

spring-boot-starter/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,12 @@
4040
<dependency>
4141
<groupId>org.springframework.boot</groupId>
4242
<artifactId>spring-boot-dependencies</artifactId>
43-
<version>2.1.6.RELEASE</version>
43+
<version>2.2.6.RELEASE</version>
4444
<type>pom</type>
4545
<scope>import</scope>
4646
</dependency>
4747
</dependencies>
4848
</dependencyManagement>
49-
5049
<dependencies>
5150
<dependency>
5251
<groupId>org.springframework.boot</groupId>

spring-boot-starter/src/main/java/com/github/containersolutions/operator/spingboot/starter/OperatorAutoConfiguration.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import com.github.containersolutions.operator.Operator;
44
import com.github.containersolutions.operator.api.ResourceController;
5+
import com.github.containersolutions.operator.processing.retry.GenericRetry;
6+
import com.github.containersolutions.operator.processing.retry.Retry;
57
import io.fabric8.kubernetes.client.ConfigBuilder;
68
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
79
import io.fabric8.kubernetes.client.KubernetesClient;
8-
import io.fabric8.kubernetes.client.dsl.internal.CustomResourceOperationsImpl;
910
import io.fabric8.openshift.client.DefaultOpenShiftClient;
1011
import org.apache.commons.lang3.StringUtils;
1112
import org.slf4j.Logger;
@@ -15,18 +16,17 @@
1516
import org.springframework.boot.context.properties.EnableConfigurationProperties;
1617
import org.springframework.context.annotation.Bean;
1718
import org.springframework.context.annotation.Configuration;
18-
import org.springframework.context.support.GenericApplicationContext;
1919

2020
import java.util.List;
2121

2222
@Configuration
23-
@EnableConfigurationProperties(OperatorProperties.class)
23+
@EnableConfigurationProperties({OperatorProperties.class, RetryProperties.class})
2424
@ConditionalOnMissingBean(Operator.class)
2525
public class OperatorAutoConfiguration {
2626
private static final Logger log = LoggerFactory.getLogger(OperatorAutoConfiguration.class);
2727

2828
@Autowired
29-
private GenericApplicationContext genericApplicationContext;
29+
private RetryProperties retryProperties;
3030

3131
@Autowired
3232
private OperatorProperties operatorProperties;
@@ -55,7 +55,28 @@ public KubernetesClient kubernetesClient() {
5555
@Bean
5656
public Operator operator(KubernetesClient kubernetesClient) {
5757
Operator operator = new Operator(kubernetesClient);
58-
resourceControllers.forEach(r -> operator.registerController(r));
58+
Retry retry = createRetryBasedOnProperties();
59+
resourceControllers.forEach(r -> operator.registerControllerForAllNamespaces(r, retry));
5960
return operator;
6061
}
62+
63+
private Retry createRetryBasedOnProperties() {
64+
GenericRetry retry = new GenericRetry();
65+
if (retryProperties.getInitialInterval() != null) {
66+
retry.setInitialInterval(retryProperties.getInitialInterval());
67+
}
68+
if (retryProperties.getIntervalMultiplier() != null) {
69+
retry.setIntervalMultiplier(retryProperties.getIntervalMultiplier());
70+
}
71+
if (retryProperties.getMaxAttempts() != null) {
72+
retry.setMaxAttempts(retryProperties.getMaxAttempts());
73+
}
74+
if (retryProperties.getMaxElapsedTime() != null) {
75+
retry.setMaxElapsedTime(retryProperties.getMaxElapsedTime());
76+
}
77+
if (retryProperties.getMaxInterval() != null) {
78+
retry.setInitialInterval(retryProperties.getMaxInterval());
79+
}
80+
return retry;
81+
}
6182
}

spring-boot-starter/src/main/java/com/github/containersolutions/operator/spingboot/starter/OperatorProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.springframework.boot.context.properties.ConfigurationProperties;
44

5-
@ConfigurationProperties(prefix = "operator.kubernetes")
5+
@ConfigurationProperties(prefix = "operator.kubernetes.client")
66
public class OperatorProperties {
77

88
private boolean openshift = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.github.containersolutions.operator.spingboot.starter;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
5+
@ConfigurationProperties(prefix = "operator.controller.retry")
6+
public class RetryProperties {
7+
8+
private Integer maxAttempts;
9+
private Long initialInterval;
10+
private Double intervalMultiplier;
11+
private Long maxInterval;
12+
private Long maxElapsedTime;
13+
14+
public Integer getMaxAttempts() {
15+
return maxAttempts;
16+
}
17+
18+
public RetryProperties setMaxAttempts(Integer maxAttempts) {
19+
this.maxAttempts = maxAttempts;
20+
return this;
21+
}
22+
23+
public Long getInitialInterval() {
24+
return initialInterval;
25+
}
26+
27+
public RetryProperties setInitialInterval(Long initialInterval) {
28+
this.initialInterval = initialInterval;
29+
return this;
30+
}
31+
32+
public Double getIntervalMultiplier() {
33+
return intervalMultiplier;
34+
}
35+
36+
public RetryProperties setIntervalMultiplier(Double intervalMultiplier) {
37+
this.intervalMultiplier = intervalMultiplier;
38+
return this;
39+
}
40+
41+
public Long getMaxInterval() {
42+
return maxInterval;
43+
}
44+
45+
public RetryProperties setMaxInterval(Long maxInterval) {
46+
this.maxInterval = maxInterval;
47+
return this;
48+
}
49+
50+
public Long getMaxElapsedTime() {
51+
return maxElapsedTime;
52+
}
53+
54+
public RetryProperties setMaxElapsedTime(Long maxElapsedTime) {
55+
this.maxElapsedTime = maxElapsedTime;
56+
return this;
57+
}
58+
}

0 commit comments

Comments
 (0)