1- // Copyright (c) 2020, 2022, 2023 , Oracle and/or its affiliates.
1+ // Copyright (c) 2020, 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 ;
1010import java .nio .file .Path ;
1111import java .nio .file .Paths ;
1212import java .nio .file .StandardCopyOption ;
13+ import java .util .ArrayList ;
1314import java .util .Arrays ;
1415import java .util .Collections ;
1516import java .util .List ;
1617import java .util .Properties ;
1718
1819import io .kubernetes .client .openapi .models .V1EnvVar ;
20+ import io .kubernetes .client .openapi .models .V1HTTPIngressPath ;
21+ import io .kubernetes .client .openapi .models .V1HTTPIngressRuleValue ;
22+ import io .kubernetes .client .openapi .models .V1IngressBackend ;
23+ import io .kubernetes .client .openapi .models .V1IngressRule ;
24+ import io .kubernetes .client .openapi .models .V1IngressServiceBackend ;
1925import io .kubernetes .client .openapi .models .V1LocalObjectReference ;
2026import io .kubernetes .client .openapi .models .V1ObjectMeta ;
27+ import io .kubernetes .client .openapi .models .V1ServiceBackendPort ;
2128import oracle .weblogic .domain .AdminServer ;
2229import oracle .weblogic .domain .AdminService ;
2330import oracle .weblogic .domain .Channel ;
2633import oracle .weblogic .domain .DomainSpec ;
2734import oracle .weblogic .domain .Model ;
2835import oracle .weblogic .domain .ServerPod ;
36+ import oracle .weblogic .kubernetes .actions .impl .NginxParams ;
37+ import oracle .weblogic .kubernetes .actions .impl .Service ;
2938import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
3039import oracle .weblogic .kubernetes .annotations .Namespaces ;
40+ //import oracle.weblogic.kubernetes.assertions.TestAssertions;
3141import oracle .weblogic .kubernetes .logging .LoggingFacade ;
3242import oracle .weblogic .kubernetes .utils .ExecResult ;
3343import org .junit .jupiter .api .BeforeAll ;
3444import org .junit .jupiter .api .BeforeEach ;
3545import org .junit .jupiter .api .DisplayName ;
3646import org .junit .jupiter .api .Tag ;
3747import org .junit .jupiter .api .Test ;
48+ import org .junit .jupiter .api .condition .DisabledIfEnvironmentVariable ;
3849
3950import static oracle .weblogic .kubernetes .TestConstants .ADMIN_PASSWORD_DEFAULT ;
4051import static oracle .weblogic .kubernetes .TestConstants .ADMIN_USERNAME_DEFAULT ;
4152import static oracle .weblogic .kubernetes .TestConstants .DB_IMAGE_TO_USE_IN_SPEC ;
4253import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_API_VERSION ;
4354import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_VERSION ;
4455import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
56+ import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
57+ import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER ;
4558import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
4659import static oracle .weblogic .kubernetes .TestConstants .TEST_IMAGES_REPO_SECRET_NAME ;
60+ import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_SLIM ;
4761import static oracle .weblogic .kubernetes .actions .ActionConstants .APP_DIR ;
4862import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
4963import static oracle .weblogic .kubernetes .actions .ActionConstants .WORK_DIR ;
5064import static oracle .weblogic .kubernetes .actions .TestActions .createDomainCustomResource ;
5165import static oracle .weblogic .kubernetes .actions .TestActions .getPodIP ;
5266import static oracle .weblogic .kubernetes .actions .TestActions .getServiceNodePort ;
67+ import static oracle .weblogic .kubernetes .actions .TestActions .listIngresses ;
5368import static oracle .weblogic .kubernetes .assertions .TestAssertions .domainExists ;
69+ import static oracle .weblogic .kubernetes .utils .ApplicationUtils .callWebAppAndWaitTillReady ;
5470import static oracle .weblogic .kubernetes .utils .ApplicationUtils .checkAppIsActive ;
5571import static oracle .weblogic .kubernetes .utils .BuildApplication .buildApplication ;
5672import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
73+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .exeAppInServerPod ;
5774import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getHostAndPort ;
5875import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
76+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getServiceExtIPAddrtOke ;
5977import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
6078import static oracle .weblogic .kubernetes .utils .DbUtils .getDBNodePort ;
6179import static oracle .weblogic .kubernetes .utils .DbUtils .startOracleDB ;
6684import static oracle .weblogic .kubernetes .utils .ImageUtils .createImageAndVerify ;
6785import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
6886import static oracle .weblogic .kubernetes .utils .ImageUtils .imageRepoLoginAndPushImageToRegistry ;
87+ import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .createIngressAndRetryIfFail ;
88+ import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .installAndVerifyNginx ;
6989import static oracle .weblogic .kubernetes .utils .OKDUtils .createRouteForOKD ;
7090import static oracle .weblogic .kubernetes .utils .OperatorUtils .installAndVerifyOperator ;
7191import static oracle .weblogic .kubernetes .utils .PodUtils .getExternalServicePodName ;
7292import static oracle .weblogic .kubernetes .utils .PodUtils .setPodAntiAffinity ;
7393import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretWithUsernamePassword ;
7494import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
95+ import static org .assertj .core .api .Assertions .assertThat ;
7596import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
97+ import static org .junit .jupiter .api .Assertions .assertEquals ;
7698import static org .junit .jupiter .api .Assertions .assertNotEquals ;
7799import static org .junit .jupiter .api .Assertions .assertNotNull ;
78100import static org .junit .jupiter .api .Assertions .assertTrue ;
82104 */
83105@ DisplayName ("Verify cross domain transaction is successful" )
84106@ IntegrationTest
85- @ Tag ("oke-parallel " )
107+ @ Tag ("oke-gate " )
86108@ Tag ("kind-parallel" )
87109@ Tag ("okd-wls-srg" )
88110class ItCrossDomainTransaction {
@@ -122,13 +144,17 @@ class ItCrossDomainTransaction {
122144 private static String dbPodIP = null ;
123145 private static int dbPort = 1521 ;
124146
147+ private static String nginxNamespace = null ;
148+ private static NginxParams nginxHelmParams = null ;
149+ private static int nginxNodePort ;
150+
125151 /**
126152 * Install Operator.
127153 * @param namespaces list of namespaces created by the IntegrationTestWatcher by the
128154 * JUnit engine parameter resolution mechanism
129155 */
130156 @ BeforeAll
131- public static void initAll (@ Namespaces (3 ) List <String > namespaces ) {
157+ public static void initAll (@ Namespaces (4 ) List <String > namespaces ) {
132158 logger = getLogger ();
133159
134160 // get a new unique opNamespace
@@ -144,6 +170,11 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
144170 assertNotNull (namespaces .get (2 ), "Namespace list is null" );
145171 domain2Namespace = namespaces .get (2 );
146172
173+ // get a unique Nginx namespace
174+ logger .info ("Assign a unique namespace for Nginx" );
175+ assertNotNull (namespaces .get (3 ), "Namespace list is null" );
176+ nginxNamespace = namespaces .get (3 );
177+
147178 final int dbListenerPort = getNextFreePort ();
148179 ORACLEDBSUFFIX = ".svc.cluster.local:" + dbListenerPort + "/devpdb.k8s" ;
149180 dbUrl = ORACLEDBURLPREFIX + domain2Namespace + ORACLEDBSUFFIX ;
@@ -172,6 +203,13 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
172203
173204 // install and verify operator
174205 installAndVerifyOperator (opNamespace , domain1Namespace , domain2Namespace );
206+
207+ if (OKE_CLUSTER ) {
208+ logger .info ("Installing Nginx controller using helm" );
209+ // install and verify Nginx
210+ nginxHelmParams = installAndVerifyNginx (nginxNamespace , 0 , 0 );
211+ }
212+
175213 buildApplicationsAndDomains ();
176214 }
177215
@@ -359,7 +397,13 @@ private static void buildApplicationsAndDomains() {
359397 "Getting admin server node port failed" );
360398 assertNotEquals (-1 , admin2ServiceNodePort , "admin server default node port is not valid" );
361399
362- hostAndPort = getHostAndPort (domain1AdminExtSvcRouteHost , domain1AdminServiceNodePort );
400+ if (OKE_CLUSTER ) {
401+ createNginxIngressPathRoutingRules ();
402+ String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
403+ hostAndPort = getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace );
404+ } else {
405+ hostAndPort = getHostAndPort (domain1AdminExtSvcRouteHost , domain1AdminServiceNodePort );
406+ }
363407 }
364408
365409 /*
@@ -414,6 +458,7 @@ void testCrossDomainTransaction() {
414458 */
415459 @ Test
416460 @ DisplayName ("Check cross domain transaction with TMAfterTLogBeforeCommitExit property commits" )
461+ @ DisabledIfEnvironmentVariable (named = "OKE_CLUSTER" , matches = "true" )
417462 void testCrossDomainTransactionWithFailInjection () {
418463
419464 String curlRequest = String .format ("curl -g -v --show-error --noproxy '*' "
@@ -499,8 +544,10 @@ private boolean checkLocalQueue() {
499544 return true ;
500545 }
501546
502- private static void createDomain (String domainUid , String domainNamespace , String adminSecretName ,
503- String domainImage ) {
547+ private static void createDomain (String domainUid ,
548+ String domainNamespace ,
549+ String adminSecretName ,
550+ String domainImage ) {
504551 // admin/managed server name here should match with model yaml in WDT_MODEL_FILE
505552 final String adminServerPodName = domainUid + "-admin-server" ;
506553 final String managedServerPrefix = domainUid + "-managed-server" ;
@@ -541,12 +588,41 @@ private static void createDomain(String domainUid, String domainNamespace, Strin
541588 // The fail inject test case, the response to the curl command takes longer than the default timeout of 30s
542589 // So, have to increase the proxy timeout for the route
543590 String command = "oc -n " + domainNamespace + " annotate route "
544- + getExternalServicePodName (adminServerPodName )
545- + " --overwrite haproxy.router.openshift.io/timeout=600s" ;
591+ + getExternalServicePodName (adminServerPodName )
592+ + " --overwrite haproxy.router.openshift.io/timeout=600s" ;
546593 logger .info ("command to set timeout = {0}" , command );
547- assertDoesNotThrow (
548- () -> exec (command , true ));
594+ assertDoesNotThrow (() -> exec (command , true ));
595+
596+ logger .info ("Getting node port" );
597+ int serviceNodePort = assertDoesNotThrow (() -> getServiceNodePort (domainNamespace ,
598+ getExternalServicePodName (adminServerPodName ), "default" ),
599+ "Getting admin server node port failed" );
549600
601+ if (!WEBLOGIC_SLIM ) {
602+ logger .info ("Validating WebLogic admin console" );
603+ String resourcePath = "/console/login/LoginForm.jsp" ;
604+ ExecResult result = exeAppInServerPod (domainNamespace , adminServerPodName ,7001 , resourcePath );
605+ logger .info ("result in OKE_CLUSTER is {0}" , result .toString ());
606+ assertEquals (0 , result .exitValue (), "Failed to access WebLogic console" );
607+
608+ /*
609+ if (OKE_CLUSTER) {
610+ String resourcePath = "/console/login/LoginForm.jsp";
611+ ExecResult result = exeAppInServerPod(domainNamespace, adminServerPodName,7001, resourcePath);
612+ logger.info("result in OKE_CLUSTER is {0}", result.toString());
613+ assertEquals(0, result.exitValue(), "Failed to access WebLogic console");
614+ } else {
615+ testUntil(
616+ assertDoesNotThrow(() -> {
617+ return TestAssertions.adminNodePortAccessible(serviceNodePort,
618+ ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT, adminExtSvcRouteHost);
619+ }, "Access to admin server node port failed"),
620+ logger,
621+ "Console login validation");
622+ }*/
623+ } else {
624+ logger .info ("Skipping WebLogic Console check for Weblogic slim images" );
625+ }
550626 }
551627
552628 private static void createDomainResource (String domainUid , String domNamespace , String adminSecretName ,
@@ -599,4 +675,57 @@ private static void createDomainResource(String domainUid, String domNamespace,
599675 assertTrue (domCreated , String .format ("Create domain custom resource failed with ApiException "
600676 + "for %s in namespace %s" , domainUid , domNamespace ));
601677 }
678+
679+ private static void createNginxIngressPathRoutingRules () {
680+ // create an ingress in domain namespace
681+ final int ADMIN_SERVER_PORT = 7001 ;
682+ String ingressName = domain1Namespace + "-nginx-path-routing" ;
683+ String ingressClassName = nginxHelmParams .getIngressClassName ();
684+
685+ // create ingress rules for two domains
686+ List <V1IngressRule > ingressRules = new ArrayList <>();
687+ List <V1HTTPIngressPath > httpIngressPaths = new ArrayList <>();
688+
689+ V1HTTPIngressPath httpIngressPath = new V1HTTPIngressPath ()
690+ .path ("/" )
691+ .pathType ("Prefix" )
692+ .backend (new V1IngressBackend ()
693+ .service (new V1IngressServiceBackend ()
694+ .name (domainUid1 + "-admin-server" )
695+ .port (new V1ServiceBackendPort ()
696+ .number (ADMIN_SERVER_PORT )))
697+ );
698+ httpIngressPaths .add (httpIngressPath );
699+
700+ V1IngressRule ingressRule = new V1IngressRule ()
701+ .host ("" )
702+ .http (new V1HTTPIngressRuleValue ()
703+ .paths (httpIngressPaths ));
704+
705+ ingressRules .add (ingressRule );
706+
707+ createIngressAndRetryIfFail (60 , false , ingressName , domain1Namespace , null , ingressClassName , ingressRules , null );
708+
709+ // check the ingress was found in the domain namespace
710+ assertThat (assertDoesNotThrow (() -> listIngresses (domain1Namespace )))
711+ .as (String .format ("Test ingress %s was found in namespace %s" , ingressName , domain1Namespace ))
712+ .withFailMessage (String .format ("Ingress %s was not found in namespace %s" , ingressName , domain1Namespace ))
713+ .contains (ingressName );
714+
715+ logger .info ("ingress {0} was created in namespace {1}" , ingressName , domain1Namespace );
716+
717+ // check the ingress is ready to route the app to the server pod
718+ String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
719+ nginxNodePort = assertDoesNotThrow (() -> Service .getServiceNodePort (nginxNamespace , nginxServiceName , "http" ),
720+ "Getting Nginx loadbalancer service node port failed" );
721+
722+ String hostAndPort = getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace ) != null
723+ ? getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace ) : K8S_NODEPORT_HOST + ":" + nginxNodePort ;
724+
725+ String curlCmd = "curl -g --silent --show-error --noproxy '*' http://" + hostAndPort
726+ + "/weblogic/ready --write-out %{http_code} -o /dev/null" ;
727+
728+ logger .info ("Executing curl command {0}" , curlCmd );
729+ assertTrue (callWebAppAndWaitTillReady (curlCmd , 60 ));
730+ }
602731}
0 commit comments