13
13
import io .javaoperatorsdk .operator .api .reconciler .support .PrimaryResourceCache ;
14
14
import io .javaoperatorsdk .operator .processing .event .ResourceID ;
15
15
16
- // todo javadoc
17
16
public class PrimaryUpdateAndCacheUtils {
18
17
19
18
private PrimaryUpdateAndCacheUtils () {}
20
19
21
20
private static final Logger log = LoggerFactory .getLogger (PrimaryUpdateAndCacheUtils .class );
22
21
23
- public static <P extends HasMetadata > P updateAndCacheStatus (P primary , Context <P > context ) {
22
+ /**
23
+ * Makes sure that the up-to-date primary resource will be present during the next reconciliation.
24
+ * Using update (PUT) method.
25
+ *
26
+ * @param primary resource
27
+ * @param context of reconciliation
28
+ * @return updated resource
29
+ * @param <P> primary resource type
30
+ */
31
+ public static <P extends HasMetadata > P updateAndCacheStatusWithLock (
32
+ P primary , Context <P > context ) {
24
33
return patchAndCacheStatusWithLock (
25
34
primary , context , (p , c ) -> c .resource (primary ).updateStatus ());
26
35
}
27
36
37
+ /**
38
+ * Makes sure that the up-to-date primary resource will be present during the next reconciliation.
39
+ * Using JSON Merge patch.
40
+ *
41
+ * @param primary resource
42
+ * @param context of reconciliation
43
+ * @return updated resource
44
+ * @param <P> primary resource type
45
+ */
28
46
public static <P extends HasMetadata > P patchAndCacheStatusWithLock (
29
47
P primary , Context <P > context ) {
30
48
return patchAndCacheStatusWithLock (
31
49
primary , context , (p , c ) -> c .resource (primary ).patchStatus ());
32
50
}
33
51
52
+ /**
53
+ * Makes sure that the up-to-date primary resource will be present during the next reconciliation.
54
+ * Using JSON Patch.
55
+ *
56
+ * @param primary resource
57
+ * @param context of reconciliation
58
+ * @return updated resource
59
+ * @param <P> primary resource type
60
+ */
34
61
public static <P extends HasMetadata > P editAndCacheStatusWithLock (
35
62
P primary , Context <P > context , UnaryOperator <P > operation ) {
36
63
return patchAndCacheStatusWithLock (
37
64
primary , context , (p , c ) -> c .resource (primary ).editStatus (operation ));
38
65
}
39
66
67
+ /**
68
+ * Makes sure that the up-to-date primary resource will be present during the next reconciliation.
69
+ *
70
+ * @param primary resource
71
+ * @param context of reconciliation
72
+ * @param patch free implementation of cache - make sure you use optimistic locking during the
73
+ * update
74
+ * @return the updated resource.
75
+ * @param <P> primary resource type
76
+ */
40
77
public static <P extends HasMetadata > P patchAndCacheStatusWithLock (
41
78
P primary , Context <P > context , BiFunction <P , KubernetesClient , P > patch ) {
42
79
checkResourceVersionPresent (primary );
@@ -48,6 +85,16 @@ public static <P extends HasMetadata> P patchAndCacheStatusWithLock(
48
85
return null ;
49
86
}
50
87
88
+ /**
89
+ * Makes sure that the up-to-date primary resource will be present during the next reconciliation.
90
+ * Using Server Side Apply.
91
+ *
92
+ * @param primary resource
93
+ * @param freshResourceWithStatus - fresh resource with target state
94
+ * @param context of reconciliation
95
+ * @return the updated resource.
96
+ * @param <P> primary resource type
97
+ */
51
98
public static <P extends HasMetadata > P ssaPatchAndCacheStatusWithLock (
52
99
P primary , P freshResourceWithStatus , Context <P > context ) {
53
100
checkResourceVersionPresent (freshResourceWithStatus );
@@ -70,15 +117,26 @@ public static <P extends HasMetadata> P ssaPatchAndCacheStatusWithLock(
70
117
return res ;
71
118
}
72
119
120
+ /**
121
+ * Patches the resource and adds it to the {@link PrimaryResourceCache} provided. Optimistic
122
+ * locking is not required.
123
+ *
124
+ * @param primary resource
125
+ * @param freshResourceWithStatus - fresh resource with target state
126
+ * @param context of reconciliation
127
+ * @param cache - resource cache managed by user
128
+ * @return the updated resource.
129
+ * @param <P> primary resource type
130
+ */
73
131
public static <P extends HasMetadata > P ssaPatchAndCacheStatus (
74
- P primary , P freshResource , Context <P > context , PrimaryResourceCache <P > cache ) {
75
- logWarnIfResourceVersionPresent (freshResource );
132
+ P primary , P freshResourceWithStatus , Context <P > context , PrimaryResourceCache <P > cache ) {
133
+ logWarnIfResourceVersionPresent (freshResourceWithStatus );
76
134
return patchAndCacheStatus (
77
135
primary ,
78
136
context .getClient (),
79
137
cache ,
80
138
(P p , KubernetesClient c ) ->
81
- c .resource (freshResource )
139
+ c .resource (freshResourceWithStatus )
82
140
.subresource ("status" )
83
141
.patch (
84
142
new PatchContext .Builder ()
@@ -88,6 +146,66 @@ public static <P extends HasMetadata> P ssaPatchAndCacheStatus(
88
146
.build ()));
89
147
}
90
148
149
+ /**
150
+ * Patches the resource with JSON Patch and adds it to the {@link PrimaryResourceCache} provided.
151
+ * Optimistic locking is not required.
152
+ *
153
+ * @param primary resource*
154
+ * @param context of reconciliation
155
+ * @param cache - resource cache managed by user
156
+ * @return the updated resource.
157
+ * @param <P> primary resource type
158
+ */
159
+ public static <P extends HasMetadata > P edithAndCacheStatus (
160
+ P primary , Context <P > context , PrimaryResourceCache <P > cache , UnaryOperator <P > operation ) {
161
+ logWarnIfResourceVersionPresent (primary );
162
+ return patchAndCacheStatus (
163
+ primary ,
164
+ context .getClient (),
165
+ cache ,
166
+ (P p , KubernetesClient c ) -> c .resource (primary ).editStatus (operation ));
167
+ }
168
+
169
+ /**
170
+ * Patches the resource with JSON Merge patch and adds it to the {@link PrimaryResourceCache}
171
+ * provided. Optimistic locking is not required.
172
+ *
173
+ * @param primary resource*
174
+ * @param context of reconciliation
175
+ * @param cache - resource cache managed by user
176
+ * @return the updated resource.
177
+ * @param <P> primary resource type
178
+ */
179
+ public static <P extends HasMetadata > P patchAndCacheStatus (
180
+ P primary , Context <P > context , PrimaryResourceCache <P > cache ) {
181
+ logWarnIfResourceVersionPresent (primary );
182
+ return patchAndCacheStatus (
183
+ primary ,
184
+ context .getClient (),
185
+ cache ,
186
+ (P p , KubernetesClient c ) -> c .resource (primary ).patchStatus ());
187
+ }
188
+
189
+ /**
190
+ * Updates the resource and adds it to the {@link PrimaryResourceCache} provided. Optimistic
191
+ * locking is not required.
192
+ *
193
+ * @param primary resource*
194
+ * @param context of reconciliation
195
+ * @param cache - resource cache managed by user
196
+ * @return the updated resource.
197
+ * @param <P> primary resource type
198
+ */
199
+ public static <P extends HasMetadata > P updateAndCacheStatus (
200
+ P primary , Context <P > context , PrimaryResourceCache <P > cache ) {
201
+ logWarnIfResourceVersionPresent (primary );
202
+ return patchAndCacheStatus (
203
+ primary ,
204
+ context .getClient (),
205
+ cache ,
206
+ (P p , KubernetesClient c ) -> c .resource (primary ).updateStatus ());
207
+ }
208
+
91
209
public static <P extends HasMetadata > P patchAndCacheStatus (
92
210
P primary ,
93
211
KubernetesClient client ,
0 commit comments