|
7 | 7 | import io.fabric8.kubernetes.api.model.HasMetadata;
|
8 | 8 | import io.fabric8.kubernetes.client.Config;
|
9 | 9 | import io.fabric8.kubernetes.client.CustomResource;
|
| 10 | +import io.fabric8.kubernetes.client.utils.Serialization; |
10 | 11 | import io.javaoperatorsdk.operator.api.monitoring.Metrics;
|
11 | 12 | import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
|
12 | 13 | import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceFactory;
|
|
17 | 18 | /** An interface from which to retrieve configuration information. */
|
18 | 19 | public interface ConfigurationService {
|
19 | 20 |
|
20 |
| - ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
21 |
| - |
22 |
| - Cloner DEFAULT_CLONER = new Cloner() { |
23 |
| - @SuppressWarnings("unchecked") |
24 |
| - @Override |
25 |
| - public HasMetadata clone(HasMetadata object) { |
26 |
| - try { |
27 |
| - return OBJECT_MAPPER.readValue(OBJECT_MAPPER.writeValueAsString(object), object.getClass()); |
28 |
| - } catch (JsonProcessingException e) { |
29 |
| - throw new IllegalStateException(e); |
30 |
| - } |
31 |
| - } |
32 |
| - }; |
33 |
| - |
34 | 21 | /**
|
35 | 22 | * Retrieves the configuration associated with the specified reconciler
|
36 | 23 | *
|
@@ -93,12 +80,25 @@ default int concurrentReconciliationThreads() {
|
93 | 80 | }
|
94 | 81 |
|
95 | 82 | /**
|
96 |
| - * Used to clone custom resources. |
| 83 | + * Used to clone custom resources. It is strongly suggested that implementors override this method |
| 84 | + * since the default implementation creates a new {@link Cloner} instance each time this method is |
| 85 | + * called. |
97 | 86 | *
|
98 |
| - * @return the ObjectMapper to use |
| 87 | + * @return the configured {@link Cloner} |
99 | 88 | */
|
100 | 89 | default Cloner getResourceCloner() {
|
101 |
| - return DEFAULT_CLONER; |
| 90 | + return new Cloner() { |
| 91 | + @SuppressWarnings("unchecked") |
| 92 | + @Override |
| 93 | + public HasMetadata clone(HasMetadata object) { |
| 94 | + try { |
| 95 | + final var mapper = getObjectMapper(); |
| 96 | + return mapper.readValue(mapper.writeValueAsString(object), object.getClass()); |
| 97 | + } catch (JsonProcessingException e) { |
| 98 | + throw new IllegalStateException(e); |
| 99 | + } |
| 100 | + } |
| 101 | + }; |
102 | 102 | }
|
103 | 103 |
|
104 | 104 | int DEFAULT_TERMINATION_TIMEOUT_SECONDS = 10;
|
@@ -126,7 +126,7 @@ default boolean closeClientOnStop() {
|
126 | 126 | }
|
127 | 127 |
|
128 | 128 | default ObjectMapper getObjectMapper() {
|
129 |
| - return OBJECT_MAPPER; |
| 129 | + return Serialization.jsonMapper(); |
130 | 130 | }
|
131 | 131 |
|
132 | 132 | default DependentResourceFactory dependentResourceFactory() {
|
|
0 commit comments