Skip to content

Commit 4dd26fe

Browse files
authored
backport pod name fix from main to release/3.4 (#3169)
* backport pod name fix from main to release/3.4
1 parent d9076a0 commit 4dd26fe

File tree

1 file changed

+15
-12
lines changed
  • integration-tests/src/test/java/oracle/weblogic/kubernetes/utils

1 file changed

+15
-12
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/DbUtils.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public static synchronized void setupDBandRCUschema(String dbImage, String fmwIm
125125
public static synchronized void startOracleDB(String dbBaseImageName, int dbPort, String dbNamespace,
126126
int dbListenerPort) throws ApiException {
127127
LoggingFacade logger = getLogger();
128+
String dbPodNamePrefix = "oracledb";
128129

129130
if (OKD) {
130131
addSccToDBSvcAccount("default", dbNamespace);
@@ -200,7 +201,7 @@ public static synchronized void startOracleDB(String dbBaseImageName, int dbPort
200201
.addEnvItem(new V1EnvVar().name("DB_BUNDLE").value("basic"))
201202
.image(dbBaseImageName)
202203
.imagePullPolicy("IfNotPresent")
203-
.name("oracledb")
204+
.name(dbPodNamePrefix)
204205
.ports(Arrays.asList(
205206
new V1ContainerPort()
206207
.containerPort(dbListenerPort)
@@ -237,7 +238,7 @@ public static synchronized void startOracleDB(String dbBaseImageName, int dbPort
237238
}
238239

239240
// wait for the Oracle DB pod to be ready
240-
String dbPodName = assertDoesNotThrow(() -> getPodNameOfDb(dbNamespace),
241+
String dbPodName = assertDoesNotThrow(() -> getPodNameOfDb(dbNamespace, dbPodNamePrefix),
241242
String.format("Get Oracle DB pod name failed with ApiException for oracleDBService in namespace %s",
242243
dbNamespace));
243244
logger.info("Wait for the oracle Db pod: {0} ready in namespace {1}", dbPodName, dbNamespace);
@@ -434,22 +435,24 @@ private static boolean createRcuRepository(String dbNamespace, String dbUrl,
434435

435436
/**
436437
* Get database pod name.
438+
*
437439
* @param dbNamespace namespace where database exists
440+
* @param podPrefix prefix of database pod
438441
* @return pod name of database
439442
* @throws ApiException if Kubernetes client API call fails
440443
*/
441-
public static String getPodNameOfDb(String dbNamespace) throws ApiException {
442-
443-
V1PodList pod = null;
444-
pod = Kubernetes.listPods(dbNamespace, null);
445-
444+
public static String getPodNameOfDb(String dbNamespace, String podPrefix) throws ApiException {
446445
String podName = null;
447-
448-
//There is only one pod in the given DB namespace
449-
if (pod != null) {
450-
podName = pod.getItems().get(0).getMetadata().getName();
446+
V1PodList pods = null;
447+
pods = Kubernetes.listPods(dbNamespace, null);
448+
if (!pods.getItems().isEmpty()) {
449+
for (V1Pod pod : pods.getItems()) {
450+
if (pod != null && pod.getMetadata().getName().startsWith(podPrefix)) {
451+
podName = pod.getMetadata().getName();
452+
break;
453+
}
454+
}
451455
}
452-
453456
return podName;
454457
}
455458

0 commit comments

Comments
 (0)