31
31
import java .util .Collections ;
32
32
import java .util .List ;
33
33
import java .util .Map ;
34
- import java .util .Objects ;
35
34
import java .util .Optional ;
36
35
import javax .json .Json ;
37
36
import javax .json .JsonPatchBuilder ;
@@ -92,7 +91,7 @@ private void createSubstitutionMap() {
92
91
substitutionVariables .put ("ADMIN_PORT" , getAsPort ().toString ());
93
92
}
94
93
95
- private V1Pod getPodModel () {
94
+ V1Pod getPodModel () {
96
95
return podModel ;
97
96
}
98
97
@@ -168,10 +167,6 @@ private String getLogHome() {
168
167
return getDomain ().getLogHome ();
169
168
}
170
169
171
- protected boolean isDomainHomeInImage () {
172
- return getDomain ().isDomainHomeInImage ();
173
- }
174
-
175
170
private String getEffectiveLogHome () {
176
171
if (!getDomain ().getLogHomeEnabled ()) return null ;
177
172
String logHome = getLogHome ();
@@ -280,7 +275,15 @@ private Step deletePod(Step next) {
280
275
* @return a step to be scheduled.
281
276
*/
282
277
Step createPod (Step next ) {
283
- return new CallBuilder ().createPodAsync (getNamespace (), getPodModel (), createResponse (next ));
278
+ return createPodAsync (createResponse (next ));
279
+ }
280
+
281
+ private Step createPodAsync (ResponseStep <V1Pod > response ) {
282
+ return new CallBuilder ().createPodAsync (getNamespace (), getPodModelWithChecksum (), response );
283
+ }
284
+
285
+ private V1Pod getPodModelWithChecksum () {
286
+ return AnnotationHelper .withSha256Hash (getPodModel ());
284
287
}
285
288
286
289
/**
@@ -298,7 +301,7 @@ Step createPod(Step next) {
298
301
* @return a step to be scheduled.
299
302
*/
300
303
private Step replacePod (Step next ) {
301
- return new CallBuilder (). createPodAsync (getNamespace (), getPodModel (), replaceResponse (next ));
304
+ return createPodAsync (replaceResponse (next ));
302
305
}
303
306
304
307
private Step patchCurrentPod (V1Pod currentPod , Step next ) {
@@ -364,47 +367,15 @@ private boolean mustPatchPod(V1Pod currentPod) {
364
367
}
365
368
366
369
private boolean canUseCurrentPod (V1Pod currentPod ) {
367
- List <String > ignoring = getVolumesToIgnore (currentPod );
368
-
369
- PodCompatibility compatibility = new PodCompatibility (getPodModel (), currentPod , ignoring );
370
- return compatibility .isCompatible ();
370
+ return AnnotationHelper .getHash (getPodModel ()).equals (AnnotationHelper .getHash (currentPod ));
371
371
}
372
372
373
373
private String getReasonToRecycle (V1Pod currentPod ) {
374
- List <String > ignoring = getVolumesToIgnore (currentPod );
375
374
376
- PodCompatibility compatibility = new PodCompatibility (getPodModel (), currentPod , ignoring );
375
+ PodCompatibility compatibility = new PodCompatibility (getPodModel (), currentPod );
377
376
return compatibility .getIncompatibility ();
378
377
}
379
378
380
- private static List <String > getVolumesToIgnore (V1Pod current ) {
381
- List <String > k8sVolumeNames = new ArrayList <>();
382
- for (V1Container container : getContainers (current ))
383
- for (V1VolumeMount mount : getVolumeMounts (container ))
384
- if (PodDefaults .K8S_SERVICE_ACCOUNT_MOUNT_PATH .equals (mount .getMountPath ()))
385
- k8sVolumeNames .add (mount .getName ());
386
-
387
- return k8sVolumeNames ;
388
- }
389
-
390
- private static List <V1Container > getContainers (V1Pod current ) {
391
- return Optional .ofNullable (current .getSpec ().getContainers ()).orElse (Collections .emptyList ());
392
- }
393
-
394
- private static List <V1VolumeMount > getVolumeMounts (V1Container container ) {
395
- return Optional .ofNullable (container .getVolumeMounts ()).orElse (Collections .emptyList ());
396
- }
397
-
398
- private static boolean isRestartVersionValid (V1ObjectMeta build , V1ObjectMeta current ) {
399
- return isLabelSame (build , current , LabelConstants .DOMAINRESTARTVERSION_LABEL )
400
- && isLabelSame (build , current , LabelConstants .CLUSTERRESTARTVERSION_LABEL )
401
- && isLabelSame (build , current , LabelConstants .SERVERRESTARTVERSION_LABEL );
402
- }
403
-
404
- private static boolean isLabelSame (V1ObjectMeta build , V1ObjectMeta current , String labelName ) {
405
- return Objects .equals (build .getLabels ().get (labelName ), current .getLabels ().get (labelName ));
406
- }
407
-
408
379
private class VerifyPodStep extends Step {
409
380
410
381
VerifyPodStep (Step next ) {
@@ -602,16 +573,36 @@ public NextAction onSuccess(
602
573
// ---------------------- model methods ------------------------------
603
574
604
575
private V1Pod createPodModel () {
576
+ return withPatchableElements (AnnotationHelper .withSha256Hash (createPodRecipe ()));
577
+ }
578
+
579
+ // Adds labels and annotations to a pod, skipping any whose names begin with "weblogic."
580
+ private V1Pod withPatchableElements (V1Pod pod ) {
581
+ V1ObjectMeta metadata = pod .getMetadata ();
582
+ getPodLabels ()
583
+ .entrySet ()
584
+ .stream ()
585
+ .filter (PodStepContext ::isCustomerItem )
586
+ .forEach (e -> metadata .putLabelsItem (e .getKey (), e .getValue ()));
587
+ getPodAnnotations ()
588
+ .entrySet ()
589
+ .stream ()
590
+ .filter (PodStepContext ::isCustomerItem )
591
+ .forEach (e -> metadata .putAnnotationsItem (e .getKey (), e .getValue ()));
592
+ return pod ;
593
+ }
594
+
595
+ private static boolean isCustomerItem (Map .Entry <String , String > entry ) {
596
+ return !entry .getKey ().startsWith ("weblogic." );
597
+ }
598
+
599
+ // Creates a pod model containing elements which are not patchable.
600
+ private V1Pod createPodRecipe () {
605
601
return new V1Pod ().metadata (createMetadata ()).spec (createSpec (TuningParameters .getInstance ()));
606
602
}
607
603
608
604
protected V1ObjectMeta createMetadata () {
609
605
V1ObjectMeta metadata = new V1ObjectMeta ().name (getPodName ()).namespace (getNamespace ());
610
- // Add custom labels
611
- getPodLabels ().forEach (metadata ::putLabelsItem );
612
-
613
- // Add internal labels. This will overwrite any custom labels that conflict with internal
614
- // labels.
615
606
metadata
616
607
.putLabelsItem (LabelConstants .RESOURCE_VERSION_LABEL , DEFAULT_DOMAIN_VERSION )
617
608
.putLabelsItem (LabelConstants .DOMAINUID_LABEL , getDomainUID ())
@@ -625,9 +616,6 @@ LabelConstants.CLUSTERRESTARTVERSION_LABEL, getServerSpec().getClusterRestartVer
625
616
.putLabelsItem (
626
617
LabelConstants .SERVERRESTARTVERSION_LABEL , getServerSpec ().getServerRestartVersion ());
627
618
628
- // Add custom annotations
629
- getPodAnnotations ().forEach (metadata ::putAnnotationsItem );
630
-
631
619
// Add prometheus annotations. This will overwrite any custom annotations with same name.
632
620
AnnotationHelper .annotateForPrometheus (metadata , getDefaultPort ());
633
621
return metadata ;
0 commit comments