Skip to content

Commit 41d35a7

Browse files
authored
OWLS-106777 - Fix for string index out of bounds exception in PodStepContext (#3988)
* OWLS-106777 - Fix for string index out of bounds exception in PodStepContext.
1 parent 0eb5006 commit 41d35a7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
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
@@ -346,7 +346,7 @@ private String createContainerPortName(List<V1ContainerPort> ports, String name)
346346
@NotNull
347347
private String getPortNamePrefix(String name) {
348348
// Use first 12 characters of port name as prefix due to 15 character port name limit
349-
return name.substring(0, 12);
349+
return name.length() > 12 ? name.substring(0, 12) : name;
350350
}
351351

352352
Integer getListenPort() {

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2023, 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;
@@ -415,6 +415,17 @@ void whenPodCreatedWithMultipleNapsWithNamesExceedingMaxPortNameLength_podContai
415415
createContainerPort(TRUNCATED_PORT_NAME_PREFIX + "-02")));
416416
}
417417

418+
@Test
419+
void whenOneNapNameExceedsMaxPortNameLengthAndOtherNapWithShortName_podContainerCreatedWithCorrectPortNames() {
420+
getServerTopology().addNetworkAccessPoint(new NetworkAccessPoint("shortname", "admin", 8001, 8001));
421+
getServerTopology().addNetworkAccessPoint(new NetworkAccessPoint(LONG_CHANNEL_NAME + "1", "admin", 8001, 8001));
422+
423+
assertThat(
424+
getContainerPorts(),
425+
hasItems(createContainerPort(TRUNCATED_PORT_NAME_PREFIX + "-01"),
426+
createContainerPort("shortname")));
427+
}
428+
418429
@Test
419430
void whenPodCreatedWithMultipleNapsSomeWithNamesExceedingMaxPortNameLength_podContainerCreatedWithMixedPortNames() {
420431
getServerTopology().addNetworkAccessPoint(new NetworkAccessPoint(LONG_CHANNEL_NAME, "admin", 8001, 8001));

0 commit comments

Comments
 (0)