Skip to content

Commit 366b322

Browse files
committed
Merge branch 'owls-115469-wdt-40-support' into 'main'
Owls 115469 wdt 40 support in MII See merge request weblogic-cloud/weblogic-kubernetes-operator!4559
2 parents 6617ded + a37845a commit 366b322

File tree

3 files changed

+116
-18
lines changed

3 files changed

+116
-18
lines changed

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

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import static oracle.kubernetes.common.utils.CommonUtils.MAX_ALLOWED_VOLUME_NAME_LENGTH;
7474
import static oracle.kubernetes.common.utils.CommonUtils.VOLUME_NAME_SUFFIX;
7575
import static oracle.kubernetes.operator.DomainStatusUpdater.createKubernetesFailureSteps;
76+
import static oracle.kubernetes.operator.IntrospectorConfigMapConstants.NUM_CONFIG_MAPS;
7677
import static oracle.kubernetes.operator.WebLogicConstants.SHUTDOWN_STATE;
7778
import static oracle.kubernetes.operator.helpers.AffinityHelper.getDefaultAntiAffinity;
7879
import static oracle.kubernetes.utils.OperatorUtils.emptyToNull;
@@ -102,9 +103,11 @@ public class JobStepContext extends BasePodStepContext {
102103
private static final CommonUtils.CheckedFunction<String, String> getMD5Hash = CommonUtils::getMD5Hash;
103104
private V1Job jobModel;
104105
private Step conflictStep;
106+
private Packet packet;
105107

106108
JobStepContext(Packet packet) {
107109
super(packet.getSpi(DomainPresenceInfo.class));
110+
this.packet = packet;
108111
domainTopology = packet.getValue(ProcessingConstants.DOMAIN_TOPOLOGY);
109112
init();
110113
}
@@ -544,8 +547,23 @@ private String getDomainHomeOnPVHomeOwnership() {
544547
return uid + ":" + gid;
545548
}
546549

550+
private Integer getSpecifiedNumConfigMaps() {
551+
return Optional.ofNullable(packet.<String>getValue(NUM_CONFIG_MAPS)).map(this::parseOrNull).orElse(null);
552+
}
553+
554+
private Integer parseOrNull(String count) {
555+
try {
556+
return Integer.parseInt(count);
557+
} catch (NumberFormatException e) {
558+
return null;
559+
}
560+
}
561+
547562
@Override
548563
protected V1PodSpec createPodSpec() {
564+
565+
Integer numOfConfigMaps = getSpecifiedNumConfigMaps();
566+
549567
V1PodSpec podSpec = super.createPodSpec()
550568
.activeDeadlineSeconds(getActiveDeadlineSeconds())
551569
.restartPolicy("Never")
@@ -556,7 +574,17 @@ protected V1PodSpec createPodSpec() {
556574
.addVolumesItem(
557575
new V1Volume()
558576
.name("mii" + IntrospectorConfigMapConstants.INTROSPECTOR_CONFIG_MAP_NAME_SUFFIX)
559-
.configMap(getIntrospectMD5VolumeSource()));
577+
.configMap(getIntrospectMD5VolumeSource(0)));
578+
579+
if (numOfConfigMaps != null && numOfConfigMaps > 1) {
580+
for (int i = 1; i < numOfConfigMaps; i++) {
581+
podSpec.addVolumesItem(
582+
new V1Volume()
583+
.name("mii" + IntrospectorConfigMapConstants.INTROSPECTOR_CONFIG_MAP_NAME_SUFFIX + '-' + i)
584+
.configMap(getIntrospectMD5VolumeSource(i)));
585+
}
586+
}
587+
560588
if (getOpssWalletPasswordSecretVolume() != null) {
561589
podSpec.addVolumesItem(new V1Volume().name(OPSS_KEYPASSPHRASE_VOLUME).secret(
562590
getOpssWalletPasswordSecretVolume()));
@@ -653,6 +681,7 @@ private void addWdtSecretVolume(V1PodSpec podSpec) {
653681

654682
@Override
655683
protected V1Container createPrimaryContainer() {
684+
Integer numOfConfigMaps = getSpecifiedNumConfigMaps();
656685
V1Container container = super.createPrimaryContainer()
657686
.addVolumeMountsItem(readOnlyVolumeMount(SECRETS_VOLUME, SECRETS_MOUNT_PATH))
658687
.addVolumeMountsItem(readOnlyVolumeMount(SCRIPTS_VOLUME, SCRIPTS_MOUNTS_PATH))
@@ -662,6 +691,16 @@ protected V1Container createPrimaryContainer() {
662691
"/weblogic-operator/introspectormii")
663692
.readOnly(false));
664693

694+
if (numOfConfigMaps != null && numOfConfigMaps > 1) {
695+
for (int i = 1; i < numOfConfigMaps; i++) {
696+
container.addVolumeMountsItem(
697+
volumeMount(
698+
"mii" + IntrospectorConfigMapConstants.INTROSPECTOR_CONFIG_MAP_NAME_SUFFIX + '-' + i,
699+
"/weblogic-operator/introspectormii" + '-' + i)
700+
.readOnly(false));
701+
}
702+
}
703+
665704
if (getOpssWalletPasswordSecretVolume() != null) {
666705
container.addVolumeMountsItem(readOnlyVolumeMount(OPSS_KEYPASSPHRASE_VOLUME, OPSS_KEY_MOUNT_PATH));
667706
}
@@ -830,10 +869,14 @@ private V1ConfigMapVolumeSource getConfigMapVolumeSource() {
830869
.defaultMode(ALL_READ_AND_EXECUTE);
831870
}
832871

833-
private V1ConfigMapVolumeSource getIntrospectMD5VolumeSource() {
872+
private V1ConfigMapVolumeSource getIntrospectMD5VolumeSource(int index) {
873+
String suffix = "";
874+
if (index > 0) {
875+
suffix = "-" + index;
876+
}
834877
V1ConfigMapVolumeSource result =
835878
new V1ConfigMapVolumeSource()
836-
.name(getDomainUid() + IntrospectorConfigMapConstants.INTROSPECTOR_CONFIG_MAP_NAME_SUFFIX)
879+
.name(getDomainUid() + IntrospectorConfigMapConstants.INTROSPECTOR_CONFIG_MAP_NAME_SUFFIX + suffix)
837880
.defaultMode(ALL_READ_AND_EXECUTE);
838881
result.setOptional(true);
839882
return result;

operator/src/main/resources/scripts/introspectDomain.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def open(self):
150150
self.JDK_PATH = self.INTROSPECT_HOME + "/jdk.path"
151151
self.MII_SECRETS_AND_ENV_MD5 = self.INTROSPECT_HOME + "/secrets_and_env.md5"
152152
self.MII_DOMAINZIP_HASH = self.INTROSPECT_HOME + "/domainzip_hash"
153+
self.MII_DOMAIN_WDT_VERSION = self.INTROSPECT_HOME + "/domain_wdt_version"
153154
self.MII_WDT_CONFIGMAP_PATH = self.getEnvOrDef('WDT_CONFIGMAP_PATH',
154155
'/weblogic-operator/wdt-config-map')
155156
self.DOMAIN_SOURCE_TYPE = self.getEnvOrDef("DOMAIN_SOURCE_TYPE", None)
@@ -1122,24 +1123,35 @@ def addDomainConfig(self):
11221123
if (str(kubernetes_platform).upper() == 'OPENSHIFT'):
11231124
os.system("chmod -R g=u %s" % self.domain_home)
11241125

1125-
# Note: only config type is needed fmwconfig, security is excluded because it's in the primordial and contain
1126+
# Note: only certain config type is needed fmwconfig, security (except saml files) is excluded because it's in the primordial and contain
11261127
# all the many policies files
1127-
packcmd = "tar -pczf /tmp/domain.tar.gz %s/config/config.xml %s/config/jdbc/ %s/config/jms %s/config/coherence " \
1128-
"%s/config/diagnostics %s/config/startup %s/config/configCache %s/config/nodemanager " \
1129-
"%s/wlsdeploy/applications/*.xml " \
1130-
"%s/config/security %s/config/fmwconfig/servers/*/logging.xml" % ( self.domain_home,
1131-
self.domain_home, self.domain_home, self.domain_home, self.domain_home, self.domain_home,
1132-
self.domain_home, self.domain_home, self.domain_home, self.domain_home, self.domain_home)
1128+
1129+
tar_name = "/tmp/domain.tar"
1130+
packcmd = "tar -pcf %s " \
1131+
"--exclude=$DOMAIN_HOME/config/wlsdeploy/custom " \
1132+
"--exclude=$DOMAIN_HOME/config/deployments " \
1133+
"--exclude=$DOMAIN_HOME/config/fmwconfig " \
1134+
"$DOMAIN_HOME/wlsdeploy/applications/*.xml " \
1135+
"$DOMAIN_HOME/config " \
1136+
"$DOMAIN_HOME/security/saml*.properties " \
1137+
"$DOMAIN_HOME/security/*.xml " % tar_name
1138+
1139+
os.system(packcmd)
1140+
packcmd = "tar -prf %s $DOMAIN_HOME/config/fmwconfig/servers/*/logging.xml" % tar_name
11331141
os.system(packcmd)
1142+
os.system("gzip %s" % tar_name)
1143+
11341144
domain_data = self.env.readBinaryFile("/tmp/domain.tar.gz")
11351145
b64 = ""
11361146
for s in base64.encodestring(domain_data).splitlines():
11371147
b64 = b64 + s
11381148
self.writeln(b64)
1149+
11391150
domainzip_hash = md5.new(domain_data).hexdigest()
11401151
fh = open("/tmp/domainzip_hash", "w")
11411152
fh.write(domainzip_hash)
11421153
fh.close()
1154+
11431155
trace('done zipping up domain ')
11441156

11451157

@@ -1954,6 +1966,9 @@ def introspect(self):
19541966
trace("cfgmap write model hash")
19551967
# Must be called after MII_PrimordialDomainGenerator
19561968
MII_IntrospectCMFileGenerator(self.env, self.env.MII_DOMAINZIP_HASH, '/tmp/domainzip_hash').generate()
1969+
trace("cfgmap write domain wdt version")
1970+
if os.path.exists('/tmp/domain_wdt_version'):
1971+
MII_IntrospectCMFileGenerator(self.env, self.env.MII_DOMAIN_WDT_VERSION, '/tmp/domain_wdt_version').generate()
19571972

19581973
if self.isFromModelAndJRFDomain() or self.isInitializeDomainJRFOnPV():
19591974
trace("cfgmap write JRF wallet")

operator/src/main/resources/scripts/modelInImage.sh

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ INTROSPECTCM_MERGED_MODEL="/weblogic-operator/introspectormii/merged_model.json"
1616
INTROSPECTCM_WLS_VERSION="/weblogic-operator/introspectormii/wls.version"
1717
INTROSPECTCM_JDK_PATH="/weblogic-operator/introspectormii/jdk.path"
1818
INTROSPECTCM_SECRETS_AND_ENV_MD5="/weblogic-operator/introspectormii/secrets_and_env.md5"
19+
INTROSPECTCM_DOMAIN_WDT_VERSION="/weblogic-operator/introspectormii/domain_wdt_version"
1920
PRIMORDIAL_DOMAIN_ZIPPED="/weblogic-operator/introspectormii/primordial_domainzip.secure"
2021
WLSDOMAIN_CONFIG_ZIPPED="/weblogic-operator/introspectormii//domainzip.secure"
2122
INTROSPECTJOB_IMAGE_MD5="/tmp/inventory_image.md5"
@@ -442,6 +443,9 @@ checkWDTVersion() {
442443
exitOrLoop
443444
fi
444445

446+
if versionGE ${WDT_VERSION} "4.0.0" ; then
447+
echo "${WDT_VERSION}" > /tmp/domain_wdt_version
448+
fi
445449
trace "Exiting checkWDTVersion"
446450
}
447451

@@ -505,7 +509,7 @@ createModelDomain() {
505509
trace "Using newly created domain"
506510
elif [ -f ${PRIMORDIAL_DOMAIN_ZIPPED} ] ; then
507511
trace "Using existing primordial domain"
508-
cd / && base64 -d ${PRIMORDIAL_DOMAIN_ZIPPED} > ${LOCAL_PRIM_DOMAIN_ZIP} && tar -pxzf ${LOCAL_PRIM_DOMAIN_ZIP}
512+
restoreIntrospectorPrimordialDomain || return 1
509513
# create empty lib since we don't archive it in primordial zip and WDT will fail without it
510514
createFolder "${DOMAIN_HOME}/lib" "This is the './lib' directory within directory 'domain.spec.domainHome'." || exitOrLoop
511515
# Since the SerializedSystem ini is encrypted, restore it first
@@ -536,6 +540,13 @@ restorePrimordialDomain() {
536540
restoreEncodedTar "primordial_domainzip.secure" || return 1
537541
}
538542

543+
restoreIntrospectorPrimordialDomain() {
544+
cd / || return 1
545+
cat $(ls /weblogic-operator/introspectormii*/primordial_domainzip.secure | sort -t- -k3) > /tmp/domain.secure || return 1
546+
base64 -d "/tmp/domain.secure" > $LOCAL_PRIM_DOMAIN_ZIP || return 1
547+
tar -pxzf $LOCAL_PRIM_DOMAIN_ZIP || return 1
548+
}
549+
539550
# Restores the specified directory, targz'ed and stored in one or more config maps after base 64 encoding
540551
# args:
541552
# $1 the name of the encoded file in the config map
@@ -643,7 +654,9 @@ createPrimordialDomain() {
643654
trace "Entering createPrimordialDomain"
644655
local create_primordial_tgz=0
645656
local recreate_domain=0
646-
if [ -f ${PRIMORDIAL_DOMAIN_ZIPPED} ] ; then
657+
658+
659+
if [ -f ${PRIMORDIAL_DOMAIN_ZIPPED} ] ; then
647660
# If there is an existing domain in the cm - this is update in the lifecycle
648661
# Call WDT validateModel.sh to generate the new merged mdoel
649662
trace "Checking if security info has been changed"
@@ -672,6 +685,14 @@ createPrimordialDomain() {
672685
diff_model_v1 ${NEW_MERGED_MODEL} ${DECRYPTED_MERGED_MODEL}
673686
fi
674687

688+
if versionGE ${WDT_VERSION} "4.0.0" ; then
689+
# If this is WDT 4.0 or newer and there is an existing primordial domain and no domain version
690+
# then it is created from WDT 3.x, force recreate of the domain
691+
if [ -f ${PRIMORDIAL_DOMAIN_ZIPPED} ] && [ ! -f ${INTROSPECTCM_DOMAIN_WDT_VERSION} ] ; then
692+
recreate_domain=1
693+
fi
694+
fi
695+
675696
if [ "${MERGED_MODEL_ENVVARS_SAME}" == "false" ] ; then
676697

677698
diff_rc=$(cat /tmp/model_diff_rc)
@@ -1268,8 +1289,8 @@ encrypt_decrypt_domain_secret() {
12681289
trace "Exiting encrypt_decrypt_domain_secret"
12691290
}
12701291

1271-
# prepare mii server
1272-
restorAppAndLibs() {
1292+
# restore App Libs and others from the archive
1293+
restoreAppAndLibs() {
12731294

12741295
createFolder "${DOMAIN_HOME}/lib" "This is the './lib' directory within DOMAIN_HOME directory 'domain.spec.domainHome'." || return 1
12751296
local WLSDEPLOY_DOMAINLIB="wlsdeploy/domainLibraries"
@@ -1308,6 +1329,16 @@ restorAppAndLibs() {
13081329
trace SEVERE "Domain Source Type is FromModel, error in extracting application archive ${IMG_ARCHIVES_ROOTDIR}/${file}"
13091330
return 1
13101331
fi
1332+
1333+
if versionGE ${WDT_VERSION} "4.0.0" ; then
1334+
trace INFO "Newer version of WDT 4.0.0 - check if there is old archive format of these files"
1335+
if [ -d ${DOMAIN_HOME}/wlsdeploy/custom ] ; then
1336+
# copy to under DOMAIN_HOME/config
1337+
mkdir -p ${DOMAIN_HOME}/config/wlsdeploy/custom
1338+
cp -R ${DOMAIN_HOME}/wlsdeploy/custom/* ${DOMAIN_HOME}/config/wlsdeploy/custom
1339+
fi
1340+
1341+
fi
13111342
done
13121343

13131344
}
@@ -1318,6 +1349,10 @@ restoreZippedDbWallets() {
13181349
if [ "$count" -gt 0 ] ; then
13191350
find ${DOMAIN_HOME}/wlsdeploy/dbWallets/*/*.zip -type f | xargs -I % sh -c 'unzip -jo % -d $(dirname %) ; rm %'
13201351
fi
1352+
count=$(find ${DOMAIN_HOME}/config/wlsdeploy/dbWallets/*/*.zip -type f 2>/dev/null | wc -l)
1353+
if [ "$count" -gt 0 ] ; then
1354+
find ${DOMAIN_HOME}/config/wlsdeploy/dbWallets/*/*.zip -type f | xargs -I % sh -c 'unzip -jo % -d $(dirname %) ; rm %'
1355+
fi
13211356
}
13221357

13231358

@@ -1358,7 +1393,7 @@ prepareMIIServer() {
13581393
# during introspection, it will overwrite the tokenized version in the archive.
13591394

13601395
trace "Model-in-Image: Restoring apps and libraries"
1361-
restorAppAndLibs || return 1
1396+
restoreAppAndLibs || return 1
13621397

13631398
trace "Model-in-Image: Restore domain config"
13641399
restoreDomainConfig || return 1
@@ -1378,14 +1413,19 @@ logSevereAndExit() {
13781413
exitOrLoop
13791414
}
13801415

1381-
# Function to expand the WDT custom folder from the archive before calling update or create domain.
1416+
# Function to expand the WDT custom/wallet folders from the archive before calling update domain.
1417+
# The domain may be created by WDT 3 and older archive format, restore any entries prior to update
1418+
# new 4.0 entry paths are config/**
13821419
expandWdtArchiveCustomDir() {
13831420
cd ${DOMAIN_HOME} || exitOrLoop
13841421
for file in $(sort_files ${IMG_ARCHIVES_ROOTDIR} "*.zip")
13851422
do
13861423
${JAVA_HOME}/bin/jar xf ${IMG_ARCHIVES_ROOTDIR}/${file} wlsdeploy/custom
1424+
${JAVA_HOME}/bin/jar xf ${IMG_ARCHIVES_ROOTDIR}/${file} wlsdeploy/dbWallets
1425+
${JAVA_HOME}/bin/jar xf ${IMG_ARCHIVES_ROOTDIR}/${file} config/wlsdeploy/custom
13871426
done
13881427

1389-
CUSTOM_DIR=${DOMAIN_HOME}/wlsdeploy/custom
1390-
traceDirs before CUSTOM_DIR
1428+
restoreZippedDbWallets
1429+
trace "Listing domain home directories"
1430+
ls -lR ${DOMAIN_HOME}
13911431
}

0 commit comments

Comments
 (0)