Skip to content

Commit 46078ce

Browse files
authored
Add a log message when replace NamespaceWatchingStopped event hits 403 (#2323)
* log a message when replace NS_WATCHING_STOPPED event hits 403 too
1 parent f3c018b commit 46078ce

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,7 @@ public NextAction onSuccess(Packet packet, CallResponse<CoreV1Event> callRespons
195195

196196
@Override
197197
public NextAction onFailure(Packet packet, CallResponse<CoreV1Event> callResponse) {
198-
if (isForbiddenForNamespaceWatchingStoppedEvent(callResponse)) {
199-
LOGGER.info(MessageKeys.CREATING_EVENT_FORBIDDEN,
200-
eventData.eventItem.getReason(), eventData.getNamespace());
198+
if (hasLoggedForbiddenNSWatchStoppedEvent(this, callResponse)) {
201199
return doNext(packet);
202200
}
203201

@@ -250,6 +248,9 @@ public NextAction onSuccess(Packet packet, CallResponse<CoreV1Event> callRespons
250248
@Override
251249
public NextAction onFailure(Packet packet, CallResponse<CoreV1Event> callResponse) {
252250
restoreExistingEvent();
251+
if (hasLoggedForbiddenNSWatchStoppedEvent(this, callResponse)) {
252+
return doNext(packet);
253+
}
253254
if (UnrecoverableErrorBuilder.isAsyncCallNotFoundFailure(callResponse)) {
254255
return doNext(Step.chain(createCreateEventCall(createEventModel(packet, eventData)), getNext()), packet);
255256
} else if (UnrecoverableErrorBuilder.isAsyncCallUnrecoverableFailure(callResponse)) {
@@ -278,6 +279,20 @@ private Step createEventRefreshStep(CoreV1Event event) {
278279
}
279280
}
280281

282+
private boolean isForbiddenForNSWatchStoppedEvent(
283+
ResponseStep responseStep, CallResponse<CoreV1Event> callResponse) {
284+
return responseStep.isForbidden(callResponse) && NAMESPACE_WATCHING_STOPPED == eventData.eventItem;
285+
}
286+
287+
private boolean hasLoggedForbiddenNSWatchStoppedEvent(
288+
ResponseStep responseStep, CallResponse<CoreV1Event> callResponse) {
289+
if (isForbiddenForNSWatchStoppedEvent(responseStep, callResponse)) {
290+
LOGGER.info(MessageKeys.CREATING_EVENT_FORBIDDEN, eventData.eventItem.getReason(), eventData.getNamespace());
291+
return true;
292+
}
293+
return false;
294+
}
295+
281296
private static class ReadEventResponseStep extends ResponseStep<CoreV1Event> {
282297
ReadEventResponseStep(Step next) {
283298
super(next);

operator/src/main/resources/Operator.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ WLSKO-0178=Operator cannot proceed, as the Custom Resource Definition for ''doma
131131
WLSKO-0179=Pod {0} in namespace {1} detected as stuck, and force-deleted
132132
WLSKO-0180=Creating event: {0}
133133
WLSKO-0181=Replacing event: {0}
134-
WLSKO-0182=Cannot create {0} event in namespace {1} due to an authorization error
134+
WLSKO-0182=Cannot create or replace {0} event in namespace {1} due to an authorization error
135135
WLSKO-0183=Creating Pod Disruption Budget for WebLogic domain with UID: {0}. Cluster name: {1}.
136136
WLSKO-0184=Existing Pod Disruption Budget is correct for WebLogic domain with UID: {0}. Cluster name: {1}.
137137
WLSKO-0185=Patching Pod Disruption Budget for WebLogic domain with UID: {0}. Cluster name: {1}.

operator/src/test/java/oracle/kubernetes/operator/helpers/EventHelperTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,34 @@ public void whenNSWatchStoppedEventCreated_fail403OnCreate_foundExpectedLogMessa
667667
assertThat(logRecords, containsInfo(CREATING_EVENT_FORBIDDEN, NAMESPACE_WATCHING_STOPPED_EVENT, NS));
668668
}
669669

670+
@Test
671+
public void whenNSWatchStoppedEventCreatedTwice_fail403OnReplace_eventCreatedOnce() {
672+
testSupport.runSteps(Step.chain(createEventStep(new EventData(NAMESPACE_WATCHING_STOPPED))));
673+
674+
CoreV1Event event = EventTestUtils.getEventWithReason(getEvents(testSupport), NAMESPACE_WATCHING_STOPPED_EVENT);
675+
dispatchAddedEventWatches();
676+
testSupport.failOnReplace(EVENT, EventTestUtils.getName(event), NS, HTTP_FORBIDDEN);
677+
678+
testSupport.runSteps(Step.chain(createEventStep(new EventData(NAMESPACE_WATCHING_STOPPED))));
679+
680+
assertThat("Found 1 NAMESPACE_WATCHING_STOPPED event with expected count 1",
681+
containsOneEventWithCount(getEvents(testSupport), NAMESPACE_WATCHING_STOPPED_EVENT, 1), is(true));
682+
}
683+
684+
@Test
685+
public void whenNSWatchStoppedEventCreatedTwice_fail403OnReplace_foundExpectedLogMessage() {
686+
loggerControl.withLogLevel(Level.INFO).collectLogMessages(logRecords, CREATING_EVENT_FORBIDDEN);
687+
testSupport.runSteps(Step.chain(createEventStep(new EventData(NAMESPACE_WATCHING_STOPPED))));
688+
689+
CoreV1Event event = EventTestUtils.getEventWithReason(getEvents(testSupport), NAMESPACE_WATCHING_STOPPED_EVENT);
690+
dispatchAddedEventWatches();
691+
testSupport.failOnReplace(EVENT, EventTestUtils.getName(event), NS, HTTP_FORBIDDEN);
692+
693+
testSupport.runSteps(Step.chain(createEventStep(new EventData(NAMESPACE_WATCHING_STOPPED))));
694+
695+
assertThat(logRecords, containsInfo(CREATING_EVENT_FORBIDDEN, NAMESPACE_WATCHING_STOPPED_EVENT, NS));
696+
}
697+
670698
@Test
671699
public void whenCreateEventStepCalledForNSWatchStartedEvent_eventCreatedWithExpectedMessage() {
672700
testSupport.runSteps(createEventStep(new EventData(NAMESPACE_WATCHING_STARTED).namespace(NS).resourceName(NS)));

0 commit comments

Comments
 (0)