@@ -25,7 +25,6 @@ public class Operator implements AutoCloseable {
25
25
private static final Logger log = LoggerFactory .getLogger (Operator .class );
26
26
private final KubernetesClient k8sClient ;
27
27
private final ConfigurationService configurationService ;
28
- private final ReentrantLock lock = new ReentrantLock ();
29
28
private final List <ConfiguredController > controllers = new LinkedList <>();
30
29
private volatile boolean started = false ;
31
30
@@ -65,44 +64,39 @@ public ConfigurationService getConfigurationService() {
65
64
*/
66
65
@ SuppressWarnings ("unchecked" )
67
66
public void start () {
68
- try {
69
- lock .lock ();
70
- if (started ) {
71
- return ;
72
- }
73
- if (controllers .isEmpty ()) {
74
- throw new OperatorException ("No ResourceController exists. Exiting!" );
75
- }
67
+ if (started ) {
68
+ return ;
69
+ }
70
+ if (controllers .isEmpty ()) {
71
+ throw new OperatorException ("No ResourceController exists. Exiting!" );
72
+ }
76
73
77
- final var version = configurationService .getVersion ();
78
- log .info (
79
- "Operator SDK {} (commit: {}) built on {} starting..." ,
80
- version .getSdkVersion (),
81
- version .getCommit (),
82
- version .getBuiltTime ());
74
+ final var version = configurationService .getVersion ();
75
+ log .info (
76
+ "Operator SDK {} (commit: {}) built on {} starting..." ,
77
+ version .getSdkVersion (),
78
+ version .getCommit (),
79
+ version .getBuiltTime ());
83
80
84
- log .info ("Client version: {}" , Version .clientVersion ());
85
- try {
86
- final var k8sVersion = k8sClient .getVersion ();
87
- if (k8sVersion != null ) {
88
- log .info ("Server version: {}.{}" , k8sVersion .getMajor (), k8sVersion .getMinor ());
89
- }
90
- } catch (Exception e ) {
91
- final String error ;
92
- if (e .getCause () instanceof ConnectException ) {
93
- error = "Cannot connect to cluster" ;
94
- } else {
95
- error = "Error retrieving the server version" ;
96
- }
97
- log .error (error , e );
98
- throw new OperatorException (error , e );
81
+ log .info ("Client version: {}" , Version .clientVersion ());
82
+ try {
83
+ final var k8sVersion = k8sClient .getVersion ();
84
+ if (k8sVersion != null ) {
85
+ log .info ("Server version: {}.{}" , k8sVersion .getMajor (), k8sVersion .getMinor ());
99
86
}
100
-
101
- controllers .parallelStream ().forEach (ConfiguredController ::start );
102
- started = true ;
103
- } finally {
104
- lock .unlock ();
87
+ } catch (Exception e ) {
88
+ final String error ;
89
+ if (e .getCause () instanceof ConnectException ) {
90
+ error = "Cannot connect to cluster" ;
91
+ } else {
92
+ error = "Error retrieving the server version" ;
93
+ }
94
+ log .error (error , e );
95
+ throw new OperatorException (error , e );
105
96
}
97
+
98
+ controllers .parallelStream ().forEach (ConfiguredController ::start );
99
+ started = true ;
106
100
}
107
101
108
102
/** Stop the operator. */
@@ -111,25 +105,20 @@ public void close() {
111
105
log .info (
112
106
"Operator SDK {} is shutting down..." , configurationService .getVersion ().getSdkVersion ());
113
107
114
- try {
115
- lock .lock ();
116
- if (!started ) {
117
- return ;
108
+ if (!started ) {
109
+ return ;
110
+ }
111
+
112
+ this .controllers .parallelStream ().forEach (closeable -> {
113
+ try {
114
+ log .debug ("closing {}" , closeable );
115
+ closeable .close ();
116
+ } catch (IOException e ) {
117
+ log .warn ("Error closing {}" , closeable , e );
118
118
}
119
+ });
119
120
120
- this .controllers .parallelStream ().forEach (closeable -> {
121
- try {
122
- log .debug ("closing {}" , closeable );
123
- closeable .close ();
124
- } catch (IOException e ) {
125
- log .warn ("Error closing {}" , closeable , e );
126
- }
127
- });
128
-
129
- started = false ;
130
- } finally {
131
- lock .unlock ();
132
- }
121
+ started = false ;
133
122
}
134
123
135
124
/**
@@ -173,13 +162,11 @@ public <R extends CustomResource> void register(
173
162
if (configuration == null ) {
174
163
configuration = existing ;
175
164
}
176
- synchronized (lock ) {
177
- final var configuredController =
178
- new ConfiguredController (controller , configuration , k8sClient );
179
- this .controllers .add (configuredController );
180
- if (started ) {
181
- configuredController .start ();
182
- }
165
+ final var configuredController =
166
+ new ConfiguredController (controller , configuration , k8sClient );
167
+ this .controllers .add (configuredController );
168
+ if (started ) {
169
+ configuredController .start ();
183
170
}
184
171
185
172
final var watchedNS =
0 commit comments