1
- // Copyright (c) 2022, 2023 , Oracle and/or its affiliates.
1
+ // Copyright (c) 2022, 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 ;
5
5
6
+ import java .nio .file .Files ;
6
7
import java .nio .file .Path ;
7
8
import java .util .ArrayList ;
8
9
import java .util .Collections ;
9
10
import java .util .HashMap ;
10
11
import java .util .List ;
11
12
import java .util .Map ;
13
+ import java .util .Optional ;
12
14
13
15
import io .kubernetes .client .openapi .models .V1EnvVar ;
14
16
import io .kubernetes .client .openapi .models .V1LocalObjectReference ;
41
43
import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_API_VERSION ;
42
44
import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_VERSION ;
43
45
import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
46
+ import static oracle .weblogic .kubernetes .TestConstants .INGRESS_CLASS_FILE_NAME ;
44
47
import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
45
48
import static oracle .weblogic .kubernetes .TestConstants .MANAGED_SERVER_NAME_BASE ;
46
49
import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_APP_NAME ;
47
50
import static oracle .weblogic .kubernetes .TestConstants .OKD ;
51
+ import static oracle .weblogic .kubernetes .TestConstants .OPERATOR_EXTERNAL_REST_HTTPSPORT ;
48
52
import static oracle .weblogic .kubernetes .TestConstants .TEST_IMAGES_REPO_SECRET_NAME ;
53
+ import static oracle .weblogic .kubernetes .TestConstants .TRAEFIK_INGRESS_HTTP_HOSTPORT ;
49
54
import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_IMAGE_NAME ;
50
55
import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_IMAGE_TAG ;
51
56
import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_SLIM ;
57
+ import static oracle .weblogic .kubernetes .TestConstants .WLSIMG_BUILDER ;
58
+ import static oracle .weblogic .kubernetes .TestConstants .WLSIMG_BUILDER_DEFAULT ;
52
59
import static oracle .weblogic .kubernetes .TestConstants .WLS_DOMAIN_TYPE ;
53
60
import static oracle .weblogic .kubernetes .actions .ActionConstants .ARCHIVE_DIR ;
54
61
import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
57
64
import static oracle .weblogic .kubernetes .actions .TestActions .getDomainCustomResource ;
58
65
import static oracle .weblogic .kubernetes .actions .TestActions .getServiceNodePort ;
59
66
import static oracle .weblogic .kubernetes .actions .TestActions .getServicePort ;
67
+ import static oracle .weblogic .kubernetes .actions .TestActions .listIngresses ;
60
68
import static oracle .weblogic .kubernetes .actions .TestActions .startDomain ;
61
69
import static oracle .weblogic .kubernetes .assertions .TestAssertions .adminNodePortAccessible ;
62
70
import static oracle .weblogic .kubernetes .assertions .TestAssertions .doesDomainExist ;
63
71
import static oracle .weblogic .kubernetes .utils .ApplicationUtils .callWebAppAndWaitTillReady ;
64
72
import static oracle .weblogic .kubernetes .utils .ApplicationUtils .verifyAdminConsoleAccessible ;
73
+ import static oracle .weblogic .kubernetes .utils .ApplicationUtils .verifyAdminServerRESTAccess ;
65
74
import static oracle .weblogic .kubernetes .utils .ClusterUtils .createClusterResourceAndAddReferenceToDomain ;
66
75
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
76
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .createIngressHostRouting ;
77
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getHostAndPort ;
67
78
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
68
79
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .scaleAndVerifyCluster ;
69
80
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .startPortForwardProcess ;
@@ -111,6 +122,7 @@ class ItMultiDomainModelsScale {
111
122
112
123
// domain constants
113
124
private static final int NUMBER_OF_CLUSTERS_MIIDOMAIN = 2 ;
125
+ private static final String adminServerName = "admin-server" ;
114
126
private static final String CLUSTER_NAME_PREFIX = "cluster-" ;
115
127
private static final int MANAGED_SERVER_PORT = 8001 ;
116
128
private static final int ADMIN_SERVER_PORT = 7001 ;
@@ -131,14 +143,14 @@ class ItMultiDomainModelsScale {
131
143
private static String opServiceAccount = null ;
132
144
private static NginxParams nginxHelmParams = null ;
133
145
private static int nodeportshttp = 0 ;
134
- private static int externalRestHttpsPort = 0 ;
135
146
private static LoggingFacade logger = null ;
136
147
private static String miiDomainNamespace = null ;
137
148
private static String domainInImageNamespace = null ;
138
149
private static String domainOnPVNamespace = null ;
139
150
private static String miiImage = null ;
140
151
private static String encryptionSecretName = "encryptionsecret" ;
141
152
private String curlCmd = null ;
153
+ private static String hostHeader = null ;
142
154
143
155
/**
144
156
* Install operator and NGINX.
@@ -178,11 +190,9 @@ public static void initAll(@Namespaces(5) List<String> namespaces) {
178
190
miiImage = createAndPushMiiImage ();
179
191
180
192
// install and verify operator with REST API
181
- installAndVerifyOperator (opNamespace , opServiceAccount , true , 0 ,
193
+ installAndVerifyOperator (opNamespace , opServiceAccount , true , OPERATOR_EXTERNAL_REST_HTTPSPORT ,
182
194
miiDomainNamespace , domainOnPVNamespace , domainInImageNamespace );
183
195
184
- externalRestHttpsPort = getServiceNodePort (opNamespace , "external-weblogic-operator-svc" );
185
-
186
196
// This test uses the operator restAPI to scale the domain. To do this in OKD cluster,
187
197
// we need to expose the external service as route and set tls termination to passthrough
188
198
logger .info ("Create a route for the operator external service - only for OKD" );
@@ -192,12 +202,17 @@ public static void initAll(@Namespaces(5) List<String> namespaces) {
192
202
setTlsTerminationForRoute ("external-weblogic-operator-svc" , opNamespace );
193
203
194
204
if (!OKD ) {
195
- // install and verify NGINX
196
- nginxHelmParams = installAndVerifyNginx (nginxNamespace , 0 , 0 );
197
- String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
198
- logger .info ("NGINX service name: {0}" , nginxServiceName );
199
- nodeportshttp = getServiceNodePort (nginxNamespace , nginxServiceName , "http" );
200
- logger .info ("NGINX http node port: {0}" , nodeportshttp );
205
+ if (WLSIMG_BUILDER .equals (WLSIMG_BUILDER_DEFAULT )) {
206
+ // install and verify NGINX
207
+ nginxHelmParams = installAndVerifyNginx (nginxNamespace , 0 , 0 );
208
+ String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
209
+ logger .info ("NGINX service name: {0}" , nginxServiceName );
210
+ nodeportshttp = getServiceNodePort (nginxNamespace , nginxServiceName , "http" );
211
+ logger .info ("NGINX http node port: {0}" , nodeportshttp );
212
+ } else {
213
+ // if not using docker, use pre-installed Traefik controller
214
+ nodeportshttp = TRAEFIK_INGRESS_HTTP_HOSTPORT ;
215
+ }
201
216
}
202
217
}
203
218
@@ -247,11 +262,16 @@ void testScaleClustersByPatchingClusterResource(String domainType) {
247
262
numberOfServers , replicaCount , curlCmd , managedServersBeforeScale );
248
263
}
249
264
250
- // verify admin console login using admin node port
251
- verifyAdminConsoleLoginUsingAdminNodePort (domainUid , domainNamespace );
252
-
253
- // verify admin console login using ingress controller
254
- verifyAdminConsoleLoginUsingIngressController (domainUid , domainNamespace );
265
+ // verify admin console login
266
+ if (!WLSIMG_BUILDER .equals (TestConstants .WLSIMG_BUILDER_DEFAULT )) {
267
+ hostHeader = createIngressHostRoutingIfNotExists (domainNamespace , domainUid );
268
+ assertDoesNotThrow (()
269
+ -> verifyAdminServerRESTAccess ("localhost" , TRAEFIK_INGRESS_HTTP_HOSTPORT , false , hostHeader ));
270
+ } else {
271
+ verifyAdminConsoleLoginUsingAdminNodePort (domainUid , domainNamespace );
272
+ // verify admin console login using ingress controller
273
+ verifyAdminConsoleLoginUsingIngressController (domainUid , domainNamespace );
274
+ }
255
275
256
276
final String hostName = "localhost" ;
257
277
String forwardedPortNo = startPortForwardProcess (hostName , domainNamespace , domainUid , ADMIN_SERVER_PORT );
@@ -293,22 +313,27 @@ void testScaleClustersWithRestApi(String domainType) {
293
313
curlCmd = generateCurlCmd (domainUid , domainNamespace , clusterName , SAMPLE_APP_CONTEXT_ROOT );
294
314
List <String > managedServersBeforeScale = listManagedServersBeforeScale (numClusters , clusterName , replicaCount );
295
315
scaleAndVerifyCluster (clusterName , domainUid , domainNamespace , managedServerPodNamePrefix ,
296
- replicaCount , numberOfServers , true , externalRestHttpsPort , opNamespace , opServiceAccount ,
316
+ replicaCount , numberOfServers , true , OPERATOR_EXTERNAL_REST_HTTPSPORT , opNamespace , opServiceAccount ,
297
317
false , "" , "" , 0 , "" , "" , curlCmd , managedServersBeforeScale );
298
318
299
319
// then scale cluster back to 2 servers
300
320
logger .info ("Scaling cluster {0} of domain {1} in namespace {2} from {3} servers to {4} servers." ,
301
321
clusterName , domainUid , domainNamespace , numberOfServers , replicaCount );
302
322
managedServersBeforeScale = listManagedServersBeforeScale (numClusters , clusterName , numberOfServers );
303
323
scaleAndVerifyCluster (clusterName , domainUid , domainNamespace , managedServerPodNamePrefix ,
304
- numberOfServers , replicaCount , true , externalRestHttpsPort , opNamespace , opServiceAccount ,
324
+ numberOfServers , replicaCount , true , OPERATOR_EXTERNAL_REST_HTTPSPORT , opNamespace , opServiceAccount ,
305
325
false , "" , "" , 0 , "" , "" , curlCmd , managedServersBeforeScale );
306
326
307
- // verify admin console login using admin node port
308
- verifyAdminConsoleLoginUsingAdminNodePort (domainUid , domainNamespace );
309
-
310
- // verify admin console login using ingress controller
311
- verifyAdminConsoleLoginUsingIngressController (domainUid , domainNamespace );
327
+ // verify admin console login
328
+ if (!WLSIMG_BUILDER .equals (TestConstants .WLSIMG_BUILDER_DEFAULT )) {
329
+ hostHeader = createIngressHostRoutingIfNotExists (domainNamespace , domainUid );
330
+ assertDoesNotThrow (()
331
+ -> verifyAdminServerRESTAccess ("localhost" , TRAEFIK_INGRESS_HTTP_HOSTPORT , false , hostHeader ));
332
+ } else {
333
+ verifyAdminConsoleLoginUsingAdminNodePort (domainUid , domainNamespace );
334
+ // verify admin console login using ingress controller
335
+ verifyAdminConsoleLoginUsingIngressController (domainUid , domainNamespace );
336
+ }
312
337
313
338
// shutdown domain and verify the domain is shutdown
314
339
shutdownDomainAndVerify (domainNamespace , domainUid , replicaCount );
@@ -349,7 +374,7 @@ void testScaleClustersWithWLDF(String domainType) {
349
374
logger .info ("BR: curlCmdForWLDFScript = {0}" , curlCmdForWLDFScript );
350
375
351
376
scaleAndVerifyCluster (clusterName , domainUid , domainNamespace , managedServerPodNamePrefix ,
352
- replicaCount , replicaCount + 1 , false , 0 , opNamespace , opServiceAccount ,
377
+ replicaCount , replicaCount + 1 , false , OPERATOR_EXTERNAL_REST_HTTPSPORT , opNamespace , opServiceAccount ,
353
378
true , domainHome , "scaleUp" , 1 ,
354
379
WLDF_OPENSESSION_APP , curlCmdForWLDFScript , curlCmd , managedServersBeforeScale );
355
380
@@ -363,11 +388,16 @@ void testScaleClustersWithWLDF(String domainType) {
363
388
true , domainHome , "scaleDown" , 1 ,
364
389
WLDF_OPENSESSION_APP , curlCmdForWLDFScript , curlCmd , managedServersBeforeScale );
365
390
366
- // verify admin console login using admin node port
367
- verifyAdminConsoleLoginUsingAdminNodePort (domainUid , domainNamespace );
368
-
369
- // verify admin console login using ingress controller
370
- verifyAdminConsoleLoginUsingIngressController (domainUid , domainNamespace );
391
+ // verify admin console login
392
+ if (!WLSIMG_BUILDER .equals (TestConstants .WLSIMG_BUILDER_DEFAULT )) {
393
+ hostHeader = createIngressHostRoutingIfNotExists (domainNamespace , domainUid );
394
+ assertDoesNotThrow (()
395
+ -> verifyAdminServerRESTAccess ("localhost" , TRAEFIK_INGRESS_HTTP_HOSTPORT , false , hostHeader ));
396
+ } else {
397
+ verifyAdminConsoleLoginUsingAdminNodePort (domainUid , domainNamespace );
398
+ // verify admin console login using ingress controller
399
+ verifyAdminConsoleLoginUsingIngressController (domainUid , domainNamespace );
400
+ }
371
401
372
402
// shutdown domain and verify the domain is shutdown
373
403
shutdownDomainAndVerify (domainNamespace , domainUid , replicaCount );
@@ -560,9 +590,9 @@ private static String generateCurlCmd(String domainUid, String domainNamespace,
560
590
if (host .contains (":" )) {
561
591
host = "[" + host + "]" ;
562
592
}
563
- return String .format ("curl -g -v --show-error --noproxy '*' -H 'host: %s' http://%s:%s /%s/index.jsp" ,
593
+ return String .format ("curl -g -v --show-error --noproxy '*' -H 'host: %s' http://%s/%s/index.jsp" ,
564
594
domainUid + "." + domainNamespace + "." + clusterName + ".test" ,
565
- host , nodeportshttp , appContextRoot );
595
+ getHostAndPort ( host , nodeportshttp ) , appContextRoot );
566
596
}
567
597
}
568
598
@@ -712,8 +742,14 @@ private static void createRouteForOKDOrIngressForDomain(DomainResource domain) {
712
742
713
743
if (!OKD ) {
714
744
logger .info ("Creating ingress for domain {0} in namespace {1}" , domainUid , domainNamespace );
715
- createIngressForDomainAndVerify (domainUid , domainNamespace , nodeportshttp , clusterNameMsPortMap ,
716
- true , nginxHelmParams .getIngressClassName (), true , ADMIN_SERVER_PORT );
745
+ if (WLSIMG_BUILDER .equals (WLSIMG_BUILDER_DEFAULT )) {
746
+ createIngressForDomainAndVerify (domainUid , domainNamespace , nodeportshttp , clusterNameMsPortMap ,
747
+ true , nginxHelmParams .getIngressClassName (), true , ADMIN_SERVER_PORT );
748
+ } else {
749
+ assertDoesNotThrow (()
750
+ -> createIngressForDomainAndVerify (domainUid , domainNamespace , TRAEFIK_INGRESS_HTTP_HOSTPORT ,
751
+ clusterNameMsPortMap , true , Files .readString (INGRESS_CLASS_FILE_NAME ), true , ADMIN_SERVER_PORT ));
752
+ }
717
753
}
718
754
}
719
755
@@ -810,4 +846,19 @@ private void verifyAdminConsoleLoginUsingIngressController(String domainUid, Str
810
846
}
811
847
}
812
848
849
+ private String createIngressHostRoutingIfNotExists (String domainNamespace ,
850
+ String domainUid ) {
851
+ String ingressName = domainNamespace + "-" + domainUid + "-" + adminServerName ;
852
+ String hostHeader = "" ;
853
+ try {
854
+ List <String > ingresses = listIngresses (domainNamespace );
855
+ Optional <String > ingressFound = ingresses .stream ().filter (ingress -> ingress .equals (ingressName )).findAny ();
856
+ if (ingressFound .isEmpty ()) {
857
+ hostHeader = createIngressHostRouting (domainNamespace , domainUid , adminServerName , 7001 );
858
+ }
859
+ } catch (Exception ex ) {
860
+ logger .severe (ex .getMessage ());
861
+ }
862
+ return hostHeader ;
863
+ }
813
864
}
0 commit comments