Skip to content

Commit 933eb9b

Browse files
authored
OWLS-106777 - Fix for string index out of bounds exception in PodStepContext. (#3989)
1 parent be450df commit 933eb9b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ private String createContainerPortName(List<V1ContainerPort> ports, String name)
368368
@Nonnull
369369
private String getPortNamePrefix(String name) {
370370
// Use first 12 characters of port name as prefix due to 15 character port name limit
371-
return name.substring(0, 12);
371+
return name.length() > 12 ? name.substring(0, 12) : name;
372372
}
373373

374374
Integer getListenPort() {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,17 @@ void whenPodCreatedWithMultipleNapsWithNamesExceedingMaxPortNameLength_podContai
475475
createContainerPort(TRUNCATED_PORT_NAME_PREFIX + "-02")));
476476
}
477477

478+
@Test
479+
void whenOneNapNameExceedsMaxPortNameLengthAndOtherNapWithShortName_podContainerCreatedWithCorrectPortNames() {
480+
getServerTopology().addNetworkAccessPoint(new NetworkAccessPoint("shortname", "admin", 8001, 8001));
481+
getServerTopology().addNetworkAccessPoint(new NetworkAccessPoint(LONG_CHANNEL_NAME + "1", "admin", 8001, 8001));
482+
483+
assertThat(
484+
getContainerPorts(),
485+
hasItems(createContainerPort(TRUNCATED_PORT_NAME_PREFIX + "-01"),
486+
createContainerPort("shortname")));
487+
}
488+
478489
@Test
479490
void whenPodCreatedWithMultipleNapsSomeWithNamesExceedingMaxPortNameLength_podContainerCreatedWithMixedPortNames() {
480491
getServerTopology().addNetworkAccessPoint(new NetworkAccessPoint(LONG_CHANNEL_NAME, "admin", 8001, 8001));

0 commit comments

Comments
 (0)