1
- // Copyright (c) 2023, 2025 , Oracle and/or its affiliates.
1
+ // Copyright (c) 2023, 2024 , Oracle and/or its affiliates.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3
3
4
4
package oracle .weblogic .kubernetes ;
31
31
import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
32
32
import static oracle .weblogic .kubernetes .TestConstants .KIND_CLUSTER ;
33
33
import static oracle .weblogic .kubernetes .TestConstants .KIND_REPO ;
34
+ import static oracle .weblogic .kubernetes .TestConstants .KUBERNETES_CLI ;
34
35
import static oracle .weblogic .kubernetes .TestConstants .OKD ;
35
36
import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
36
37
import static oracle .weblogic .kubernetes .TestConstants .TEST_IMAGES_REPO_SECRET_NAME ;
@@ -85,9 +86,8 @@ class ItWlsMiiSample {
85
86
* JUnit engine parameter resolution mechanism
86
87
*/
87
88
@ BeforeAll
88
- static void initAll (@ Namespaces (3 ) List <String > namespaces ) {
89
+ public static void initAll (@ Namespaces (3 ) List <String > namespaces ) {
89
90
logger = getLogger ();
90
-
91
91
// get a new unique opNamespace
92
92
logger .info ("Creating unique namespace for Operator" );
93
93
assertNotNull (namespaces .get (0 ), "Namespace list is null" );
@@ -101,42 +101,37 @@ static void initAll(@Namespaces(3) List<String> namespaces) {
101
101
assertNotNull (namespaces .get (2 ), "Namespace list is null" );
102
102
traefikNamespace = namespaces .get (2 );
103
103
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" ;
106
105
107
- // env variables to override default values in sample scripts
108
106
envMap = new HashMap <>();
109
107
envMap .put ("OPER_NAMESPACE" , opNamespace );
110
108
envMap .put ("DOMAIN_NAMESPACE" , domainNamespace );
111
109
envMap .put ("DOMAIN_UID1" , getUniqueName ("sample-domain1-" ));
112
110
envMap .put ("DOMAIN_UID2" , getUniqueName ("sample-domain2-" ));
113
111
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
116
114
envMap .put ("TRAEFIK_NAME" , TRAEFIK_RELEASE_NAME + "-" + traefikNamespace .substring (3 ));
117
115
envMap .put ("TRAEFIK_IMAGE_REGISTRY" , TRAEFIK_INGRESS_IMAGE_REGISTRY );
118
116
envMap .put ("TRAEFIK_IMAGE_REPOSITORY" , TRAEFIK_INGRESS_IMAGE_NAME );
119
117
envMap .put ("TRAEFIK_IMAGE_TAG" , TRAEFIK_INGRESS_IMAGE_TAG );
120
118
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 (":" )));
123
121
envMap .put ("BASE_IMAGE_TAG" , WEBLOGIC_IMAGE_TAG );
124
122
envMap .put ("IMAGE_PULL_SECRET_NAME" , BASE_IMAGES_REPO_SECRET_NAME );
125
123
envMap .put ("DOMAIN_IMAGE_PULL_SECRET_NAME" , TEST_IMAGES_REPO_SECRET_NAME );
126
124
envMap .put ("WLSIMG_BUILDER_DEFAULT" , WLSIMG_BUILDER_DEFAULT );
127
125
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 ) );
130
128
131
- // kind cluster uses openjdk which is not supported by image tool
132
129
if (WIT_JAVA_HOME != null ) {
133
130
envMap .put ("JAVA_HOME" , WIT_JAVA_HOME );
134
131
}
135
-
136
132
if (WIT_DOWNLOAD_URL != null ) {
137
133
envMap .put ("WIT_INSTALLER_URL" , WIT_DOWNLOAD_URL );
138
134
}
139
-
140
135
if (WDT_DOWNLOAD_URL != null ) {
141
136
envMap .put ("WDT_INSTALLER_URL" , WDT_DOWNLOAD_URL );
142
137
}
@@ -146,23 +141,16 @@ static void initAll(@Namespaces(3) List<String> namespaces) {
146
141
envMap .put ("OPER_IMAGE_NAME" , "localhost/weblogic-kubernetes-operator" );
147
142
envMap .put ("MODEL_IMAGE_NAME" , DOMAIN_CREATION_IMAGE_NAME );
148
143
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 ));
151
145
} else {
152
- envMap .put ("TRAEFIK_NAMESPACE" , traefikNamespace );
153
146
envMap .put ("K8S_NODEPORT_HOST" , K8S_NODEPORT_HOST );
154
147
}
155
-
148
+
156
149
logger .info ("Environment variables to the script {0}" , envMap );
157
150
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
161
151
createTestRepoSecret (domainNamespace );
162
152
logger .info ("Registry secret {0} created for domain image successfully in namespace {1}" ,
163
153
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
166
154
createBaseRepoSecret (domainNamespace );
167
155
logger .info ("Registry secret {0} for base image created successfully in namespace {1}" ,
168
156
BASE_IMAGES_REPO_SECRET_NAME , domainNamespace );
@@ -173,7 +161,7 @@ static void initAll(@Namespaces(3) List<String> namespaces) {
173
161
*/
174
162
@ Test
175
163
@ Order (1 )
176
- void testInstallOperator () {
164
+ public void testInstallOperator () {
177
165
execTestScriptAndAssertSuccess ("-oper" , "Failed to run -oper" );
178
166
}
179
167
@@ -182,7 +170,7 @@ void testInstallOperator() {
182
170
*/
183
171
@ Test
184
172
@ Order (2 )
185
- void testInstallTraefik () {
173
+ public void testInstallTraefik () {
186
174
if (KIND_CLUSTER && !WLSIMG_BUILDER .equals (WLSIMG_BUILDER_DEFAULT )) {
187
175
logger .info ("skip installing Traefik in KIND and podman environment" );
188
176
logger .info ("Traefik is already installed in InitialTask in namespace %s" , TRAEFIK_NAMESPACE );
@@ -196,7 +184,7 @@ void testInstallTraefik() {
196
184
*/
197
185
@ Test
198
186
@ Order (3 )
199
- void testInitialImage () {
187
+ public void testInitialImage () {
200
188
imagePull (BUSYBOX_IMAGE + ":" + BUSYBOX_TAG );
201
189
imageTag (BUSYBOX_IMAGE + ":" + BUSYBOX_TAG , "busybox" );
202
190
execTestScriptAndAssertSuccess ("-initial-image" , "Failed to run -initial-image" );
@@ -214,7 +202,7 @@ void testInitialImage() {
214
202
*/
215
203
@ Test
216
204
@ Order (4 )
217
- void testInitialMain () {
205
+ public void testInitialMain () {
218
206
// load the base image to kind if using kind cluster
219
207
if (KIND_REPO != null ) {
220
208
logger .info ("loading image {0} to kind" , WEBLOGIC_IMAGE_TO_USE_IN_SPEC );
@@ -229,7 +217,7 @@ void testInitialMain() {
229
217
*/
230
218
@ Test
231
219
@ Order (5 )
232
- void testUpate1 () {
220
+ public void testUpate1 () {
233
221
execTestScriptAndAssertSuccess ("-update1" , "Failed to run -update1" );
234
222
}
235
223
@@ -238,7 +226,7 @@ void testUpate1() {
238
226
*/
239
227
@ Test
240
228
@ Order (6 )
241
- void testUpate2 () {
229
+ public void testUpate2 () {
242
230
execTestScriptAndAssertSuccess ("-update2" , "Failed to run -update2" );
243
231
}
244
232
@@ -247,7 +235,7 @@ void testUpate2() {
247
235
*/
248
236
@ Test
249
237
@ Order (7 )
250
- void testUpate3 () {
238
+ public void testUpate3 () {
251
239
execTestScriptAndAssertSuccess ("-update3-image" , "Failed to run -update3-image" );
252
240
253
241
// load the image to kind if using kind cluster
@@ -265,7 +253,7 @@ void testUpate3() {
265
253
*/
266
254
@ Test
267
255
@ Order (8 )
268
- void testUpate4 () {
256
+ public void testUpate4 () {
269
257
execTestScriptAndAssertSuccess ("-update4" , "Failed to run -update4" );
270
258
}
271
259
@@ -274,44 +262,68 @@ void testUpate4() {
274
262
* @param arg arguments to execute script
275
263
* @param errString a string of detailed error
276
264
*/
277
- private void execTestScriptAndAssertSuccess (String arg ,
278
- String errString ) {
279
-
265
+ private void execTestScriptAndAssertSuccess (String arg , String errString ) {
280
266
Assumptions .assumeTrue (previousTestSuccessful );
281
267
previousTestSuccessful = false ;
282
268
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
+ }
293
273
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
+ }
299
294
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 " ;
304
298
305
299
assertTrue (success , outStr );
306
-
307
300
previousTestSuccessful = true ;
308
301
}
309
302
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
+
310
322
/**
311
323
* Uninstall Traefik.
312
324
*/
313
325
@ AfterAll
314
- static void tearDownAll () {
326
+ public static void tearDownAll () {
315
327
logger = getLogger ();
316
328
// uninstall traefik
317
329
if (traefikNamespace != null ) {
0 commit comments