99
1010import io .kubernetes .client .custom .IntOrString ;
1111import 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 ;
1330import 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 ;
1648import oracle .kubernetes .operator .calls .CallResponse ;
1749import oracle .kubernetes .operator .logging .LoggingFacade ;
1850import oracle .kubernetes .operator .logging .LoggingFactory ;
@@ -145,7 +177,7 @@ protected boolean isDomainHomeInImage() {
145177 return getDomain ().isDomainHomeInImage ();
146178 }
147179
148- String getEffectiveLogHome () {
180+ private String getEffectiveLogHome () {
149181 if (!getDomain ().getLogHomeEnabled ()) return null ;
150182 String logHome = getLogHome ();
151183 if (logHome == null || "" .equals (logHome .trim ())) {
@@ -274,6 +306,21 @@ private Step replacePod(Step next) {
274306 return new CallBuilder ().createPodAsync (getNamespace (), getPodModel (), replaceResponse (next ));
275307 }
276308
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+
277324 private void logPodCreated () {
278325 LOGGER .info (getPodCreatedMessageKey (), getDomainUID (), getServerName ());
279326 }
@@ -282,6 +329,10 @@ private void logPodExists() {
282329 LOGGER .fine (getPodExistsMessageKey (), getDomainUID (), getServerName ());
283330 }
284331
332+ private void logPodPatched () {
333+ LOGGER .info (getPodPatchedMessageKey (), getDomainUID (), getServerName ());
334+ }
335+
285336 private void logPodReplaced () {
286337 LOGGER .info (getPodReplacedMessageKey (), getDomainUID (), getServerName ());
287338 }
@@ -290,6 +341,8 @@ private void logPodReplaced() {
290341
291342 abstract String getPodExistsMessageKey ();
292343
344+ abstract String getPodPatchedMessageKey ();
345+
293346 abstract String getPodReplacedMessageKey ();
294347
295348 Step createCyclePodStep (Step next ) {
@@ -309,6 +362,12 @@ public NextAction apply(Packet packet) {
309362 }
310363 }
311364
365+ private boolean mustPatchPod (V1Pod currentPod ) {
366+ return KubernetesUtils .isMissingValues (currentPod .getMetadata ().getLabels (), getPodLabels ())
367+ || KubernetesUtils .isMissingValues (
368+ currentPod .getMetadata ().getAnnotations (), getPodAnnotations ());
369+ }
370+
312371 private boolean canUseCurrentPod (V1Pod currentPod ) {
313372 return isCurrentPodValid (getPodModel (), currentPod );
314373 }
@@ -326,9 +385,7 @@ private static boolean isCurrentPodValid(V1Pod build, V1Pod current) {
326385
327386 private static boolean isCurrentPodMetadataValid (V1ObjectMeta build , V1ObjectMeta current ) {
328387 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 );
332389 }
333390
334391 private static boolean isCurrentPodSpecValid (
@@ -472,12 +529,14 @@ public NextAction apply(Packet packet) {
472529 V1Pod currentPod = getSko ().getPod ().get ();
473530 if (currentPod == null ) {
474531 return doNext (createNewPod (getNext ()), packet );
475- } else if (canUseCurrentPod (currentPod )) {
476- logPodExists ();
477- return doNext (packet );
478- } else {
532+ } else if (!canUseCurrentPod (currentPod )) {
479533 LOGGER .info (MessageKeys .CYCLING_POD , currentPod , getPodModel ());
480534 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 );
481540 }
482541 }
483542 }
@@ -560,6 +619,37 @@ public NextAction onSuccess(Packet packet, CallResponse<V1Pod> callResponse) {
560619 }
561620 }
562621
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+
563653 Step verifyPersistentVolume (Step next ) {
564654 return new VerifyPersistentVolumeStep (next );
565655 }
0 commit comments