Skip to content

Commit 91d68d9

Browse files
committed
Fix issues in upgrade test
1 parent 4921db8 commit 91d68d9

File tree

1 file changed

+7
-188
lines changed

1 file changed

+7
-188
lines changed

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

Lines changed: 7 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2024, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2025, 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.weblogic.kubernetes;
@@ -19,21 +19,12 @@
1919
import java.util.Properties;
2020

2121
import io.kubernetes.client.custom.Quantity;
22-
import io.kubernetes.client.openapi.models.V1EnvVar;
23-
import io.kubernetes.client.openapi.models.V1LocalObjectReference;
24-
import io.kubernetes.client.openapi.models.V1ObjectMeta;
25-
import oracle.weblogic.domain.AdminServer;
26-
import oracle.weblogic.domain.AdminService;
27-
import oracle.weblogic.domain.Channel;
2822
import oracle.weblogic.domain.Configuration;
2923
import oracle.weblogic.domain.CreateIfNotExists;
3024
import oracle.weblogic.domain.DomainCreationImage;
3125
import oracle.weblogic.domain.DomainOnPV;
3226
import oracle.weblogic.domain.DomainOnPVType;
3327
import oracle.weblogic.domain.DomainResource;
34-
import oracle.weblogic.domain.DomainSpec;
35-
import oracle.weblogic.domain.Model;
36-
import oracle.weblogic.domain.ServerPod;
3728
import oracle.weblogic.kubernetes.actions.impl.primitive.Command;
3829
import oracle.weblogic.kubernetes.actions.impl.primitive.CommandParams;
3930
import oracle.weblogic.kubernetes.actions.impl.primitive.WitParams;
@@ -66,49 +57,36 @@
6657
import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST;
6758
import static oracle.weblogic.kubernetes.TestConstants.KIND_CLUSTER;
6859
import static oracle.weblogic.kubernetes.TestConstants.KUBERNETES_CLI;
69-
import static oracle.weblogic.kubernetes.TestConstants.MII_AUXILIARY_IMAGE_NAME;
70-
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_APP_NAME;
7160
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_NAME;
7261
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
73-
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_WDT_MODEL_FILE;
7462
import static oracle.weblogic.kubernetes.TestConstants.OKE_CLUSTER;
7563
import static oracle.weblogic.kubernetes.TestConstants.OLD_DOMAIN_VERSION;
7664
import static oracle.weblogic.kubernetes.TestConstants.RESULTS_ROOT;
7765
import static oracle.weblogic.kubernetes.TestConstants.RESULTS_TEMPFILE;
7866
import static oracle.weblogic.kubernetes.TestConstants.SKIP_CLEANUP;
79-
import static oracle.weblogic.kubernetes.TestConstants.SSL_PROPERTIES;
80-
import static oracle.weblogic.kubernetes.TestConstants.TEST_IMAGES_REPO_SECRET_NAME;
8167
import static oracle.weblogic.kubernetes.TestConstants.TRAEFIK_INGRESS_HTTP_HOSTPORT;
8268
import static oracle.weblogic.kubernetes.TestConstants.WDT_BASIC_IMAGE_NAME;
8369
import static oracle.weblogic.kubernetes.TestConstants.WDT_BASIC_IMAGE_TAG;
84-
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TO_USE_IN_SPEC;
8570
import static oracle.weblogic.kubernetes.TestConstants.WLSIMG_BUILDER;
8671
import static oracle.weblogic.kubernetes.TestConstants.WLSIMG_BUILDER_DEFAULT;
87-
import static oracle.weblogic.kubernetes.actions.ActionConstants.ARCHIVE_DIR;
8872
import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR;
8973
import static oracle.weblogic.kubernetes.actions.ActionConstants.RESOURCE_DIR;
90-
import static oracle.weblogic.kubernetes.actions.ActionConstants.WORK_DIR;
91-
import static oracle.weblogic.kubernetes.actions.TestActions.createDomainCustomResource;
9274
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
9375
import static oracle.weblogic.kubernetes.actions.TestActions.scaleCluster;
94-
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists;
9576
import static oracle.weblogic.kubernetes.utils.ApplicationUtils.collectAppAvailability;
9677
import static oracle.weblogic.kubernetes.utils.ApplicationUtils.deployAndAccessApplication;
9778
import static oracle.weblogic.kubernetes.utils.ApplicationUtils.verifyAdminConsoleAccessible;
9879
import static oracle.weblogic.kubernetes.utils.ApplicationUtils.verifyAdminServerRESTAccess;
9980
import static oracle.weblogic.kubernetes.utils.AuxiliaryImageUtils.createAndPushAuxiliaryImage;
100-
import static oracle.weblogic.kubernetes.utils.AuxiliaryImageUtils.createPushAuxiliaryImageWithDomainConfig;
10181
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.verifyPodsNotRolled;
10282
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkServiceExists;
10383
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createIngressHostRouting;
10484
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.formatIPv6Host;
105-
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getNextFreePort;
10685
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getUniqueName;
10786
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
10887
import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainAndVerify;
10988
import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainResourceOnPv;
11089
import static oracle.weblogic.kubernetes.utils.DomainUtils.verifyDomainStatusConditionTypeDoesNotExist;
111-
import static oracle.weblogic.kubernetes.utils.FileUtils.generateFileFromTemplate;
11290
import static oracle.weblogic.kubernetes.utils.FileUtils.replaceStringInFile;
11391
import static oracle.weblogic.kubernetes.utils.FmwUtils.getConfiguration;
11492
import static oracle.weblogic.kubernetes.utils.FmwUtils.verifyDomainReady;
@@ -161,8 +139,6 @@ class ItOperatorWlsUpgrade {
161139
private String domainNamespace;
162140
private Path srcDomainYaml = null;
163141
private Path destDomainYaml = null;
164-
private static String miiAuxiliaryImageTag = "aux-explict-upgrade";
165-
private static final String miiAuxiliaryImage = MII_AUXILIARY_IMAGE_NAME + ":" + miiAuxiliaryImageTag;
166142
private static String hostHeader;
167143

168144
/**
@@ -181,7 +157,7 @@ void beforeEach(@Namespaces(2) List<String> namespaces) {
181157
}
182158

183159
/**
184-
* Does some initialization of logger, conditionfactory, etc common
160+
* Does some initialization of logger, conditionfactory, etc. common
185161
* to all test methods.
186162
*/
187163
@BeforeAll
@@ -320,73 +296,6 @@ void tearDown() {
320296
}
321297
}
322298

