Skip to content

Commit acadba5

Browse files
committed
Limit event note to 1024 characters
1 parent 4f5fb2a commit acadba5

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public class EventHelper {
108108

109109
private static final Random random = new Random();
110110

111+
private static final int MAX_NOTE_LENGTH = 1024;
112+
111113
/**
112114
* Factory for {@link Step} that asynchronously create an event.
113115
*
@@ -196,7 +198,7 @@ private static EventsV1Event createEventModel(
196198
.type(eventItem.getType())
197199
.action(eventItem.getReason()) // use reason for action and reason
198200
.reason(eventItem.getReason())
199-
.note(eventItem.getNote(eventData))
201+
.note(limitLength(eventItem.getNote(eventData), MAX_NOTE_LENGTH))
200202
.regarding(eventItem.createRegarding(eventData));
201203
}
202204

@@ -1123,7 +1125,7 @@ private static EventsV1Event createConversionWebhookEventModel(EventItem eventIt
11231125
.type(eventItem.getType())
11241126
.action(eventItem.getReason()) // use reason for action and reason
11251127
.reason(eventItem.getReason())
1126-
.note(eventItem.getNote(eventData))
1128+
.note(limitLength(eventItem.getNote(eventData), MAX_NOTE_LENGTH))
11271129
.regarding(eventItem.createRegarding(eventData))
11281130
.metadata(CreateEventStep.createMetadata(eventData));
11291131
}
@@ -1184,7 +1186,7 @@ private static EventsV1Event createEventModel(EventData eventData) {
11841186
.type(eventItem.getType())
11851187
.action(eventItem.getReason()) // use reason for action and reason
11861188
.reason(eventItem.getReason())
1187-
.note(eventItem.getNote(eventData))
1189+
.note(limitLength(eventItem.getNote(eventData), MAX_NOTE_LENGTH))
11881190
.regarding(eventItem.createRegarding(eventData));
11891191
}
11901192

@@ -1336,4 +1338,11 @@ public String getResourceNameFromInfo() {
13361338
return Optional.ofNullable(domainUid).orElse("");
13371339
}
13381340
}
1341+
1342+
private static String limitLength(String input, int maxLength) {
1343+
if (input == null) {
1344+
return null;
1345+
}
1346+
return input.length() > maxLength ? input.substring(0, maxLength) : input;
1347+
}
13391348
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,6 @@ private void assertTopologyMismatchReported(String messageKey, Object... paramet
484484

485485
assertThat(domain, hasCondition(FAILED).withReason(TOPOLOGY_MISMATCH).withMessageContaining(message));
486486
assertThat(logRecords, containsWarning(messageKey).withParams(parameters));
487-
assertThat(testSupport,
488-
hasEvent(DOMAIN_FAILED_EVENT)
489-
.withNoteContaining(getLocalizedString(TOPOLOGY_MISMATCH_EVENT_ERROR), message));
490487
}
491488

492489
private void assertMaxReplicasSet() {

0 commit comments

Comments
 (0)