Skip to content

Commit ee1a28f

Browse files
committed
Merge branch 'fixwlsmii' into 'release/4.2'
OWLS-128825 - ItWlsMiiLegacySample.testUpate4, ItWlsMiiSample.testUpate4 failed due run-test.sh does not check pod readiness before comparing See merge request weblogic-cloud/weblogic-kubernetes-operator!4966
2 parents 9b70ed6 + e34df1f commit ee1a28f

File tree

3 files changed

+125
-88
lines changed

3 files changed

+125
-88
lines changed

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

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST;
3232
import static oracle.weblogic.kubernetes.TestConstants.KIND_CLUSTER;
3333
import static oracle.weblogic.kubernetes.TestConstants.KIND_REPO;
34+
import static oracle.weblogic.kubernetes.TestConstants.KUBERNETES_CLI;
3435
import static oracle.weblogic.kubernetes.TestConstants.OKD;
3536
import static oracle.weblogic.kubernetes.TestConstants.RESULTS_ROOT;
3637
import static oracle.weblogic.kubernetes.TestConstants.TEST_IMAGES_REPO_SECRET_NAME;
@@ -87,7 +88,6 @@ class ItWlsMiiSample {
8788
@BeforeAll
8889
public static void initAll(@Namespaces(3) List<String> namespaces) {
8990
logger = getLogger();
90-
9191
// get a new unique opNamespace
9292
logger.info("Creating unique namespace for Operator");
9393
assertNotNull(namespaces.get(0), "Namespace list is null");
@@ -101,42 +101,37 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
101101
assertNotNull(namespaces.get(2), "Namespace list is null");
102102
traefikNamespace = namespaces.get(2);
103103

104-
String miiSampleWorkDir =
105-
RESULTS_ROOT + "/" + domainNamespace + "/model-in-image-sample-work-dir";
104+
String miiSampleWorkDir = RESULTS_ROOT + "/" + domainNamespace + "/model-in-image-sample-work-dir";
106105

107-
// env variables to override default values in sample scripts
108106
envMap = new HashMap<>();
109107
envMap.put("OPER_NAMESPACE", opNamespace);
110108
envMap.put("DOMAIN_NAMESPACE", domainNamespace);
111109
envMap.put("DOMAIN_UID1", getUniqueName("sample-domain1-"));
112110
envMap.put("DOMAIN_UID2", getUniqueName("sample-domain2-"));
113111
envMap.put("TRAEFIK_NAMESPACE", traefikNamespace);
114-
envMap.put("TRAEFIK_HTTP_NODEPORT", "0"); // 0-->dynamically choose the np
115-
envMap.put("TRAEFIK_HTTPS_NODEPORT", "0"); // 0-->dynamically choose the np
112+
envMap.put("TRAEFIK_HTTP_NODEPORT", "0");// 0-->dynamically choose the np
113+
envMap.put("TRAEFIK_HTTPS_NODEPORT", "0");// 0-->dynamically choose the np
116114
envMap.put("TRAEFIK_NAME", TRAEFIK_RELEASE_NAME + "-" + traefikNamespace.substring(3));
117115
envMap.put("TRAEFIK_IMAGE_REGISTRY", TRAEFIK_INGRESS_IMAGE_REGISTRY);
118116
envMap.put("TRAEFIK_IMAGE_REPOSITORY", TRAEFIK_INGRESS_IMAGE_NAME);
119117
envMap.put("TRAEFIK_IMAGE_TAG", TRAEFIK_INGRESS_IMAGE_TAG);
120118
envMap.put("WORKDIR", miiSampleWorkDir);
121-
envMap.put("BASE_IMAGE_NAME", WEBLOGIC_IMAGE_TO_USE_IN_SPEC
122-
.substring(0, WEBLOGIC_IMAGE_TO_USE_IN_SPEC.lastIndexOf(":")));
119+
envMap.put("BASE_IMAGE_NAME", WEBLOGIC_IMAGE_TO_USE_IN_SPEC.substring(0,
120+
WEBLOGIC_IMAGE_TO_USE_IN_SPEC.lastIndexOf(":")));
123121
envMap.put("BASE_IMAGE_TAG", WEBLOGIC_IMAGE_TAG);
124122
envMap.put("IMAGE_PULL_SECRET_NAME", BASE_IMAGES_REPO_SECRET_NAME);
125123
envMap.put("DOMAIN_IMAGE_PULL_SECRET_NAME", TEST_IMAGES_REPO_SECRET_NAME);
126124
envMap.put("WLSIMG_BUILDER_DEFAULT", WLSIMG_BUILDER_DEFAULT);
127125
envMap.put("WLSIMG_BUILDER", WLSIMG_BUILDER);
128-
envMap.put("OKD", "" + OKD);
129-
envMap.put("KIND_CLUSTER", "" + KIND_CLUSTER);
126+
envMap.put("OKD", String.valueOf(OKD));
127+
envMap.put("KIND_CLUSTER", String.valueOf(KIND_CLUSTER));
130128

131-
// kind cluster uses openjdk which is not supported by image tool
132129
if (WIT_JAVA_HOME != null) {
133130
envMap.put("JAVA_HOME", WIT_JAVA_HOME);
134131
}
135-
136132
if (WIT_DOWNLOAD_URL != null) {
137133
envMap.put("WIT_INSTALLER_URL", WIT_DOWNLOAD_URL);
138134
}
139-
140135
if (WDT_DOWNLOAD_URL != null) {
141136
envMap.put("WDT_INSTALLER_URL", WDT_DOWNLOAD_URL);
142137
}
@@ -146,23 +141,16 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
146141
envMap.put("OPER_IMAGE_NAME", "localhost/weblogic-kubernetes-operator");
147142
envMap.put("MODEL_IMAGE_NAME", DOMAIN_CREATION_IMAGE_NAME);
148143
envMap.put("K8S_NODEPORT_HOST", assertDoesNotThrow(() -> InetAddress.getLocalHost().getHostAddress()));
149-
envMap.put("TRAEFIK_INGRESS_HTTP_HOSTPORT", "" + TRAEFIK_INGRESS_HTTP_HOSTPORT);
150-
envMap.put("TRAEFIK_NAMESPACE", TRAEFIK_NAMESPACE);
144+
envMap.put("TRAEFIK_INGRESS_HTTP_HOSTPORT", String.valueOf(TRAEFIK_INGRESS_HTTP_HOSTPORT));
151145
} else {
152-
envMap.put("TRAEFIK_NAMESPACE", traefikNamespace);
153146
envMap.put("K8S_NODEPORT_HOST", K8S_NODEPORT_HOST);
154147
}
155-
148+
156149
logger.info("Environment variables to the script {0}", envMap);
157150

158-
logger.info("Setting up image registry secrets");
159-
// Create the repo secret to pull the domain image
160-
// this secret is used only for non-kind cluster
161151
createTestRepoSecret(domainNamespace);
162152
logger.info("Registry secret {0} created for domain image successfully in namespace {1}",
163153
TEST_IMAGES_REPO_SECRET_NAME, domainNamespace);
164-
// Create the repo secret to pull the base image
165-
// this secret is used only for non-kind cluster
166154
createBaseRepoSecret(domainNamespace);
167155
logger.info("Registry secret {0} for base image created successfully in namespace {1}",
168156
BASE_IMAGES_REPO_SECRET_NAME, domainNamespace);
@@ -274,39 +262,63 @@ public void testUpate4() {
274262
* @param arg arguments to execute script
275263
* @param errString a string of detailed error
276264
*/
277-
private void execTestScriptAndAssertSuccess(String arg,
278-
String errString) {
279-
265+
private void execTestScriptAndAssertSuccess(String arg, String errString) {
280266
Assumptions.assumeTrue(previousTestSuccessful);
281267
previousTestSuccessful = false;
282268

283-
String command = miiSampleScript
284-
+ " "
285-
+ arg;
286-
287-
ExecResult result = Command.withParams(
288-
new CommandParams()
289-
.command(command)
290-
.env(envMap)
291-
.redirect(true)
292-
).executeAndReturnResult();
269+
Map<String, String> podSnapshotBefore = null;
270+
if ("-update4".equals(arg)) {
271+
podSnapshotBefore = getPodTimestamps(envMap.get("DOMAIN_NAMESPACE"));
272+
}
293273

294-
boolean success =
295-
result != null
296-
&& result.exitValue() == 0
297-
&& result.stdout() != null
298-
&& result.stdout().contains("Finished without errors");
274+
String command = miiSampleScript + " " + arg;
275+
ExecResult result = Command.withParams(new CommandParams().command(command)
276+
.env(envMap).redirect(true)).executeAndReturnResult();
277+
278+
boolean success = result != null && result.exitValue() == 0 && result.stdout() != null
279+
&& result.stdout().contains("Finished without errors");
280+
281+
if (success && "-update4".equals(arg)) {
282+
Map<String, String> podSnapshotAfter = getPodTimestamps(envMap.get("DOMAIN_NAMESPACE"));
283+
for (Map.Entry<String, String> entry : podSnapshotBefore.entrySet()) {
284+
String pod = entry.getKey();
285+
String beforeTime = entry.getValue();
286+
String afterTime = podSnapshotAfter.get(pod);
287+
if (afterTime != null && !beforeTime.equals(afterTime)) {
288+
success = false;
289+
logger.severe("Unexpected pod restart detected for pod "
290+
+ pod + ": before=" + beforeTime + " after=" + afterTime);
291+
}
292+
}
293+
}
299294

300-
String outStr = errString;
301-
outStr += ", command=\n{\n" + command + "\n}\n";
302-
outStr += ", stderr=\n{\n" + (result != null ? result.stderr() : "") + "\n}\n";
303-
outStr += ", stdout=\n{\n" + (result != null ? result.stdout() : "") + "\n}\n";
295+
String outStr = errString + ", command=\n{\n" + command + "\n}\n"
296+
+ ", stderr=\n{\n" + (result != null ? result.stderr() : "") + "\n}\n"
297+
+ ", stdout=\n{\n" + (result != null ? result.stdout() : "") + "\n}\n";
304298

305299
assertTrue(success, outStr);
306-
307300
previousTestSuccessful = true;
308301
}
309302

303+
private Map<String, String> getPodTimestamps(String namespace) {
304+
ExecResult result = Command.withParams(new CommandParams()
305+
.command(KUBERNETES_CLI + " get pods -n " + namespace
306+
+ " -o=jsonpath='{range .items[*]}{.metadata.name}:{.metadata.creationTimestamp}\\n{end}'")
307+
.redirect(true)).executeAndReturnResult();
308+
309+
Map<String, String> timestamps = new HashMap<>();
310+
if (result != null && result.exitValue() == 0 && result.stdout() != null) {
311+
String[] lines = result.stdout().replace("'", "").split("\n");
312+
for (String line : lines) {
313+
String[] parts = line.trim().split(":");
314+
if (parts.length == 2) {
315+
timestamps.put(parts[0], parts[1]);
316+
}
317+
}
318+
}
319+
return timestamps;
320+
}
321+
310322
/**
311323
* Uninstall Traefik.
312324
*/
Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
22

3-
# Copyright (c) 2018, 2022, Oracle and/or its affiliates.
3+
# Copyright (c) 2018, 2025, Oracle and/or its affiliates.
44
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55

66
# 'build-wl-operator.sh'
77
#
8-
# Build and helm install an operator that monitors DOMAIN_NAMESPACE.
9-
#
8+
# Build and helm install an operator that monitors DOMAIN_NAMESPACE.
9+
#
1010
# This script is not necessary if the operator is already running
1111
# and monitoring DOMAIN_NAMESPACE.
1212
#
@@ -19,63 +19,76 @@ set -o pipefail
1919

2020
TESTDIR="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
2121
SRCDIR="$( cd "$TESTDIR/../../.." > /dev/null 2>&1 ; pwd -P )"
22+
cd "${SRCDIR}"
2223

23-
cd ${SRCDIR}
24-
25-
echo "build Operator image"
24+
echo "Building Operator image..."
2625

26+
# Environment and defaults
2727
OPER_IMAGE_TAG=${OPER_IMAGE_TAG:-test}
2828
OPER_IMAGE_NAME=${OPER_IMAGE_NAME:-weblogic-kubernetes-operator}
29-
OPER_JAR_VERSION="`grep -m1 "<version>" pom.xml | cut -f2 -d">" | cut -f1 -d "<"`"
29+
OPER_JAR_VERSION="$(grep -m1 '<version>' pom.xml | cut -f2 -d'>' | cut -f1 -d'<')"
3030

31-
echo "OPER_IMAGE_NAME=$OPER_IMAGE_NAME"
32-
echo "OPER_IMAGE_TAG=$OPER_IMAGE_TAG"
33-
echo "OPER_JAR_VERSION=$OPER_JAR_VERSION"
31+
echo "OPER_IMAGE_NAME=${OPER_IMAGE_NAME}"
32+
echo "OPER_IMAGE_TAG=${OPER_IMAGE_TAG}"
33+
echo "OPER_JAR_VERSION=${OPER_JAR_VERSION}"
3434

35+
# Generate checksum based on content
3536
latest_cksum() {
3637
# force a rebuild even if only image name/tag/ver changes...
3738
echo "$OPER_IMAGE_NAME $OPER_IMAGE_TAG $OPER_JAR_VERSION"
3839

3940
# force a rebuild if the image isn't cached anymore
40-
${WLSIMG_BUILDER:-docker} images $OPER_IMAGE_NAME:$OPER_IMAGE_TAG -q
41-
41+
${WLSIMG_BUILDER:-docker} images "$OPER_IMAGE_NAME:$OPER_IMAGE_TAG" -q || true
4242
# force a rebuild if any .java, .sh, or .py file changed
43-
find "$SRCDIR/operator/src/main" -name "*.[jsp]*" | xargs cat | cksum
44-
find "$SRCDIR/operator/src/test" -name "*.[jsp]*" | xargs cat | cksum
43+
find "$SRCDIR/operator/src/main" "$SRCDIR/operator/src/test" -type f \( -name "*.java" -o -name "*.sh" -o -name "*.py" \) -exec cat {} + | cksum
4544
}
4645

4746
save_cksum() {
48-
latest_cksum > $SRCDIR/operator/src/main.cksum
47+
latest_cksum > "$SRCDIR/operator/src/main.cksum"
4948
}
5049

5150
old_cksum() {
52-
[ -f $SRCDIR/operator/src/main.cksum ] && cat $SRCDIR/operator/src/main.cksum
51+
[ -f "$SRCDIR/operator/src/main.cksum" ] && cat "$SRCDIR/operator/src/main.cksum"
5352
}
5453

55-
if [ "$(old_cksum)" = "$(latest_cksum)" ]; then
56-
echo "@@ Info: Skipping oper build/tag - cksum unchanged."
54+
# Avoid rebuild if nothing changed
55+
if [ "$(old_cksum 2>/dev/null)" = "$(latest_cksum)" ]; then
56+
echo "@@ Info: Skipping Operator image build - no changes detected."
5757
exit 0
5858
fi
5959

60-
#mvn clean install -DskipTests -Dcheckstyle.skip
61-
mvn clean install
62-
if [ -n "${http_proxy:-}" ]; then
63-
HTTP_BUILD_ARG="--build-arg http_proxy=$http_proxy"
64-
fi
65-
if [ -n "${https_proxy:-}" ]; then
66-
HTTP_BUILD_ARG="$HTTP_BUILD_ARG --build-arg https_proxy=$https_proxy "
67-
fi
68-
if [ -n "${no_proxy:-}" ]; then
69-
HTTP_BUILD_ARG="$HTTP_BUILD_ARG --build-arg no_proxy=$no_proxy"
70-
fi
71-
${WLSIMG_BUILDER:-docker} build ${HTTP_BUILD_ARG:-} -t "$OPER_IMAGE_NAME:$OPER_IMAGE_TAG" --build-arg VERSION=$OPER_JAR_VERSION --no-cache=true .
60+
# Clean up target to avoid file lock issues
61+
echo "@@ Info: Cleaning Maven targets..."
62+
find "$SRCDIR/operator" -name target -type d -exec chmod -R u+w {} \; -exec rm -rf {} +
63+
64+
# Create unique temp local Maven repo to avoid .m2 lock collisions
65+
TEMP_M2_REPO="/tmp/m2repo-$RANDOM"
66+
67+
echo "@@ Info: Running Maven build..."
68+
mvn clean install -Dmaven.repo.local="$TEMP_M2_REPO"
69+
70+
# Handle build args for proxy if set
71+
HTTP_BUILD_ARG=""
72+
[ -n "${http_proxy:-}" ] && HTTP_BUILD_ARG+=" --build-arg http_proxy=$http_proxy"
73+
[ -n "${https_proxy:-}" ] && HTTP_BUILD_ARG+=" --build-arg https_proxy=$https_proxy"
74+
[ -n "${no_proxy:-}" ] && HTTP_BUILD_ARG+=" --build-arg no_proxy=$no_proxy"
75+
76+
77+
${WLSIMG_BUILDER:-docker} build ${HTTP_BUILD_ARG:-} \
78+
-t "${OPER_IMAGE_NAME}:${OPER_IMAGE_TAG}" \
79+
--build-arg VERSION="${OPER_JAR_VERSION}" \
80+
--no-cache=true .
7281

7382
save_cksum
7483

75-
# push to remote repo if cluster is remote
76-
# if [ -z "$REPO_REGISTRY" ] || [ -z "$REPO_USERNAME" ] || [ -z "$REPO_PASSWORD" ]; then
77-
# echo "Provide container registry login details using REPO_REGISTRY, REPO_USERNAME & REPO_PASSWORD env variables to push the Operator image to the repository."
78-
# exit 1
84+
# Optional: push image to remote registry
85+
# Uncomment if needed and set REPO_REGISTRY, REPO_USERNAME, REPO_PASSWORD
86+
# if [[ -n "${REPO_REGISTRY:-}" && -n "${REPO_USERNAME:-}" && -n "${REPO_PASSWORD:-}" ]]; then
87+
# echo "@@ Info: Pushing image to ${REPO_REGISTRY}..."
88+
# ${WLSIMG_BUILDER:-docker} login "$REPO_REGISTRY" -u "$REPO_USERNAME" -p "$REPO_PASSWORD"
89+
# ${WLSIMG_BUILDER:-docker} push "${OPER_IMAGE_NAME}:${OPER_IMAGE_TAG}"
90+
# else
91+
# echo "@@ Warning: Skipping ${WLSIMG_BUILDER:-docker} push. Set REPO_REGISTRY, REPO_USERNAME, and REPO_PASSWORD to enable."
7992
# fi
80-
# ${WLSIMG_BUILDER:-docker} login $REPO_REGISTRY -u $REPO_USERNAME -p $REPO_PASSWORD
81-
# ${WLSIMG_BUILDER:-docker} push ${IMAGE_NAME_OPERATOR}:${IMAGE_TAG_OPERATOR}
93+
94+
echo "@@ Done: Operator image built and tagged successfully."

operator/integration-tests/model-in-image/run-test.sh

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright (c) 2020, 2024, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2025, Oracle and/or its affiliates.
33
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44

55
#
@@ -645,6 +645,10 @@ if [ "$DO_UPDATE4" = "true" ]; then
645645
doCommand "\$WORKDIR/model-in-image/utils/patch-introspect-version.sh -d \$DOMAIN_UID -n \$DOMAIN_NAMESPACE"
646646
waitForDomain Completed
647647

648+
# Ensure pods are Ready before comparing timestamps
649+
echo "@@ Waiting for all pods to be ready in namespace $DOMAIN_NAMESPACE..."
650+
${KUBERNETES_CLI:-kubectl} -n $DOMAIN_NAMESPACE wait --for=condition=Ready pods --all --timeout=300s
651+
648652
if [ ! "$DRY_RUN" = "true" ]; then
649653
if [ "$KIND_CLUSTER" = "true" ]; then
650654
testapp internal cluster-1 v2 "'SampleMinThreads' with configured count: 2" 60 quiet
@@ -662,13 +666,21 @@ if [ "$DO_UPDATE4" = "true" ]; then
662666
fi
663667

664668
podInfoAfter="$(getPodInfo | grep -v introspectVersion)"
665-
if [ "$podInfoBefore" = "$podInfoAfter" ]; then
666-
trace "No roll detected. Good!"
669+
getPodTimestamps() {
670+
echo "$1" | grep -E 'name=|creationTimestamp=' | sed -e 's/^ *//' | paste - - | sed 's/ /\\n/g'
671+
}
672+
673+
beforeTimestamps=$(getPodTimestamps "$podInfoBefore")
674+
afterTimestamps=$(getPodTimestamps "$podInfoAfter")
675+
676+
if [ "$beforeTimestamps" = "$afterTimestamps" ]; then
677+
trace "No roll detected based on pod creation timestamps. Good!"
667678
else
668-
dumpInfo
669-
trace "Info: Pods before:" && echo "${podInfoBefore}"
670-
trace "Info: Pods after:" && echo "${podInfoAfter}"
671-
trace "Error: Unexpected roll detected."
679+
trace "Error: Unexpected roll detected based on creation timestamps."
680+
echo "Before timestamps:"
681+
echo "$beforeTimestamps"
682+
echo "After timestamps:"
683+
echo "$afterTimestamps"
672684
exit 1
673685
fi
674686
fi

0 commit comments

Comments
 (0)