Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 65bf68d

Browse files
csvirimetacosm
authored andcommittedOct 10, 2024
improve: remove deprecated APIs (#2375)
Signed-off-by: Attila Mészáros <csviri@gmail.com>
1 parent e53a84c commit 65bf68d

File tree

22 files changed

+27
-300
lines changed

22 files changed

+27
-300
lines changed
 

‎micrometer-support/src/main/java/io/javaoperatorsdk/operator/monitoring/micrometer/MicrometerMetrics.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@ public class MicrometerMetrics implements Metrics {
5959
private final Map<String, AtomicInteger> gauges = new ConcurrentHashMap<>();
6060
private final Cleaner cleaner;
6161

62-
/**
63-
* Creates a default micrometer-based Metrics implementation, collecting metrics on a per resource
64-
* basis and not dealing with cleaning these after these resources are deleted. Note that this
65-
* probably will change in a future release. If you want more control over what the implementation
66-
* actually does, please use the static factory methods instead.
67-
*
68-
* @param registry the {@link MeterRegistry} instance to use for metrics recording
69-
* @deprecated Use the factory methods / builders instead
70-
*/
71-
@Deprecated
72-
public MicrometerMetrics(MeterRegistry registry) {
73-
this(registry, Cleaner.NOOP, true);
74-
}
75-
7662
/**
7763
* Creates a MicrometerMetrics instance configured to not collect per-resource metrics, just
7864
* aggregates per resource **type**

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/Operator.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public Operator() {
3535
}
3636

3737
Operator(KubernetesClient kubernetesClient) {
38-
this(kubernetesClient, null);
38+
this(initConfigurationService(kubernetesClient, null));
3939
}
4040

4141
/**
@@ -63,19 +63,7 @@ public Operator(ConfigurationService configurationService) {
6363
* {@link ConfigurationService} values
6464
*/
6565
public Operator(Consumer<ConfigurationServiceOverrider> overrider) {
66-
this(null, overrider);
67-
}
68-
69-
/**
70-
* @param client client to use to all Kubernetes related operations
71-
* @param overrider a {@link ConfigurationServiceOverrider} consumer used to override the default
72-
* {@link ConfigurationService} values
73-
* @deprecated Use {@link Operator#Operator(Consumer)} instead, passing your custom client with
74-
* {@link ConfigurationServiceOverrider#withKubernetesClient(KubernetesClient)}
75-
*/
76-
@Deprecated(since = "4.4.0")
77-
public Operator(KubernetesClient client, Consumer<ConfigurationServiceOverrider> overrider) {
78-
this(initConfigurationService(client, overrider));
66+
this(initConfigurationService(null, overrider));
7967
}
8068

8169
private static ConfigurationService initConfigurationService(KubernetesClient client,

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationService.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ default boolean checkCRDAndValidateLocalModel() {
132132
}
133133

134134
int DEFAULT_RECONCILIATION_THREADS_NUMBER = 50;
135-
/**
136-
* @deprecated Not used anymore in the default implementation
137-
*/
138-
@Deprecated(forRemoval = true)
139-
int MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER = 10;
140135

141136
/**
142137
* The number of threads the operator can spin out to dispatch reconciliation requests to
@@ -148,23 +143,7 @@ default int concurrentReconciliationThreads() {
148143
return DEFAULT_RECONCILIATION_THREADS_NUMBER;
149144
}
150145

151-
/**
152-
* The minimum number of threads the operator starts in the thread pool for reconciliations.
153-
*
154-
* @deprecated not used anymore by default executor implementation
155-
* @return the minimum number of concurrent reconciliation threads
156-
*/
157-
@Deprecated(forRemoval = true)
158-
default int minConcurrentReconciliationThreads() {
159-
return MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER;
160-
}
161-
162146
int DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = DEFAULT_RECONCILIATION_THREADS_NUMBER;
163-
/**
164-
* @deprecated Not used anymore in the default implementation
165-
*/
166-
@Deprecated(forRemoval = true)
167-
int MIN_DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER = MIN_DEFAULT_RECONCILIATION_THREADS_NUMBER;
168147

169148
/**
170149
* Number of threads the operator can spin out to be used in the workflows with the default
@@ -176,17 +155,6 @@ default int concurrentWorkflowExecutorThreads() {
176155
return DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER;
177156
}
178157

179-
/**
180-
* The minimum number of threads the operator starts in the thread pool for workflows.
181-
*
182-
* @deprecated not used anymore by default executor implementation
183-
* @return the minimum number of concurrent workflow threads
184-
*/
185-
@Deprecated(forRemoval = true)
186-
default int minConcurrentWorkflowExecutorThreads() {
187-
return MIN_DEFAULT_WORKFLOW_EXECUTOR_THREAD_NUMBER;
188-
}
189-
190158
default Metrics getMetrics() {
191159
return Metrics.NOOP;
192160
}

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverrider.java

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.Optional;
55
import java.util.Set;
66
import java.util.concurrent.ExecutorService;
7-
import java.util.function.Consumer;
87
import java.util.function.Function;
98

109
import org.slf4j.Logger;
@@ -23,9 +22,7 @@ public class ConfigurationServiceOverrider {
2322
private Metrics metrics;
2423
private Boolean checkCR;
2524
private Integer concurrentReconciliationThreads;
26-
private Integer minConcurrentReconciliationThreads;
2725
private Integer concurrentWorkflowExecutorThreads;
28-
private Integer minConcurrentWorkflowExecutorThreads;
2926
private Cloner cloner;
3027
private Boolean closeClientOnStop;
3128
private KubernetesClient client;
@@ -64,24 +61,6 @@ public ConfigurationServiceOverrider withConcurrentWorkflowExecutorThreads(int t
6461
return this;
6562
}
6663

67-
private int minimumMaxValueFor(Integer minValue) {
68-
return minValue != null ? (minValue < 0 ? 0 : minValue) + 1 : 1;
69-
}
70-
71-
public ConfigurationServiceOverrider withMinConcurrentReconciliationThreads(int threadNumber) {
72-
this.minConcurrentReconciliationThreads = Utils.ensureValid(threadNumber,
73-
"minimum reconciliation threads", ExecutorServiceManager.MIN_THREAD_NUMBER,
74-
original.minConcurrentReconciliationThreads());
75-
return this;
76-
}
77-
78-
public ConfigurationServiceOverrider withMinConcurrentWorkflowExecutorThreads(int threadNumber) {
79-
this.minConcurrentWorkflowExecutorThreads = Utils.ensureValid(threadNumber,
80-
"minimum workflow execution threads", ExecutorServiceManager.MIN_THREAD_NUMBER,
81-
original.minConcurrentWorkflowExecutorThreads());
82-
return this;
83-
}
84-
8564
@SuppressWarnings("rawtypes")
8665
public ConfigurationServiceOverrider withDependentResourceFactory(
8766
DependentResourceFactory dependentResourceFactory) {
@@ -222,7 +201,7 @@ public int concurrentReconciliationThreads() {
222201
overriddenValueOrDefault(concurrentReconciliationThreads,
223202
ConfigurationService::concurrentReconciliationThreads),
224203
"maximum reconciliation threads",
225-
minimumMaxValueFor(minConcurrentReconciliationThreads),
204+
1,
226205
original.concurrentReconciliationThreads());
227206
}
228207

@@ -232,30 +211,10 @@ public int concurrentWorkflowExecutorThreads() {
232211
overriddenValueOrDefault(concurrentWorkflowExecutorThreads,
233212
ConfigurationService::concurrentWorkflowExecutorThreads),
234213
"maximum workflow execution threads",
235-
minimumMaxValueFor(minConcurrentWorkflowExecutorThreads),
214+
1,
236215
original.concurrentWorkflowExecutorThreads());
237216
}
238217

239-
/**
240-
* @deprecated Not used anymore in the default implementation
241-
*/
242-
@Deprecated(forRemoval = true)
243-
@Override
244-
public int minConcurrentReconciliationThreads() {
245-
return overriddenValueOrDefault(minConcurrentReconciliationThreads,
246-
ConfigurationService::minConcurrentReconciliationThreads);
247-
}
248-
249-
/**
250-
* @deprecated Not used anymore in the default implementation
251-
*/
252-
@Override
253-
@Deprecated(forRemoval = true)
254-
public int minConcurrentWorkflowExecutorThreads() {
255-
return overriddenValueOrDefault(minConcurrentWorkflowExecutorThreads,
256-
ConfigurationService::minConcurrentWorkflowExecutorThreads);
257-
}
258-
259218
@Override
260219
public Metrics getMetrics() {
261220
return overriddenValueOrDefault(metrics, ConfigurationService::getMetrics);
@@ -344,15 +303,4 @@ public boolean cloneSecondaryResourcesWhenGettingFromCache() {
344303
};
345304
}
346305

347-
/**
348-
* @deprecated Use
349-
* {@link ConfigurationService#newOverriddenConfigurationService(ConfigurationService, Consumer)}
350-
* instead
351-
* @param original that will be overridden
352-
* @return current overrider
353-
*/
354-
@Deprecated(since = "2.2.0")
355-
public static ConfigurationServiceOverrider override(ConfigurationService original) {
356-
return new ConfigurationServiceOverrider(original);
357-
}
358306
}

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/ExecutorServiceManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
public class ExecutorServiceManager {
2323

2424
private static final Logger log = LoggerFactory.getLogger(ExecutorServiceManager.class);
25-
public static final int MIN_THREAD_NUMBER = 0;
2625
private ExecutorService executor;
2726
private ExecutorService workflowExecutor;
2827
private ExecutorService cachingExecutorService;

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/monitoring/Metrics.java

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.javaoperatorsdk.operator.api.monitoring;
22

3-
import java.util.Collections;
43
import java.util.Map;
54

65
import io.fabric8.kubernetes.api.model.HasMetadata;
@@ -37,16 +36,6 @@ default void controllerRegistered(Controller<? extends HasMetadata> controller)
3736
*/
3837
default void receivedEvent(Event event, Map<String, Object> metadata) {}
3938

40-
/**
41-
* @param metadata additional metadata
42-
* @param resourceID of primary resource
43-
* @param retryInfo for current execution
44-
* @deprecated Use {@link #reconcileCustomResource(HasMetadata, RetryInfo, Map)} instead
45-
*/
46-
@Deprecated(forRemoval = true)
47-
@SuppressWarnings("unused")
48-
default void reconcileCustomResource(ResourceID resourceID, RetryInfo retryInfo,
49-
Map<String, Object> metadata) {}
5039

5140
/**
5241
* Called right before a resource is dispatched to the ExecutorService for reconciliation.
@@ -56,19 +45,6 @@ default void reconcileCustomResource(ResourceID resourceID, RetryInfo retryInfo,
5645
* @param metadata metadata associated with the resource being processed
5746
*/
5847
default void reconcileCustomResource(HasMetadata resource, RetryInfo retryInfo,
59-
Map<String, Object> metadata) {
60-
reconcileCustomResource(ResourceID.fromResource(resource), retryInfo, metadata);
61-
}
62-
63-
/**
64-
* @param exception actual exception
65-
* @param metadata additional metadata
66-
* @param resourceID of primary resource
67-
* @deprecated Use {@link #failedReconciliation(HasMetadata, Exception, Map)} instead
68-
*/
69-
@Deprecated(forRemoval = true)
70-
@SuppressWarnings("unused")
71-
default void failedReconciliation(ResourceID resourceID, Exception exception,
7248
Map<String, Object> metadata) {}
7349

7450
/**
@@ -81,24 +57,14 @@ default void failedReconciliation(ResourceID resourceID, Exception exception,
8157
* @param metadata metadata associated with the resource being processed
8258
*/
8359
default void failedReconciliation(HasMetadata resource, Exception exception,
84-
Map<String, Object> metadata) {
85-
failedReconciliation(ResourceID.fromResource(resource), exception, metadata);
86-
}
60+
Map<String, Object> metadata) {}
8761

8862

8963
default void reconciliationExecutionStarted(HasMetadata resource, Map<String, Object> metadata) {}
9064

9165
default void reconciliationExecutionFinished(HasMetadata resource,
9266
Map<String, Object> metadata) {}
9367

94-
/**
95-
* @param resourceID of primary resource
96-
* @deprecated Use (and implement) {@link #cleanupDoneFor(ResourceID, Map)} instead
97-
*/
98-
@Deprecated
99-
default void cleanupDoneFor(ResourceID resourceID) {
100-
cleanupDoneFor(resourceID, Collections.emptyMap());
101-
}
10268

10369
/**
10470
* Called when the resource associated with the specified {@link ResourceID} has been successfully
@@ -109,24 +75,6 @@ default void cleanupDoneFor(ResourceID resourceID) {
10975
*/
11076
default void cleanupDoneFor(ResourceID resourceID, Map<String, Object> metadata) {}
11177

112-
/**
113-
* @param resourceID of primary resource
114-
* @deprecated Use (and implement) {@link #finishedReconciliation(ResourceID, Map)} instead
115-
*/
116-
@Deprecated
117-
default void finishedReconciliation(ResourceID resourceID) {
118-
finishedReconciliation(resourceID, Collections.emptyMap());
119-
}
120-
121-
/**
122-
* @param resourceID of primary resource
123-
* @param metadata additional metadata
124-
* @deprecated Use {@link #finishedReconciliation(HasMetadata, Map)} instead
125-
*/
126-
@Deprecated(forRemoval = true)
127-
@SuppressWarnings("unused")
128-
default void finishedReconciliation(ResourceID resourceID, Map<String, Object> metadata) {}
129-
13078
/**
13179
* Called when the
13280
* {@link io.javaoperatorsdk.operator.api.reconciler.Reconciler#reconcile(HasMetadata, Context)}
@@ -136,9 +84,7 @@ default void finishedReconciliation(ResourceID resourceID, Map<String, Object> m
13684
* @param resource the {@link ResourceID} associated with the resource being processed
13785
* @param metadata metadata associated with the resource being processed
13886
*/
139-
default void finishedReconciliation(HasMetadata resource, Map<String, Object> metadata) {
140-
finishedReconciliation(ResourceID.fromResource(resource), metadata);
141-
}
87+
default void finishedReconciliation(HasMetadata resource, Map<String, Object> metadata) {}
14288

14389
/**
14490
* Encapsulates the information about a controller execution i.e. a call to either

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/KubernetesClientAware.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResourceConfig.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,6 @@ public KubernetesDependentResourceConfig(Set<String> namespaces,
5252
this.useSSA = useSSA;
5353
}
5454

55-
// use builder instead
56-
@Deprecated(forRemoval = true)
57-
public KubernetesDependentResourceConfig(Set<String> namespaces, String labelSelector) {
58-
this(namespaces, labelSelector, true, DEFAULT_CREATE_RESOURCE_ONLY_IF_NOT_EXISTING_WITH_SSA,
59-
null, null,
60-
null, null, null);
61-
}
62-
63-
// use builder instead
64-
@Deprecated(forRemoval = true)
65-
public KubernetesDependentResourceConfig<R> setLabelSelector(String labelSelector) {
66-
this.labelSelector = labelSelector;
67-
return this;
68-
}
69-
7055
public Set<String> namespaces() {
7156
return namespaces;
7257
}

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultManagedWorkflow.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
1414
import io.javaoperatorsdk.operator.api.reconciler.dependent.EventSourceReferencer;
1515
import io.javaoperatorsdk.operator.api.reconciler.dependent.NameSetter;
16-
import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.KubernetesClientAware;
1716

1817
import static io.javaoperatorsdk.operator.api.reconciler.Constants.NO_VALUE_SET;
1918

@@ -112,10 +111,6 @@ private <R> DependentResource<R, P> resolve(DependentResourceSpec<R, P> spec,
112111
((NameSetter) dependentResource).setName(name);
113112
}
114113

115-
if (dependentResource instanceof KubernetesClientAware) {
116-
((KubernetesClientAware) dependentResource).setKubernetesClient(client);
117-
}
118-
119114
spec.getUseEventSourceWithName()
120115
.ifPresent(esName -> {
121116
if (dependentResource instanceof EventSourceReferencer) {

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/WorkflowResult.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ public Map<DependentResource, Exception> getErroredDependents() {
2121
return erroredDependents;
2222
}
2323

24-
/**
25-
* @deprecated Use {@link #erroredDependentsExist()} instead
26-
* @return if any dependents are in error state
27-
*/
28-
@Deprecated(forRemoval = true)
29-
public boolean erroredDependentsExists() {
30-
return !erroredDependents.isEmpty();
31-
}
32-
3324
@SuppressWarnings("unused")
3425
public boolean erroredDependentsExist() {
3526
return !erroredDependents.isEmpty();

‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/InformerEventSource.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,6 @@ public Set<R> getSecondaryResources(P primary) {
255255
.collect(Collectors.toSet());
256256
}
257257

258-
/**
259-
* Returns the configuration object for the informer.
260-
*
261-
* @return the informer configuration object
262-
*
263-
* @deprecated Use {@link #configuration()} instead
264-
*/
265-
@Deprecated(forRemoval = true)
266-
public InformerConfiguration<R> getConfiguration() {
267-
return configuration();
268-
}
269-
270258
@Override
271259
public synchronized void handleRecentResourceUpdate(ResourceID resourceID, R resource,
272260
R previousVersionOfResource) {

‎operator-framework-core/src/test/java/io/javaoperatorsdk/operator/api/config/ConfigurationServiceOverriderTest.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import io.fabric8.kubernetes.api.model.HasMetadata;
99
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
1010

11-
import static org.junit.jupiter.api.Assertions.assertEquals;
1211
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1312

1413
class ConfigurationServiceOverriderTest {
@@ -80,24 +79,4 @@ public <R extends HasMetadata> R clone(R object) {
8079
overridden.getLeaderElectionConfiguration());
8180
}
8281

83-
@Test
84-
void shouldReplaceInvalidValues() {
85-
final var original = new BaseConfigurationService();
86-
87-
final var service = ConfigurationService.newOverriddenConfigurationService(original,
88-
o -> o
89-
.withConcurrentReconciliationThreads(0)
90-
.withMinConcurrentReconciliationThreads(-1)
91-
.withConcurrentWorkflowExecutorThreads(2)
92-
.withMinConcurrentWorkflowExecutorThreads(3));
93-
94-
assertEquals(original.minConcurrentReconciliationThreads(),
95-
service.minConcurrentReconciliationThreads());
96-
assertEquals(original.concurrentReconciliationThreads(),
97-
service.concurrentReconciliationThreads());
98-
assertEquals(3, service.minConcurrentWorkflowExecutorThreads());
99-
assertEquals(original.concurrentWorkflowExecutorThreads(),
100-
service.concurrentWorkflowExecutorThreads());
101-
}
102-
10382
}

‎operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/AbstractOperatorExtension.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,30 +111,15 @@ public <T extends HasMetadata> T create(T resource) {
111111
return kubernetesClient.resource(resource).inNamespace(namespace).create();
112112
}
113113

114-
@Deprecated(forRemoval = true)
115-
public <T extends HasMetadata> T create(Class<T> type, T resource) {
116-
return create(resource);
117-
}
118-
119114
public <T extends HasMetadata> T replace(T resource) {
120115
return kubernetesClient.resource(resource).inNamespace(namespace).replace();
121116
}
122117

123-
@Deprecated(forRemoval = true)
124-
public <T extends HasMetadata> T replace(Class<T> type, T resource) {
125-
return replace(resource);
126-
}
127-
128118
public <T extends HasMetadata> boolean delete(T resource) {
129119
var res = kubernetesClient.resource(resource).inNamespace(namespace).delete();
130120
return res.size() == 1 && res.get(0).getCauses().isEmpty();
131121
}
132122

133-
@Deprecated(forRemoval = true)
134-
public <T extends HasMetadata> boolean delete(Class<T> type, T resource) {
135-
return delete(resource);
136-
}
137-
138123
protected void beforeAllImpl(ExtensionContext context) {
139124
if (oneNamespacePerClass) {
140125
namespace = perClassNamespaceNameSupplier.apply(context);

‎operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/KubernetesClientAware.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎operator-framework-junit5/src/main/java/io/javaoperatorsdk/operator/junit/LocallyRunOperatorExtension.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ private LocallyRunOperatorExtension(
7070
this.portForwards = portForwards;
7171
this.localPortForwards = new ArrayList<>(portForwards.size());
7272
this.additionalCustomResourceDefinitions = additionalCustomResourceDefinitions;
73-
this.operator = new Operator(getKubernetesClient(), configurationServiceOverrider);
73+
this.operator = new Operator(
74+
configurationServiceOverrider == null ? o -> o.withKubernetesClient(getKubernetesClient())
75+
: configurationServiceOverrider
76+
.andThen(o -> o.withKubernetesClient(getKubernetesClient())));
7477
this.registeredControllers = new HashMap<>();
7578
}
7679

‎operator-framework/src/test/java/io/javaoperatorsdk/operator/InformerRelatedBehaviorITS.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,9 @@ Operator startOperator(boolean stopOnInformerErrorDuringStartup, boolean addStop
316316

317317
reconciler = new InformerRelatedBehaviorTestReconciler();
318318

319-
Operator operator = new Operator(clientUsingServiceAccount(),
319+
Operator operator = new Operator(
320320
co -> {
321+
co.withKubernetesClient(clientUsingServiceAccount());
321322
co.withStopOnInformerErrorDuringStartup(stopOnInformerErrorDuringStartup);
322323
co.withCacheSyncTimeout(Duration.ofMillis(3000));
323324
if (addStopHandler) {

‎operator-framework/src/test/java/io/javaoperatorsdk/operator/LeaderElectionPermissionIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ void operatorStopsIfNoLeaderElectionPermission() {
3232
.withImpersonateUsername("leader-elector-stop-noaccess")
3333
.build()).build();
3434

35-
var operator = new Operator(client, o -> {
35+
var operator = new Operator(o -> {
36+
o.withKubernetesClient(client);
3637
o.withLeaderElectionConfiguration(
3738
new LeaderElectionConfiguration("lease1", "default"));
3839
o.withStopOnInformerErrorDuringStartup(false);

‎operator-framework/src/test/java/io/javaoperatorsdk/operator/PerResourcePollingEventSourceIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class PerResourcePollingEventSourceIT {
2828
**/
2929
@Test
3030
void fetchedAndReconciledMultipleTimes() {
31-
operator.create(PerResourceEventSourceCustomResource.class, resource(NAME_1));
32-
operator.create(PerResourceEventSourceCustomResource.class, resource(NAME_2));
31+
operator.create(resource(NAME_1));
32+
operator.create(resource(NAME_2));
3333

3434
var reconciler =
3535
operator.getReconcilerOfType(PerResourcePollingEventSourceTestReconciler.class);

‎sample-operators/leader-election/src/main/java/io/javaoperatorsdk/operator/sample/LeaderElectionTestOperator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55

6-
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
76
import io.javaoperatorsdk.operator.Operator;
87
import io.javaoperatorsdk.operator.api.config.LeaderElectionConfiguration;
98

@@ -22,9 +21,8 @@ public static void main(String[] args) {
2221
? new LeaderElectionConfiguration("leader-election-test")
2322
: new LeaderElectionConfiguration("leader-election-test", namespace, identity);
2423

25-
var client = new KubernetesClientBuilder().build();
2624
Operator operator =
27-
new Operator(client, c -> c.withLeaderElectionConfiguration(leaderElectionConfiguration));
25+
new Operator(c -> c.withLeaderElectionConfiguration(leaderElectionConfiguration));
2826

2927
operator.register(new LeaderElectionTestReconciler(identity));
3028
operator.start();

‎sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageOperator.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
88

9-
import io.fabric8.kubernetes.client.KubernetesClient;
10-
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
119
import io.javaoperatorsdk.operator.Operator;
1210
import io.javaoperatorsdk.operator.sample.probes.LivenessHandler;
1311
import io.javaoperatorsdk.operator.sample.probes.StartupHandler;
@@ -28,11 +26,10 @@ public class WebPageOperator {
2826
public static void main(String[] args) throws IOException {
2927
log.info("WebServer Operator starting!");
3028

31-
KubernetesClient client = new KubernetesClientBuilder().build();
32-
Operator operator = new Operator(client, o -> o.withStopOnInformerErrorDuringStartup(false));
29+
Operator operator = new Operator(o -> o.withStopOnInformerErrorDuringStartup(false));
3330
String reconcilerEnvVar = System.getenv(WEBPAGE_RECONCILER_ENV);
3431
if (WEBPAGE_CLASSIC_RECONCILER_ENV_VALUE.equals(reconcilerEnvVar)) {
35-
operator.register(new WebPageReconciler(client));
32+
operator.register(new WebPageReconciler());
3633
} else if (WEBPAGE_MANAGED_DEPENDENT_RESOURCE_ENV_VALUE
3734
.equals(reconcilerEnvVar)) {
3835
operator.register(new WebPageManagedDependentsReconciler());

‎sample-operators/webpage/src/main/java/io/javaoperatorsdk/operator/sample/WebPageReconciler.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import io.fabric8.kubernetes.api.model.*;
1313
import io.fabric8.kubernetes.api.model.apps.Deployment;
1414
import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
15-
import io.fabric8.kubernetes.client.KubernetesClient;
1615
import io.javaoperatorsdk.operator.ReconcilerUtils;
1716
import io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration;
1817
import io.javaoperatorsdk.operator.api.reconciler.*;
@@ -35,10 +34,8 @@ public class WebPageReconciler
3534

3635
private static final Logger log = LoggerFactory.getLogger(WebPageReconciler.class);
3736

38-
private final KubernetesClient kubernetesClient;
37+
public WebPageReconciler() {
3938

40-
public WebPageReconciler(KubernetesClient kubernetesClient) {
41-
this.kubernetesClient = kubernetesClient;
4239
}
4340

4441
@Override
@@ -89,7 +86,7 @@ public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> contex
8986
"Creating or updating ConfigMap {} in {}",
9087
desiredHtmlConfigMap.getMetadata().getName(),
9188
ns);
92-
kubernetesClient.configMaps().inNamespace(ns).resource(desiredHtmlConfigMap)
89+
context.getClient().configMaps().inNamespace(ns).resource(desiredHtmlConfigMap)
9390
.serverSideApply();
9491
}
9592

@@ -99,7 +96,7 @@ public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> contex
9996
"Creating or updating Deployment {} in {}",
10097
desiredDeployment.getMetadata().getName(),
10198
ns);
102-
kubernetesClient.apps().deployments().inNamespace(ns).resource(desiredDeployment)
99+
context.getClient().apps().deployments().inNamespace(ns).resource(desiredDeployment)
103100
.serverSideApply();
104101
}
105102

@@ -109,19 +106,19 @@ public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> contex
109106
"Creating or updating Deployment {} in {}",
110107
desiredDeployment.getMetadata().getName(),
111108
ns);
112-
kubernetesClient.services().inNamespace(ns).resource(desiredService)
109+
context.getClient().services().inNamespace(ns).resource(desiredService)
113110
.serverSideApply();
114111
}
115112

116113
var existingIngress = context.getSecondaryResource(Ingress.class);
117114
if (Boolean.TRUE.equals(webPage.getSpec().getExposed())) {
118115
var desiredIngress = makeDesiredIngress(webPage);
119116
if (existingIngress.isEmpty() || !match(desiredIngress, existingIngress.get())) {
120-
kubernetesClient.resource(desiredIngress).inNamespace(ns).serverSideApply();
117+
context.getClient().resource(desiredIngress).inNamespace(ns).serverSideApply();
121118
}
122119
} else
123120
existingIngress.ifPresent(
124-
ingress -> kubernetesClient.resource(ingress).delete());
121+
ingress -> context.getClient().resource(ingress).delete());
125122

126123
// not that this is not necessary, eventually mounted config map would be updated, just this way
127124
// is much faster; what is handy for demo purposes.
@@ -130,7 +127,7 @@ public UpdateControl<WebPage> reconcile(WebPage webPage, Context<WebPage> contex
130127
previousConfigMap.getData().get(INDEX_HTML),
131128
desiredHtmlConfigMap.getData().get(INDEX_HTML))) {
132129
log.info("Restarting pods because HTML has changed in {}", ns);
133-
kubernetesClient.pods().inNamespace(ns).withLabel("app", deploymentName(webPage)).delete();
130+
context.getClient().pods().inNamespace(ns).withLabel("app", deploymentName(webPage)).delete();
134131
}
135132

136133
return UpdateControl.patchStatus(

‎sample-operators/webpage/src/test/java/io/javaoperatorsdk/operator/sample/WebPageOperatorE2E.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public WebPageOperatorE2E() throws FileNotFoundException {}
2727
isLocal()
2828
? LocallyRunOperatorExtension.builder()
2929
.waitForNamespaceDeletion(false)
30-
.withReconciler(new WebPageReconciler(client))
30+
.withReconciler(new WebPageReconciler())
3131
.build()
3232
: ClusterDeployedOperatorExtension.builder()
3333
.waitForNamespaceDeletion(false)

0 commit comments

Comments
 (0)
Please sign in to comment.