9
9
10
10
import io .kubernetes .client .custom .IntOrString ;
11
11
import io .kubernetes .client .custom .Quantity ;
12
- import io .kubernetes .client .models .*;
12
+ import io .kubernetes .client .models .V1Container ;
13
+ import io .kubernetes .client .models .V1ContainerPort ;
14
+ import io .kubernetes .client .models .V1DeleteOptions ;
15
+ import io .kubernetes .client .models .V1EnvVar ;
16
+ import io .kubernetes .client .models .V1ExecAction ;
17
+ import io .kubernetes .client .models .V1HTTPGetAction ;
18
+ import io .kubernetes .client .models .V1Handler ;
19
+ import io .kubernetes .client .models .V1Lifecycle ;
20
+ import io .kubernetes .client .models .V1ObjectMeta ;
21
+ import io .kubernetes .client .models .V1PersistentVolume ;
22
+ import io .kubernetes .client .models .V1PersistentVolumeList ;
23
+ import io .kubernetes .client .models .V1Pod ;
24
+ import io .kubernetes .client .models .V1PodSpec ;
25
+ import io .kubernetes .client .models .V1Probe ;
26
+ import io .kubernetes .client .models .V1ResourceRequirements ;
27
+ import io .kubernetes .client .models .V1Status ;
28
+ import io .kubernetes .client .models .V1Volume ;
29
+ import io .kubernetes .client .models .V1VolumeMount ;
13
30
import java .io .File ;
14
- import java .util .*;
15
- import oracle .kubernetes .operator .*;
31
+ import java .util .ArrayList ;
32
+ import java .util .Arrays ;
33
+ import java .util .Collections ;
34
+ import java .util .HashSet ;
35
+ import java .util .Iterator ;
36
+ import java .util .List ;
37
+ import java .util .Map ;
38
+ import java .util .Objects ;
39
+ import java .util .Optional ;
40
+ import java .util .Set ;
41
+ import javax .json .Json ;
42
+ import javax .json .JsonPatchBuilder ;
43
+ import oracle .kubernetes .operator .KubernetesConstants ;
44
+ import oracle .kubernetes .operator .LabelConstants ;
45
+ import oracle .kubernetes .operator .PodAwaiterStepFactory ;
46
+ import oracle .kubernetes .operator .ProcessingConstants ;
47
+ import oracle .kubernetes .operator .TuningParameters ;
16
48
import oracle .kubernetes .operator .calls .CallResponse ;
17
49
import oracle .kubernetes .operator .logging .LoggingFacade ;
18
50
import oracle .kubernetes .operator .logging .LoggingFactory ;
@@ -145,7 +177,7 @@ protected boolean isDomainHomeInImage() {
145
177
return getDomain ().isDomainHomeInImage ();
146
178
}
147
179
148
- String getEffectiveLogHome () {
180
+ private String getEffectiveLogHome () {
149
181
if (!getDomain ().getLogHomeEnabled ()) return null ;
150
182
String logHome = getLogHome ();
151
183
if (logHome == null || "" .equals (logHome .trim ())) {
@@ -274,6 +306,21 @@ private Step replacePod(Step next) {
274
306
return new CallBuilder ().createPodAsync (getNamespace (), getPodModel (), replaceResponse (next ));
275
307
}
276
308
309
+ private Step patchCurrentPod (V1Pod currentPod , Step next ) {
310
+ JsonPatchBuilder patchBuilder = Json .createPatchBuilder ();
311
+
312
+ KubernetesUtils .addPatches (
313
+ patchBuilder , "/metadata/labels/" , currentPod .getMetadata ().getLabels (), getPodLabels ());
314
+ KubernetesUtils .addPatches (
315
+ patchBuilder ,
316
+ "/metadata/annotations/" ,
317
+ currentPod .getMetadata ().getAnnotations (),
318
+ getPodAnnotations ());
319
+
320
+ return new CallBuilder ()
321
+ .patchPodAsync (getPodName (), getNamespace (), patchBuilder .build (), patchResponse (next ));
322
+ }
323
+
277
324
private void logPodCreated () {
278
325
LOGGER .info (getPodCreatedMessageKey (), getDomainUID (), getServerName ());
279
326
}
@@ -282,6 +329,10 @@ private void logPodExists() {
282
329
LOGGER .fine (getPodExistsMessageKey (), getDomainUID (), getServerName ());
283
330
}
284
331
332
+ private void logPodPatched () {
333
+ LOGGER .info (getPodPatchedMessageKey (), getDomainUID (), getServerName ());
334
+ }
335
+
285
336
private void logPodReplaced () {
286
337
LOGGER .info (getPodReplacedMessageKey (), getDomainUID (), getServerName ());
287
338
}
@@ -290,6 +341,8 @@ private void logPodReplaced() {
290
341
291
342
abstract String getPodExistsMessageKey ();
292
343
344
+ abstract String getPodPatchedMessageKey ();
345
+
293
346
abstract String getPodReplacedMessageKey ();
294
347
295
348
Step createCyclePodStep (Step next ) {
@@ -309,6 +362,12 @@ public NextAction apply(Packet packet) {
309
362
}
310
363
}
311
364
365
+ private boolean mustPatchPod (V1Pod currentPod ) {
366
+ return KubernetesUtils .isMissingValues (currentPod .getMetadata ().getLabels (), getPodLabels ())
367
+ || KubernetesUtils .isMissingValues (
368
+ currentPod .getMetadata ().getAnnotations (), getPodAnnotations ());
369
+ }
370
+
312
371
private boolean canUseCurrentPod (V1Pod currentPod ) {
313
372
return isCurrentPodValid (getPodModel (), currentPod );
314
373
}
@@ -326,9 +385,7 @@ private static boolean isCurrentPodValid(V1Pod build, V1Pod current) {
326
385
327
386
private static boolean isCurrentPodMetadataValid (V1ObjectMeta build , V1ObjectMeta current ) {
328
387
return VersionHelper .matchesResourceVersion (current , DEFAULT_DOMAIN_VERSION )
329
- && isRestartVersionValid (build , current )
330
- && KubernetesUtils .areLabelsValid (build , current )
331
- && KubernetesUtils .areAnnotationsValid (build , current );
388
+ && isRestartVersionValid (build , current );
332
389
}
333
390
334
391
private static boolean isCurrentPodSpecValid (
@@ -472,12 +529,14 @@ public NextAction apply(Packet packet) {
472
529
V1Pod currentPod = getSko ().getPod ().get ();
473
530
if (currentPod == null ) {
474
531
return doNext (createNewPod (getNext ()), packet );
475
- } else if (canUseCurrentPod (currentPod )) {
476
- logPodExists ();
477
- return doNext (packet );
478
- } else {
532
+ } else if (!canUseCurrentPod (currentPod )) {
479
533
LOGGER .info (MessageKeys .CYCLING_POD , currentPod , getPodModel ());
480
534
return doNext (replaceCurrentPod (getNext ()), packet );
535
+ } else if (mustPatchPod (currentPod )) {
536
+ return doNext (patchCurrentPod (currentPod , getNext ()), packet );
537
+ } else {
538
+ logPodExists ();
539
+ return doNext (packet );
481
540
}
482
541
}
483
542
}
@@ -560,6 +619,37 @@ public NextAction onSuccess(Packet packet, CallResponse<V1Pod> callResponse) {
560
619
}
561
620
}
562
621
622
+ private ResponseStep <V1Pod > patchResponse (Step next ) {
623
+ return new PatchPodResponseStep (next );
624
+ }
625
+
626
+ private class PatchPodResponseStep extends ResponseStep <V1Pod > {
627
+ private final Step next ;
628
+
629
+ PatchPodResponseStep (Step next ) {
630
+ super (next );
631
+ this .next = next ;
632
+ }
633
+
634
+ @ Override
635
+ public NextAction onFailure (Packet packet , CallResponse <V1Pod > callResponse ) {
636
+ return super .onFailure (getConflictStep (), packet , callResponse );
637
+ }
638
+
639
+ @ Override
640
+ public NextAction onSuccess (Packet packet , CallResponse <V1Pod > callResponse ) {
641
+
642
+ V1Pod newPod = callResponse .getResult ();
643
+ logPodPatched ();
644
+ if (newPod != null ) {
645
+ setRecordedPod (newPod );
646
+ }
647
+
648
+ PodAwaiterStepFactory pw = PodHelper .getPodAwaiterStepFactory (packet );
649
+ return doNext (pw .waitForReady (newPod , next ), packet );
650
+ }
651
+ }
652
+
563
653
Step verifyPersistentVolume (Step next ) {
564
654
return new VerifyPersistentVolumeStep (next );
565
655
}
0 commit comments