Skip to content

Commit 5b429fe

Browse files
authored
backport PR3242 plus new fix to address WDT imagePullSecrets issue (#3260)
1 parent 3e382c8 commit 5b429fe

File tree

4 files changed

+149
-162
lines changed

4 files changed

+149
-162
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItLiftAndShiftFromOnPremDomain.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TAG;
4545
import static oracle.weblogic.kubernetes.actions.ActionConstants.ARCHIVE_DIR;
4646
import static oracle.weblogic.kubernetes.actions.ActionConstants.RESOURCE_DIR;
47-
import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_VERSION;
47+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT;
48+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_URL;
4849
import static oracle.weblogic.kubernetes.actions.ActionConstants.WORK_DIR;
4950
import static oracle.weblogic.kubernetes.actions.TestActions.buildAppArchive;
5051
import static oracle.weblogic.kubernetes.actions.TestActions.defaultAppParams;
@@ -53,6 +54,7 @@
5354
import static oracle.weblogic.kubernetes.utils.ApplicationUtils.checkAppIsRunning;
5455
import static oracle.weblogic.kubernetes.utils.BuildApplication.setupWebLogicPod;
5556
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
57+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getActualLocationIfNeeded;
5658
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getHostAndPort;
5759
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
5860
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withQuickRetryPolicy;
@@ -160,15 +162,7 @@ void testCreateMiiDomainWithClusterFromOnPremDomain() {
160162
final String adminServerPodName = domainUid + "-admin-server";
161163
final String managedServerPrefix = domainUid + "-managed-server";
162164
final String clusterService = domainUid + "-cluster-cluster-1";
163-
164-
// As of WDT v2.3.1, the discovery tool will not put the replica count
165-
// in genererated domain resource yaml file. So the Operator will not
166-
// start any managed server (default replica count is zero)
167-
//https://github.com/oracle/weblogic-kubernetes-operator/blob/release/3.4/documentation/domains/Domain.md
168-
// To add custom replica count, need to create a wdt model file with
169-
// kubernates section with custom repilca count
170-
// final int replicaCount = 5;
171-
final int replicaCount = 0;
165+
final int replicaCount = 5;
172166

173167
assertDoesNotThrow(() -> {
174168
logger.info("Deleting and recreating {0}", LIFT_AND_SHIFT_WORK_DIR);
@@ -361,11 +355,14 @@ void testCreateMiiDomainWithClusterFromOnPremDomain() {
361355
}
362356

363357
private static V1Pod callSetupWebLogicPod(String namespace) {
358+
getLogger().info("The input WDT_DOWNLOAD_URL is: {0}", WDT_DOWNLOAD_URL);
359+
String wdtDownloadurl = getActualLocationIfNeeded(WDT_DOWNLOAD_URL, WDT, LIFT_AND_SHIFT_WORK_DIR);
360+
getLogger().info("The actual download location for lifeAndShift is {0}", wdtDownloadurl);
364361
// create a V1Container with specific scripts and properties for creating domain
365362
V1Container container = new V1Container()
366363
.addEnvItem(new V1EnvVar()
367-
.name("WDT_VERSION")
368-
.value(WDT_VERSION))
364+
.name("WDT_INSTALL_ZIP_URL")
365+
.value(wdtDownloadurl))
369366
.addEnvItem(new V1EnvVar()
370367
.name("DOMAIN_SRC")
371368
.value("onpremdomain"))
@@ -418,9 +415,11 @@ private static void updateDomainYamlFile() {
418415
replaceStringInFile(LIFT_AND_SHIFT_WORK_DIR + "/u01/" + DISCOVER_DOMAIN_OUTPUT_DIR + "/" + WKO_DOMAIN_YAML,
419416
"\\{\\{\\{imageName\\}\\}\\}", imageName);
420417
replaceStringInFile(LIFT_AND_SHIFT_WORK_DIR + "/u01/" + DISCOVER_DOMAIN_OUTPUT_DIR + "/" + WKO_DOMAIN_YAML,
421-
"name: ocir", "name: ocir-secret");
418+
"imagePullSecrets: \\[\\]", "imagePullSecrets:\n - name: ocir-secret");
422419
replaceStringInFile(LIFT_AND_SHIFT_WORK_DIR + "/u01/" + DISCOVER_DOMAIN_OUTPUT_DIR + "/" + WKO_DOMAIN_YAML,
423420
"\\{\\{\\{modelHome\\}\\}\\}", "/u01/wdt/models");
421+
replaceStringInFile(LIFT_AND_SHIFT_WORK_DIR + "/u01/" + DISCOVER_DOMAIN_OUTPUT_DIR + "/" + WKO_DOMAIN_YAML,
422+
"# replicas: 99", "replicas: 5");
424423
} catch (IOException ioex) {
425424
logger.info("Exception while replacing user password in the script file");
426425
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Installer.java

Lines changed: 2 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,20 @@
88
import static oracle.weblogic.kubernetes.actions.ActionConstants.DOWNLOAD_DIR;
99
import static oracle.weblogic.kubernetes.actions.ActionConstants.IMAGE_TOOL;
1010
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE;
11-
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_DOWNLOAD_FILENAME_DEFAULT;
1211
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_DOWNLOAD_URL;
13-
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_DOWNLOAD_URL_DEFAULT;
1412
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_FILE;
1513
import static oracle.weblogic.kubernetes.actions.ActionConstants.SNAKE;
16-
import static oracle.weblogic.kubernetes.actions.ActionConstants.SNAKE_DOWNLOADED_FILENAME;
1714
import static oracle.weblogic.kubernetes.actions.ActionConstants.SNAKE_DOWNLOAD_URL;
1815
import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT;
19-
import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_FILENAME_DEFAULT;
2016
import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_URL;
21-
import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_URL_DEFAULT;
2217
import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT;
23-
import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_DOWNLOAD_FILENAME_DEFAULT;
2418
import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_DOWNLOAD_URL;
25-
import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_DOWNLOAD_URL_DEFAULT;
2619
import static oracle.weblogic.kubernetes.actions.ActionConstants.WLE;
27-
import static oracle.weblogic.kubernetes.actions.ActionConstants.WLE_DOWNLOAD_FILENAME_DEFAULT;
2820
import static oracle.weblogic.kubernetes.actions.ActionConstants.WLE_DOWNLOAD_URL;
29-
import static oracle.weblogic.kubernetes.actions.ActionConstants.WLE_DOWNLOAD_URL_DEFAULT;
3021
import static oracle.weblogic.kubernetes.actions.ActionConstants.WORK_DIR;
3122
import static oracle.weblogic.kubernetes.actions.impl.primitive.Command.defaultCommandParams;
23+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getActualLocationIfNeeded;
24+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getInstallerFileName;
3225
import static oracle.weblogic.kubernetes.utils.FileUtils.checkDirectory;
3326
import static oracle.weblogic.kubernetes.utils.FileUtils.doesFileExist;
3427
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
@@ -210,119 +203,4 @@ private String buildDownloadCommand(String downloadDir) {
210203
return command;
211204
}
212205

213-
/**
214-
* Figure out the actual version number of the latest release of WDT or WIT if the version
215-
* parameter is not specified or is specified as "latest". Otherwise return the passed in
216-
* version parameter itself.
217-
*
218-
* @return the version number that is determined
219-
* @throws RuntimeException if the operation failed for any reason
220-
*/
221-
private String getActualLocationIfNeeded(
222-
String location,
223-
String type,
224-
String downloadDir
225-
) throws RuntimeException {
226-
String actualLocation = location;
227-
if (needToGetActualLocation(location, type)) {
228-
String version = "";
229-
String command = String.format(
230-
"curl -fL %s -o %s/%s-%s",
231-
location,
232-
downloadDir,
233-
type,
234-
TMP_FILE_NAME);
235-
236-
CommandParams params =
237-
defaultCommandParams()
238-
.command(command)
239-
.saveResults(true);
240-
if (!Command.withParams(params).execute()) {
241-
RuntimeException exception =
242-
new RuntimeException(String.format("Failed to get the latest %s release information.", type));
243-
getLogger().severe(
244-
String.format(
245-
"Failed to get the latest %s release information. The stderr is %s",
246-
type,
247-
params.stderr()),
248-
exception);
249-
throw exception;
250-
}
251-
252-
command = String.format(
253-
"cat %s/%s-%s | grep 'releases/download' | awk '{ split($0,a,/href=\"/);%s | %s",
254-
downloadDir,
255-
type,
256-
TMP_FILE_NAME,
257-
" print a[2] }'",
258-
" cut -d/ -f 6");
259-
260-
params =
261-
defaultCommandParams()
262-
.command(command)
263-
.saveResults(true)
264-
.redirect(true);
265-
266-
// the command is considered successful only if we have got back a real version number in params.stdout()
267-
if (Command.withParams(params).execute()
268-
&& params.stdout() != null
269-
&& params.stdout().length() != 0) {
270-
// Because I've updated the name of the logging exporter to remove the version number in the name, but
271-
// also preserved the original, there will be two entries located. Take the first.
272-
version = params.stdout().lines().findFirst().get().trim();
273-
} else {
274-
RuntimeException exception =
275-
new RuntimeException(String.format("Failed to get the version number of the requested %s release.", type));
276-
getLogger().severe(
277-
String.format(
278-
"Failed to get the version number of the requested %s release. The stderr is %s",
279-
type,
280-
params.stderr()),
281-
exception);
282-
throw exception;
283-
}
284-
285-
if (version != null) {
286-
actualLocation = location.replace("latest",
287-
String.format("download/%s/%s", version, getInstallerFileName(type)));
288-
}
289-
}
290-
getLogger().info("The actual download location for {0} is {1}", params.type(), actualLocation);
291-
return actualLocation;
292-
}
293-
294-
private boolean needToGetActualLocation(
295-
String location,
296-
String type) {
297-
switch (type) {
298-
case WDT:
299-
return WDT_DOWNLOAD_URL_DEFAULT.equals(location);
300-
case WIT:
301-
return WIT_DOWNLOAD_URL_DEFAULT.equals(location);
302-
case WLE:
303-
return WLE_DOWNLOAD_URL_DEFAULT.equals(location);
304-
case REMOTECONSOLE:
305-
return REMOTECONSOLE_DOWNLOAD_URL_DEFAULT.equals(location);
306-
default:
307-
return false;
308-
}
309-
}
310-
311-
private String getInstallerFileName(
312-
String type) {
313-
switch (type) {
314-
case WDT:
315-
return WDT_DOWNLOAD_FILENAME_DEFAULT;
316-
case WIT:
317-
return WIT_DOWNLOAD_FILENAME_DEFAULT;
318-
case WLE:
319-
return WLE_DOWNLOAD_FILENAME_DEFAULT;
320-
case SNAKE:
321-
return SNAKE_DOWNLOADED_FILENAME;
322-
case REMOTECONSOLE:
323-
return REMOTECONSOLE_DOWNLOAD_FILENAME_DEFAULT;
324-
default:
325-
return "";
326-
}
327-
}
328206
}

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

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,27 @@
4646
import static oracle.weblogic.kubernetes.TestConstants.OKD;
4747
import static oracle.weblogic.kubernetes.TestConstants.RESULTS_ROOT;
4848
import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR;
49+
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE;
50+
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_DOWNLOAD_FILENAME_DEFAULT;
51+
import static oracle.weblogic.kubernetes.actions.ActionConstants.REMOTECONSOLE_DOWNLOAD_URL_DEFAULT;
52+
import static oracle.weblogic.kubernetes.actions.ActionConstants.SNAKE;
53+
import static oracle.weblogic.kubernetes.actions.ActionConstants.SNAKE_DOWNLOADED_FILENAME;
54+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT;
55+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_FILENAME_DEFAULT;
56+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WDT_DOWNLOAD_URL_DEFAULT;
57+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT;
58+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_DOWNLOAD_FILENAME_DEFAULT;
59+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WIT_DOWNLOAD_URL_DEFAULT;
60+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WLE;
61+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WLE_DOWNLOAD_FILENAME_DEFAULT;
62+
import static oracle.weblogic.kubernetes.actions.ActionConstants.WLE_DOWNLOAD_URL_DEFAULT;
4963
import static oracle.weblogic.kubernetes.actions.TestActions.getPodCreationTimestamp;
5064
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
5165
import static oracle.weblogic.kubernetes.actions.TestActions.scaleCluster;
5266
import static oracle.weblogic.kubernetes.actions.TestActions.scaleClusterWithRestApi;
5367
import static oracle.weblogic.kubernetes.actions.TestActions.scaleClusterWithWLDF;
5468
import static oracle.weblogic.kubernetes.actions.impl.UniqueName.random;
69+
import static oracle.weblogic.kubernetes.actions.impl.primitive.Command.defaultCommandParams;
5570
import static oracle.weblogic.kubernetes.assertions.TestAssertions.credentialsNotValid;
5671
import static oracle.weblogic.kubernetes.assertions.TestAssertions.credentialsValid;
5772
import static oracle.weblogic.kubernetes.assertions.TestAssertions.podStateNotChanged;
@@ -91,6 +106,7 @@ private static ConditionFactory createStandardRetryPolicyWithAtMost(long minutes
91106

92107
public static ConditionFactory withStandardRetryPolicy = createStandardRetryPolicyWithAtMost(5);
93108
public static ConditionFactory withLongRetryPolicy = createStandardRetryPolicyWithAtMost(15);
109+
private static final String TMP_FILE_NAME = "temp-download-file.out";
94110

95111
/**
96112
* Test assertion using standard retry policy over time until it passes or the timeout expires.
@@ -1249,4 +1265,122 @@ public static String getUniqueName(String prefix, String... suffix) {
12491265
getLogger().info("Creating unique name {0}", cmName);
12501266
return cmName;
12511267
}
1268+
1269+
/**
1270+
* If we use actual URL of WDT or WIT return it. If we use the "latest" release figure out the
1271+
* actual version number and construct the complete URL
1272+
* @return the actual download URL
1273+
* @throws RuntimeException if the operation failed for any reason
1274+
*/
1275+
public static String getActualLocationIfNeeded(
1276+
String location,
1277+
String type,
1278+
String downloadDir
1279+
) throws RuntimeException {
1280+
String actualLocation = location;
1281+
if (needToGetActualLocation(location, type)) {
1282+
String version = "";
1283+
String command = String.format(
1284+
"curl -fL %s -o %s/%s-%s",
1285+
location,
1286+
downloadDir,
1287+
type,
1288+
TMP_FILE_NAME);
1289+
1290+
CommandParams params =
1291+
defaultCommandParams()
1292+
.command(command)
1293+
.saveResults(true);
1294+
if (!Command.withParams(params).execute()) {
1295+
RuntimeException exception =
1296+
new RuntimeException(String.format("Failed to get the latest %s release information.", type));
1297+
getLogger().severe(
1298+
String.format(
1299+
"Failed to get the latest %s release information. The stderr is %s",
1300+
type,
1301+
params.stderr()),
1302+
exception);
1303+
throw exception;
1304+
}
1305+
1306+
command = String.format(
1307+
"cat %s/%s-%s | grep 'releases/download' | awk '{ split($0,a,/href=\"/);%s | %s",
1308+
downloadDir,
1309+
type,
1310+
TMP_FILE_NAME,
1311+
" print a[2] }'",
1312+
" cut -d/ -f 6");
1313+
1314+
params =
1315+
defaultCommandParams()
1316+
.command(command)
1317+
.saveResults(true)
1318+
.redirect(true);
1319+
1320+
// the command is considered successful only if we have got back a real version number in params.stdout()
1321+
if (Command.withParams(params).execute()
1322+
&& params.stdout() != null
1323+
&& params.stdout().length() != 0) {
1324+
// Because I've updated the name of the logging exporter to remove the version number in the name, but
1325+
// also preserved the original, there will be two entries located. Take the first.
1326+
version = params.stdout().lines().findFirst().get().trim();
1327+
} else {
1328+
RuntimeException exception =
1329+
new RuntimeException(String.format("Failed to get the version number of the requested %s release.", type));
1330+
getLogger().severe(
1331+
String.format(
1332+
"Failed to get the version number of the requested %s release. The stderr is %s",
1333+
type,
1334+
params.stderr()),
1335+
exception);
1336+
throw exception;
1337+
}
1338+
1339+
if (version != null) {
1340+
actualLocation = location.replace("latest",
1341+
String.format("download/%s/%s", version, getInstallerFileName(type)));
1342+
}
1343+
}
1344+
getLogger().info("The actual download location for {0} is {1}", type, actualLocation);
1345+
return actualLocation;
1346+
}
1347+
1348+
private static boolean needToGetActualLocation(
1349+
String location,
1350+
String type) {
1351+
switch (type) {
1352+
case WDT:
1353+
return WDT_DOWNLOAD_URL_DEFAULT.equals(location);
1354+
case WIT:
1355+
return WIT_DOWNLOAD_URL_DEFAULT.equals(location);
1356+
case WLE:
1357+
return WLE_DOWNLOAD_URL_DEFAULT.equals(location);
1358+
case REMOTECONSOLE:
1359+
return REMOTECONSOLE_DOWNLOAD_URL_DEFAULT.equals(location);
1360+
default:
1361+
return false;
1362+
}
1363+
}
1364+
1365+
/**
1366+
* Get the installer download filename.
1367+
* @return the download filename
1368+
*/
1369+
public static String getInstallerFileName(
1370+
String type) {
1371+
switch (type) {
1372+
case WDT:
1373+
return WDT_DOWNLOAD_FILENAME_DEFAULT;
1374+
case WIT:
1375+
return WIT_DOWNLOAD_FILENAME_DEFAULT;
1376+
case WLE:
1377+
return WLE_DOWNLOAD_FILENAME_DEFAULT;
1378+
case SNAKE:
1379+
return SNAKE_DOWNLOADED_FILENAME;
1380+
case REMOTECONSOLE:
1381+
return REMOTECONSOLE_DOWNLOAD_FILENAME_DEFAULT;
1382+
default:
1383+
return "";
1384+
}
1385+
}
12521386
}

0 commit comments

Comments
 (0)