@@ -35,6 +35,7 @@ public abstract class KubernetesDependentResource<R extends HasMetadata, P exten
35
35
private InformerEventSource <R , P > informerEventSource ;
36
36
private boolean addOwnerReference ;
37
37
protected ResourceMatcher resourceMatcher ;
38
+ protected ResourceUpdatePreProcessor <R > resourceUpdatePreProcessor ;
38
39
39
40
@ Override
40
41
public void configureWith (KubernetesDependentResourceConfig config ) {
@@ -74,10 +75,10 @@ public void configureWith(ConfigurationService configurationService,
74
75
boolean addOwnerReference ) {
75
76
this .informerEventSource = informerEventSource ;
76
77
this .addOwnerReference = addOwnerReference ;
77
- initResourceMatcherIfNotSet (configurationService );
78
+ initResourceMatcherAndUpdatePreProcessorIfNotSet (configurationService );
78
79
}
79
80
80
- protected void beforeCreateOrUpdate (R desired , P primary ) {
81
+ protected void beforeCreate (R desired , P primary ) {
81
82
if (addOwnerReference ) {
82
83
desired .addOwnerReference (primary );
83
84
}
@@ -93,7 +94,7 @@ protected boolean match(R actualResource, R desiredResource, Context context) {
93
94
protected R create (R target , P primary , Context context ) {
94
95
log .debug ("Creating target resource with type: " +
95
96
"{}, with id: {}" , target .getClass (), ResourceID .fromResource (target ));
96
- beforeCreateOrUpdate (target , primary );
97
+ beforeCreate (target , primary );
97
98
Class <R > targetClass = (Class <R >) target .getClass ();
98
99
return client .resources (targetClass ).inNamespace (target .getMetadata ().getNamespace ())
99
100
.create (target );
@@ -104,15 +105,15 @@ protected R create(R target, P primary, Context context) {
104
105
protected R update (R actual , R target , P primary , Context context ) {
105
106
log .debug ("Updating target resource with type: {}, with id: {}" , target .getClass (),
106
107
ResourceID .fromResource (target ));
107
- beforeCreateOrUpdate (target , primary );
108
108
Class <R > targetClass = (Class <R >) target .getClass ();
109
+ var updatedActual = resourceUpdatePreProcessor .replaceSpecOnActual (actual , target );
109
110
return client .resources (targetClass ).inNamespace (target .getMetadata ().getNamespace ())
110
- .replace (target );
111
+ .replace (updatedActual );
111
112
}
112
113
113
114
@ Override
114
115
public EventSource eventSource (EventSourceContext <P > context ) {
115
- initResourceMatcherIfNotSet (context .getConfigurationService ());
116
+ initResourceMatcherAndUpdatePreProcessorIfNotSet (context .getConfigurationService ());
116
117
if (informerEventSource == null ) {
117
118
configureWith (context .getConfigurationService (), null , null ,
118
119
KubernetesDependent .ADD_OWNER_REFERENCE_DEFAULT );
@@ -156,10 +157,25 @@ public void setKubernetesClient(KubernetesClient kubernetesClient) {
156
157
*
157
158
* @param configurationService config service to mainly access object mapper
158
159
*/
159
- protected void initResourceMatcherIfNotSet (ConfigurationService configurationService ) {
160
+ protected void initResourceMatcherAndUpdatePreProcessorIfNotSet (
161
+ ConfigurationService configurationService ) {
160
162
if (resourceMatcher == null ) {
161
163
resourceMatcher = new DesiredValueMatcher (configurationService .getObjectMapper ());
162
164
}
165
+ if (resourceUpdatePreProcessor == null ) {
166
+ resourceUpdatePreProcessor =
167
+ new ResourceUpdatePreProcessor <>(configurationService .getResourceCloner ());
168
+ }
169
+ }
170
+
171
+ public KubernetesDependentResource <R , P > setResourceMatcher (ResourceMatcher resourceMatcher ) {
172
+ this .resourceMatcher = resourceMatcher ;
173
+ return this ;
163
174
}
164
175
176
+ public KubernetesDependentResource <R , P > setResourceUpdatePreProcessor (
177
+ ResourceUpdatePreProcessor <R > resourceUpdatePreProcessor ) {
178
+ this .resourceUpdatePreProcessor = resourceUpdatePreProcessor ;
179
+ return this ;
180
+ }
165
181
}
0 commit comments