1- // Copyright (c) 2023, 2025 , Oracle and/or its affiliates.
1+ // Copyright (c) 2023, 2024 , 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
44package oracle .weblogic .kubernetes ;
3131import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
3232import static oracle .weblogic .kubernetes .TestConstants .KIND_CLUSTER ;
3333import static oracle .weblogic .kubernetes .TestConstants .KIND_REPO ;
34+ import static oracle .weblogic .kubernetes .TestConstants .KUBERNETES_CLI ;
3435import static oracle .weblogic .kubernetes .TestConstants .OKD ;
3536import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
3637import static oracle .weblogic .kubernetes .TestConstants .TEST_IMAGES_REPO_SECRET_NAME ;
@@ -85,9 +86,8 @@ class ItWlsMiiSample {
8586 * JUnit engine parameter resolution mechanism
8687 */
8788 @ BeforeAll
88- static void initAll (@ Namespaces (3 ) List <String > namespaces ) {
89+ 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 @@ 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 @@ 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 );
@@ -173,7 +161,7 @@ static void initAll(@Namespaces(3) List<String> namespaces) {
173161 */
174162 @ Test
175163 @ Order (1 )
176- void testInstallOperator () {
164+ public void testInstallOperator () {
177165 execTestScriptAndAssertSuccess ("-oper" , "Failed to run -oper" );
178166 }
179167
@@ -182,7 +170,7 @@ void testInstallOperator() {
182170 */
183171 @ Test
184172 @ Order (2 )
185- void testInstallTraefik () {
173+ public void testInstallTraefik () {
186174 if (KIND_CLUSTER && !WLSIMG_BUILDER .equals (WLSIMG_BUILDER_DEFAULT )) {
187175 logger .info ("skip installing Traefik in KIND and podman environment" );
188176 logger .info ("Traefik is already installed in InitialTask in namespace %s" , TRAEFIK_NAMESPACE );
@@ -196,7 +184,7 @@ void testInstallTraefik() {
196184 */
197185 @ Test
198186 @ Order (3 )
199- void testInitialImage () {
187+ public void testInitialImage () {
200188 imagePull (BUSYBOX_IMAGE + ":" + BUSYBOX_TAG );
201189 imageTag (BUSYBOX_IMAGE + ":" + BUSYBOX_TAG , "busybox" );
202190 execTestScriptAndAssertSuccess ("-initial-image" , "Failed to run -initial-image" );
@@ -214,7 +202,7 @@ void testInitialImage() {
214202 */
215203 @ Test
216204 @ Order (4 )
217- void testInitialMain () {
205+ public void testInitialMain () {
218206 // load the base image to kind if using kind cluster
219207 if (KIND_REPO != null ) {
220208 logger .info ("loading image {0} to kind" , WEBLOGIC_IMAGE_TO_USE_IN_SPEC );
@@ -229,7 +217,7 @@ void testInitialMain() {
229217 */
230218 @ Test
231219 @ Order (5 )
232- void testUpate1 () {
220+ public void testUpate1 () {
233221 execTestScriptAndAssertSuccess ("-update1" , "Failed to run -update1" );
234222 }
235223
@@ -238,7 +226,7 @@ void testUpate1() {
238226 */
239227 @ Test
240228 @ Order (6 )
241- void testUpate2 () {
229+ public void testUpate2 () {
242230 execTestScriptAndAssertSuccess ("-update2" , "Failed to run -update2" );
243231 }
244232
@@ -247,7 +235,7 @@ void testUpate2() {
247235 */
248236 @ Test
249237 @ Order (7 )
250- void testUpate3 () {
238+ public void testUpate3 () {
251239 execTestScriptAndAssertSuccess ("-update3-image" , "Failed to run -update3-image" );
252240
253241 // load the image to kind if using kind cluster
@@ -265,7 +253,7 @@ void testUpate3() {
265253 */
266254 @ Test
267255 @ Order (8 )
268- void testUpate4 () {
256+ public void testUpate4 () {
269257 execTestScriptAndAssertSuccess ("-update4" , "Failed to run -update4" );
270258 }
271259
@@ -274,44 +262,68 @@ 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 */
313325 @ AfterAll
314- static void tearDownAll () {
326+ public static void tearDownAll () {
315327 logger = getLogger ();
316328 // uninstall traefik
317329 if (traefikNamespace != null ) {
0 commit comments