323-
void upgradeWlsAuxDomain(String oldVersion) {
324-
logger.info("Upgrade version/{0} Auxiliary Domain(v8) to current", oldVersion);
325-
installOldOperator(oldVersion,opNamespace,domainNamespace);
326-
createSecrets();
327-
328-
// Create the repo secret to pull base WebLogic image
329-
createBaseRepoSecret(domainNamespace);
330-
331-
// Creating an aux image domain with v8 version
332-
List<String> archiveList = Collections.singletonList(ARCHIVE_DIR + "/" + MII_BASIC_APP_NAME + ".zip");
333-
List<String> modelList = new ArrayList<>();
334-
modelList.add(MODEL_DIR + "/" + MII_BASIC_WDT_MODEL_FILE);
335-
modelList.add(MODEL_DIR + "/model.jms2.yaml");
336-
logger.info("creating auxiliary image {0}:{1} using imagetool.sh ", miiAuxiliaryImage, MII_BASIC_IMAGE_TAG);
337-
createPushAuxiliaryImageWithDomainConfig(MII_AUXILIARY_IMAGE_NAME, miiAuxiliaryImageTag, archiveList, modelList);
338-
339-
// Generate a v8 version of domain.yaml file from a template file
340-
// by replacing domain namespace, domain uid, base image and aux image
341-
String auxImage = MII_AUXILIARY_IMAGE_NAME + ":" + miiAuxiliaryImageTag;
342-
Map<String, String> templateMap = new HashMap<>();
343-
templateMap.put("DOMAIN_NS", domainNamespace);
344-
templateMap.put("DOMAIN_UID", domainUid);
345-
templateMap.put("AUX_IMAGE", auxImage);
346-
templateMap.put("BASE_IMAGE", WEBLOGIC_IMAGE_TO_USE_IN_SPEC);
347-
templateMap.put("API_VERSION", "v8");
348-
Path srcDomainFile = Paths.get(RESOURCE_DIR,
349-
"upgrade", "auxilary.single.image.template.yaml");
350-
Path targetDomainFile = assertDoesNotThrow(
351-
() -> generateFileFromTemplate(srcDomainFile.toString(),
352-
"domain.yaml", templateMap));
353-
logger.info("Generated Domain Resource file {0}", targetDomainFile);
354-
355-
// run KUBERNETES_CLI to create the domain
356-
logger.info("Run " + KUBERNETES_CLI + " to create the domain");
357-
CommandParams params = new CommandParams().defaults();
358-
params.command(KUBERNETES_CLI + " apply -f "
359-
+ Paths.get(WORK_DIR + "/domain.yaml"));
360-
boolean result = Command.withParams(params).execute();
361-
assertTrue(result, "Failed to create domain custom resource");
362-
363-
// wait for the domain to exist
364-
logger.info("Checking for domain custom resource in namespace {0}", domainNamespace);
365-
testUntil(
366-
domainExists(domainUid, "v8", domainNamespace),
367-
logger,
368-
"domain {0} to be created in namespace {1}",
369-
domainUid,
370-
domainNamespace);
371-
checkDomainStarted(domainUid, domainNamespace);
372-
LinkedHashMap<String, OffsetDateTime> pods = new LinkedHashMap<>();
373-
pods.put(adminServerPodName, getPodCreationTime(domainNamespace, adminServerPodName));
374-
// get the creation time of the managed server pods before upgrading the operator
375-
for (int i = 1; i <= replicaCount; i++) {
376-
pods.put(managedServerPodNamePrefix + i, getPodCreationTime(domainNamespace, managedServerPodNamePrefix + i));
377-
}
378-
// verify there is no status condition type Completed
379-
// before upgrading to Latest
380-
verifyDomainStatusConditionTypeDoesNotExist(domainUid, domainNamespace,
381-
DOMAIN_STATUS_CONDITION_COMPLETED_TYPE, OLD_DOMAIN_VERSION);
382-
upgradeOperatorToCurrent(opNamespace);
383-
checkDomainStatus(domainNamespace,domainUid);
384-
verifyPodsNotRolled(domainNamespace, pods);
385-
scaleClusterUpAndDown();
386-
}
387-
388-
389-
390299
// After upgrade scale up/down the cluster
391300
private void scaleClusterUpAndDown() {
392301
String clusterName = domainUid + "-" + "cluster-1";
@@ -464,12 +373,10 @@ private void upgradeOperatorAndVerify(String opNamespace, String domainNamespace
464373
logger.info("Start a thread to keep track of application availability");
465374
Thread accountingThread =
466375
new Thread(
467-
() -> {
468-
collectAppAvailability(
469-
domainNamespace, opNamespace, appAvailability,
470-
adminServerPodName, managedServerPodNamePrefix,
471-
replicaCount, "7001", "8001", "testwebapp/index.jsp");
472-
});
376+
() -> collectAppAvailability(
377+
domainNamespace, opNamespace, appAvailability,
378+
adminServerPodName, managedServerPodNamePrefix,
379+
replicaCount, "7001", "8001", "testwebapp/index.jsp"));
473380
accountingThread.start();
474381
try {
475382
// upgrade to current operator
@@ -581,94 +488,6 @@ private void restartDomain(String domainUid, String domainNamespace) {
581488
checkDomainStarted(domainUid, domainNamespace);
582489
}
583490

584-
private void createDomainResource(
585-
String domainNamespace,
586-
String domVersion,
587-
String domainHomeSourceType,
588-
String domainImage) {
589-
590-
String domApiVersion = "weblogic.oracle/" + domVersion;
591-
logger.info("Default Domain API version {0}", DOMAIN_API_VERSION);
592-
logger.info("Domain API version selected {0}", domApiVersion);
593-
logger.info("Domain Image name selected {0}", domainImage);
594-
logger.info("Create domain resource for domainUid {0} in namespace {1}",
595-
domainUid, domainNamespace);
596-
597-
// create encryption secret
598-
logger.info("Create encryption secret");
599-
String encryptionSecretName = "encryptionsecret";
600-
createSecretWithUsernamePassword(encryptionSecretName, domainNamespace,
601-
"weblogicenc", "weblogicenc");
602-
DomainResource domain = new DomainResource()
603-
.apiVersion(domApiVersion)
604-
.kind("Domain")
605-
.metadata(new V1ObjectMeta()
606-
.name(domainUid)
607-
.namespace(domainNamespace))
608-
.spec(new DomainSpec()
609-
.domainUid(domainUid)
610-
.domainHomeSourceType(domainHomeSourceType)
611-
.image(domainImage)
612-
.addImagePullSecretsItem(new V1LocalObjectReference()
613-
.name(TEST_IMAGES_REPO_SECRET_NAME))
614-
.webLogicCredentialsSecret(new V1LocalObjectReference()
615-
.name(adminSecretName))
616-
.includeServerOutInPodLog(true)
617-
.serverStartPolicy("weblogic.oracle/v8".equals(domApiVersion) ? "IF_NEEDED" : "IfNeeded")
618-
.serverPod(new ServerPod()
619-
.addEnvItem(new V1EnvVar()
620-
.name("JAVA_OPTIONS")
621-
.value(SSL_PROPERTIES))
622-
.addEnvItem(new V1EnvVar()
623-
.name("USER_MEM_ARGS")
624-
.value("-Djava.security.egd=file:/dev/./urandom ")))
625-
.adminServer(new AdminServer()
626-
.adminService(new AdminService()
627-
.addChannelsItem(new Channel()
628-
.channelName("default")
629-
.nodePort(getNextFreePort()))))
630-
.configuration(new Configuration()
631-
.model(new Model()
632-
.runtimeEncryptionSecret(encryptionSecretName)
633-
.domainType("WLS"))
634-
.introspectorJobActiveDeadlineSeconds(300L)));
635-
boolean domCreated = assertDoesNotThrow(() -> createDomainCustomResource(domain, domVersion),
636-
String.format("Create domain custom resource failed with ApiException for %s in namespace %s",
637-
domainUid, domainNamespace));
638-
assertTrue(domCreated,
639-
String.format("Create domain custom resource failed with ApiException "
640-
+ "for %s in namespace %s", domainUid, domainNamespace));
641-
setPodAntiAffinity(domain);
642-
removePortForwardingAttribute(domainNamespace,domainUid);
643-
}
644-
645-
// Remove the artifact adminChannelPortForwardingEnabled from domain resource
646-
// if exist, so that the Operator release default will be effective.
647-
// e.g. in Release 3.3.x the default is false, but 4.x.x onward it is true
648-
// However in release(s) lower to 3.3.x, the CRD does not contain this attribute
649-
// so the patch command to remove this attribute fails. So we do not assert
650-
// the result of patch command
651-
private void removePortForwardingAttribute(
652-
String domainNamespace, String domainUid) {
653-
654-
StringBuffer patchStr = new StringBuffer("[{");
655-
patchStr.append("\"op\": \"remove\",")
656-
.append(" \"path\": \"/spec/adminServer/adminChannelPortForwardingEnabled\"")
657-
.append("}]");
658-
logger.info("The patch String {0}", patchStr);
659-
StringBuffer commandStr = new StringBuffer(KUBERNETES_CLI + " patch domain ");
660-
commandStr.append(domainUid)
661-
.append(" -n " + domainNamespace)
662-
.append(" --type 'json' -p='")
663-
.append(patchStr)
664-
.append("'");
665-
logger.info("The Command String: {0}", commandStr);
666-
CommandParams params = new CommandParams().defaults();
667-
668-
params.command(new String(commandStr));
669-
Command.withParams(params).execute();
670-
}
671-
672491
/**
673492
* Replace the fields in domain yaml file with testing attributes.
674493
* For example, namespace, domainUid, and image. Then create domain using
@@ -844,7 +663,7 @@ void installOperatorCreatesPvPvcWlsDomainAndUpgrade(String operatorVersion) {
844663
upgradeOperatorToCurrent(opNamespace);
845664
checkDomainStatus(domainNamespace, domainUid);
846665
verifyPodsNotRolled(domainNamespace, pods);
847-
scaleClusterUpAndDown(clusterName);
666+
scaleClusterUpAndDown(domainUid + "-" + clusterName);
848667
}
849668

850669

0 commit comments

Comments
 (0)