1
- // Copyright (c) 2018, 2024 , Oracle and/or its affiliates.
1
+ // Copyright (c) 2018, 2025 , Oracle and/or its affiliates.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3
3
4
4
package oracle .kubernetes .operator .helpers ;
@@ -353,7 +353,7 @@ public Result onSuccess(Packet packet, KubernetesApiResponse<V1ConfigMap> callRe
353
353
} else if (isOutdated (existingMap )) {
354
354
return doNext (replaceConfigMap (getNext ()), packet );
355
355
} else if (mustPatchCurrentMap (existingMap )) {
356
- return doNext (patchCurrentMap (existingMap , getNext ()), packet );
356
+ return doNext (patchCurrentMap (existingMap , packet , getNext ()), packet );
357
357
} else if (mustPatchImageHashInMap (existingMap , packet )) {
358
358
return doNext (patchImageHashInCurrentMap (existingMap , packet , getNext ()), packet );
359
359
} else {
@@ -408,12 +408,20 @@ private ResponseStep<V1ConfigMap> createPatchResponseStep(Step next) {
408
408
return new PatchResponseStep (next );
409
409
}
410
410
411
- private Step patchCurrentMap (V1ConfigMap currentMap , Step next ) {
411
+ private Step patchCurrentMap (V1ConfigMap currentMap , Packet packet , Step next ) {
412
412
JsonPatchBuilder patchBuilder = Json .createPatchBuilder ();
413
413
414
414
if (labelsNotDefined (currentMap )) {
415
415
patchBuilder .add ("/metadata/labels" , JsonValue .EMPTY_JSON_OBJECT );
416
416
}
417
+
418
+ String introspectionTime = packet .getValue (INTROSPECTION_TIME );
419
+ if (introspectionTime != null ) {
420
+ if (annotationsNotDefined (currentMap )) {
421
+ patchBuilder .add ("/metadata/annotations" , JsonValue .EMPTY_JSON_OBJECT );
422
+ }
423
+ patchBuilder .replace ("/metadata/annotations/" + INTROSPECTION_TIME , introspectionTime );
424
+ }
417
425
418
426
KubernetesUtils .addPatches (
419
427
patchBuilder , "/metadata/labels/" , getMapLabels (currentMap ), getLabels ());
@@ -428,6 +436,14 @@ private Step patchImageHashInCurrentMap(V1ConfigMap currentMap, Packet packet, S
428
436
429
437
patchBuilder .add ("/data/" + DOMAIN_INPUTS_HASH , (String )packet .get (DOMAIN_INPUTS_HASH ));
430
438
439
+ String introspectionTime = packet .getValue (INTROSPECTION_TIME );
440
+ if (introspectionTime != null ) {
441
+ if (annotationsNotDefined (currentMap )) {
442
+ patchBuilder .add ("/metadata/annotations" , JsonValue .EMPTY_JSON_OBJECT );
443
+ }
444
+ patchBuilder .replace ("/metadata/annotations/" + INTROSPECTION_TIME , introspectionTime );
445
+ }
446
+
431
447
return RequestBuilder .CM .patch (
432
448
namespace , name , V1Patch .PATCH_FORMAT_JSON_PATCH ,
433
449
new V1Patch (patchBuilder .build ().toString ()), createPatchResponseStep (next ));
@@ -436,6 +452,10 @@ private Step patchImageHashInCurrentMap(V1ConfigMap currentMap, Packet packet, S
436
452
private boolean labelsNotDefined (V1ConfigMap currentMap ) {
437
453
return Objects .requireNonNull (currentMap .getMetadata ()).getLabels () == null ;
438
454
}
455
+
456
+ private boolean annotationsNotDefined (V1ConfigMap currentMap ) {
457
+ return Objects .requireNonNull (currentMap .getMetadata ()).getAnnotations () == null ;
458
+ }
439
459
}
440
460
441
461
private class CreateResponseStep extends ResponseStep <V1ConfigMap > {
0 commit comments