1- // Copyright (c) 2018, 2024 , Oracle and/or its affiliates.
1+ // Copyright (c) 2018, 2025 , Oracle and/or its affiliates.
22// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33
44package oracle .kubernetes .operator .helpers ;
@@ -353,7 +353,7 @@ public Result onSuccess(Packet packet, KubernetesApiResponse<V1ConfigMap> callRe
353353 } else if (isOutdated (existingMap )) {
354354 return doNext (replaceConfigMap (getNext ()), packet );
355355 } else if (mustPatchCurrentMap (existingMap )) {
356- return doNext (patchCurrentMap (existingMap , getNext ()), packet );
356+ return doNext (patchCurrentMap (existingMap , packet , getNext ()), packet );
357357 } else if (mustPatchImageHashInMap (existingMap , packet )) {
358358 return doNext (patchImageHashInCurrentMap (existingMap , packet , getNext ()), packet );
359359 } else {
@@ -408,12 +408,20 @@ private ResponseStep<V1ConfigMap> createPatchResponseStep(Step next) {
408408 return new PatchResponseStep (next );
409409 }
410410
411- private Step patchCurrentMap (V1ConfigMap currentMap , Step next ) {
411+ private Step patchCurrentMap (V1ConfigMap currentMap , Packet packet , Step next ) {
412412 JsonPatchBuilder patchBuilder = Json .createPatchBuilder ();
413413
414414 if (labelsNotDefined (currentMap )) {
415415 patchBuilder .add ("/metadata/labels" , JsonValue .EMPTY_JSON_OBJECT );
416416 }
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+ }
417425
418426 KubernetesUtils .addPatches (
419427 patchBuilder , "/metadata/labels/" , getMapLabels (currentMap ), getLabels ());
@@ -428,6 +436,14 @@ private Step patchImageHashInCurrentMap(V1ConfigMap currentMap, Packet packet, S
428436
429437 patchBuilder .add ("/data/" + DOMAIN_INPUTS_HASH , (String )packet .get (DOMAIN_INPUTS_HASH ));
430438
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+ 431447 return RequestBuilder .CM .patch (
432448 namespace , name , V1Patch .PATCH_FORMAT_JSON_PATCH ,
433449 new V1Patch (patchBuilder .build ().toString ()), createPatchResponseStep (next ));
@@ -436,6 +452,10 @@ private Step patchImageHashInCurrentMap(V1ConfigMap currentMap, Packet packet, S
436452 private boolean labelsNotDefined (V1ConfigMap currentMap ) {
437453 return Objects .requireNonNull (currentMap .getMetadata ()).getLabels () == null ;
438454 }
455+ 456+ private boolean annotationsNotDefined (V1ConfigMap currentMap ) {
457+ return Objects .requireNonNull (currentMap .getMetadata ()).getAnnotations () == null ;
458+ }
439459 }
440460
441461 private class CreateResponseStep extends ResponseStep <V1ConfigMap > {
0 commit comments