8000 refactor: introduce AbstractControllerConfiguration · r00ta/java-operator-sdk@18bf0c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18bf0c8

Browse files
committed
refactor: introduce AbstractControllerConfiguration
1 parent 25256c7 commit 18bf0c8

File tree

2 files changed

+96
-62
lines changed

2 files changed

+96
-62
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.javaoperatorsdk.operator.api.config;
2+
3+
import io.fabric8.kubernetes.client.CustomResource;
4+
import java.util.Collections;
5+
import java.util.Set;
6+
7+
public abstract class AbstractControllerConfiguration<R extends CustomResource>
8+
implements ControllerConfiguration<R> {
9+
10+
private final String associatedControllerClassName;
11+
private final String name;
12+
private final String crdName;
13+
private final String finalizer;
14+
private final boolean generationAware;
15+
private final Set<String> namespaces;
16+
private final boolean watchAllNamespaces;
17+
private final RetryConfiguration retryConfiguration;
18+
19+
public AbstractControllerConfiguration(
20+
String associatedControllerClassName,
21+
String name,
22+
String crdName,
23+
String finalizer,
24+
boolean generationAware,
25+
Set<String> namespaces,
26+
RetryConfiguration retryConfiguration) {
27+
this.associatedControllerClassName = associatedControllerClassName;
28+
this.name = name;
29+
this.crdName = crdName;
30+
this.finalizer = finalizer;
31+
this.generationAware = generationAware;
32+
this.namespaces =
33+
namespaces != null ? Collections.unmodifiableSet(namespaces) : Collections.emptySet();
34+
this.watchAllNamespaces = this.namespaces.contains(WATCH_ALL_NAMESPACES_MARKER);
35+
this.retryConfiguration =
36+
retryConfiguration == null
37+
? ControllerConfiguration.super.getRetryConfiguration()
38+
: retryConfiguration;
39+
}
40+
41+
@Override
42+
public String getName() {
43+
return name;
44+
}
45+
46+
@Override
47+
public String getCRDName() {
48+
return crdName;
49+
}
50+
51+
@Override
52+
public String getFinalizer() {
53+
return finalizer;
54+
}
55+
56+
@Override
57+
public boolean isGenerationAware() {
58+
return generationAware;
59+
}
60+
61+
@Override
62+
public String getAssociatedControllerClassName() {
63+
return associatedControllerClassName;
64+
}
65+
66+
@Override
67+
public Set<String> getNamespaces() {
68+
return namespaces;
69+
}
70+
71+
@Override
72+
public boolean watchAllNamespaces() {
73+
return watchAllNamespaces;
74+
}
75+
76+
@Override
77+
public RetryConfiguration getRetryConfiguration() {
78+
return retryConfiguration;
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
package io.javaoperatorsdk.quarkus.extension;
22

33
import io.fabric8.kubernetes.client.CustomResource;
4-
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
4+
import io.javaoperatorsdk.operator.api.config.AbstractControllerConfiguration;
55
import io.javaoperatorsdk.operator.api.config.RetryConfiguration;
66
import io.quarkus.runtime.annotations.RecordableConstructor;
77
import java.util.Collections;
88
import java.util.Set;
99

1010
public class QuarkusControllerConfiguration<R extends CustomResource>
11-
implements ControllerConfiguration<R> {
12-
private final String associatedControllerClassName;
13-
private final String name;
14-
private final String crdName;
15-
private final String finalizer;
16-
private final boolean generationAware;
17-
private final Set<String> namespaces;
11+
extends AbstractControllerConfiguration<R> {
12+
1813
private final String crClass;
19-
private final boolean watchAllNamespaces;
20-
private final RetryConfiguration retryConfiguration;
14+
private Class<R> clazz;
2115

2216
@RecordableConstructor
2317
public QuarkusControllerConfiguration(
@@ -29,18 +23,15 @@ public QuarkusControllerConfiguration(
2923
Set<String> namespaces,
3024
String crClass,
3125
RetryConfiguration retryConfiguration) {
32-
this.associatedControllerClassName = associatedControllerClassName;
33-
this.name = name;
34-
this.crdName = crdName;
35-
this.finalizer = finalizer;
36-
this.generationAware = generationAware;
37-
this.namespaces = namespaces;
26+
super(
27+
associatedControllerClassName,
28+
name,
29+
crdName,
30+
finalizer,
31+
generationAware,
32+
namespaces,
33+
retryConfiguration);
3834
this.crClass = crClass;
39-
this.watchAllNamespaces = this.namespaces.contains(WATCH_ALL_NAMESPACES_MARKER);
40-
this.retryConfiguration =
41-
retryConfiguration == null
42-
? ControllerConfiguration.super.getRetryConfiguration()
43-
: retryConfiguration;
4435
}
4536

4637
public static Set<String> asSet(String[] namespaces) {
@@ -59,29 +50,12 @@ public String getCrClass() {
5950
return crClass;
6051
}
6152

62-
@Override
63-
public String getName() {
64-
return name;
65-
}
66-
67-
@Override
68-
public String getCRDName() {
69-
return crdName;
70-
}
71-
72-
@Override
73-
public String getFinalizer() {
74-
return finalizer;
75-
}
76-
77-
@Override
78-
public boolean isGenerationAware() {
79-
return generationAware;
80-
}
81-
8253
@Override
8354
public Class<R> getCustomResourceClass() {
84-
return (Class<R>) loadClass(crClass);
55+
if (clazz == null) {
56+
clazz = (Class<R>) loadClass(crClass);
57+
}
58+
return clazz;
8559
}
8660

8761
private Class<?> loadClass(String className) {
@@ -91,24 +65,4 @@ private Class<?> loadClass(String className) {
9165
throw new IllegalArgumentException("Couldn't find class " + className);
9266
}
9367
}
94-
95-
@Override
96-
public String getAssociatedControllerClassName() {
97-
return associatedControllerClassName;
98-
}
99-
100-
@Override
101-
public Set<String> getNamespaces() {
102-
return namespaces;
103-
}
104-
105-
@Override
106-
public boolean watchAllNamespaces() {
107-
return watchAllNamespaces;
108-
}
109-
110-
@Override
111-
public RetryConfiguration getRetryConfiguration() {
112-
return retryConfiguration;
113-
}
11468
}

0 commit comments

Comments
 (0)
0