Skip to content

Commit 90ca899

Browse files
committed
Correctly record time of annotation and adjust status earlier to prevent additional introspections
1 parent c3368bc commit 90ca899

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

operator/src/main/java/oracle/kubernetes/operator/DomainStatusUpdater.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,22 @@ private boolean wasNotRolling() {
198198

199199
}
200200

201+
public static Step createIncompleteBeforeIntrospectionStep() {
202+
return new IncompleteBeforeIntrospectionStep();
203+
}
204+
205+
public static class IncompleteBeforeIntrospectionStep extends DomainStatusUpdaterStep {
206+
207+
private IncompleteBeforeIntrospectionStep() {
208+
}
209+
210+
@Override
211+
void modifyStatus(DomainStatus status) {
212+
status.addCondition(new DomainCondition(COMPLETED).withStatus(false));
213+
}
214+
215+
}
216+
201217
/**
202218
* Creates an asynchronous step to initialize the domain status, if needed, to indicate that the operator has
203219
* seen the domain and is now working on it.

operator/src/main/java/oracle/kubernetes/operator/MakeRightDomainOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 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

44
package oracle.kubernetes.operator;
@@ -82,7 +82,7 @@ private static boolean wasInspectionRun(Packet packet) {
8282
String time = packet.getValue(INTROSPECTION_TIME);
8383
if (time != null) {
8484
OffsetDateTime lastIntrospectionTime = OffsetDateTime.parse(time);
85-
if (lastIntrospectionTime.isAfter(lastTransitionTime)) {
85+
if (lastIntrospectionTime.isAfter(lastTransitionTime.minusSeconds(3))) {
8686
return true;
8787
}
8888
}

operator/src/main/java/oracle/kubernetes/operator/helpers/ConfigMapHelper.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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

44
package 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> {

operator/src/main/java/oracle/kubernetes/operator/helpers/JobHelper.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.kubernetes.client.util.generic.options.DeleteOptions;
3636
import io.kubernetes.client.util.generic.options.ListOptions;
3737
import oracle.kubernetes.common.logging.MessageKeys;
38+
import oracle.kubernetes.operator.DomainStatusUpdater;
3839
import oracle.kubernetes.operator.IntrospectionStatus;
3940
import oracle.kubernetes.operator.IntrospectorConfigMapConstants;
4041
import oracle.kubernetes.operator.LabelConstants;
@@ -423,6 +424,7 @@ private Step cleanUpAndReintrospect(Step next) {
423424
private Step createIntrospectionSteps(Step next) {
424425
return Step.chain(
425426
readExistingIntrospectorConfigMap(),
427+
DomainStatusUpdater.createIncompleteBeforeIntrospectionStep(),
426428
createNewJob(),
427429
processExistingIntrospectorJob(next));
428430
}

0 commit comments

Comments
 (0)