1212import java .util .Arrays ;
1313import java .util .Collections ;
1414import java .util .List ;
15- import java .util .Map ;
1615
1716import io .kubernetes .client .openapi .models .V1EnvVar ;
17+ import io .kubernetes .client .openapi .models .V1HTTPIngressPath ;
18+ import io .kubernetes .client .openapi .models .V1HTTPIngressRuleValue ;
19+ import io .kubernetes .client .openapi .models .V1IngressBackend ;
20+ import io .kubernetes .client .openapi .models .V1IngressRule ;
21+ import io .kubernetes .client .openapi .models .V1IngressServiceBackend ;
1822import io .kubernetes .client .openapi .models .V1LocalObjectReference ;
23+ import io .kubernetes .client .openapi .models .V1ServiceBackendPort ;
1924import oracle .weblogic .domain .AuxiliaryImage ;
2025import oracle .weblogic .domain .Channel ;
2126import oracle .weblogic .domain .ClusterList ;
2227import oracle .weblogic .domain .ClusterSpec ;
2328import oracle .weblogic .domain .DomainResource ;
2429import oracle .weblogic .kubernetes .actions .impl .AppParams ;
2530import oracle .weblogic .kubernetes .actions .impl .Cluster ;
31+ import oracle .weblogic .kubernetes .actions .impl .NginxParams ;
32+ import oracle .weblogic .kubernetes .actions .impl .Service ;
2633import oracle .weblogic .kubernetes .actions .impl .primitive .WitParams ;
2734import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
2835import oracle .weblogic .kubernetes .annotations .Namespaces ;
4249import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
4350import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
4451import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOSTNAME ;
52+ import static oracle .weblogic .kubernetes .TestConstants .KUBERNETES_CLI ;
53+ import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER ;
4554import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
4655import static oracle .weblogic .kubernetes .TestConstants .TRAEFIK_INGRESS_HTTP_HOSTPORT ;
4756import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_IMAGE_TO_USE_IN_SPEC ;
5160import static oracle .weblogic .kubernetes .actions .TestActions .buildAppArchive ;
5261import static oracle .weblogic .kubernetes .actions .TestActions .defaultAppParams ;
5362import static oracle .weblogic .kubernetes .actions .TestActions .getServiceNodePort ;
63+ import static oracle .weblogic .kubernetes .actions .TestActions .listIngresses ;
64+ import static oracle .weblogic .kubernetes .utils .ApplicationUtils .callWebAppAndWaitTillReady ;
5465import static oracle .weblogic .kubernetes .utils .AuxiliaryImageUtils .createAndPushAuxiliaryImage ;
5566import static oracle .weblogic .kubernetes .utils .ClusterUtils .createClusterAndVerify ;
5667import static oracle .weblogic .kubernetes .utils .ClusterUtils .createClusterResource ;
6071import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getDateAndTimeStamp ;
6172import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getHostAndPort ;
6273import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
74+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getServiceExtIPAddrtOke ;
6375import static oracle .weblogic .kubernetes .utils .CommonTestUtils .runClientInsidePod ;
6476import static oracle .weblogic .kubernetes .utils .CommonTestUtils .runJavacInsidePod ;
6577import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
6678import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainAndVerify ;
6779import static oracle .weblogic .kubernetes .utils .FileUtils .copyFileToPod ;
6880import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
81+ import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .createIngressAndRetryIfFail ;
82+ import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .installAndVerifyNginx ;
6983import static oracle .weblogic .kubernetes .utils .OperatorUtils .installAndVerifyOperator ;
84+ import static oracle .weblogic .kubernetes .utils .PodUtils .checkPodReady ;
7085import static oracle .weblogic .kubernetes .utils .PodUtils .getExternalServicePodName ;
7186import static oracle .weblogic .kubernetes .utils .PodUtils .setPodAntiAffinity ;
7287import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretWithUsernamePassword ;
7388import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretsForImageRepos ;
7489import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
90+ import static org .assertj .core .api .Assertions .assertThat ;
7591import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
7692import static org .junit .jupiter .api .Assertions .assertNotEquals ;
7793import static org .junit .jupiter .api .Assertions .assertNotNull ;
8399@ DisplayName ("Verify cross domain transaction is successful with CrossDomainSecurityEnabled set to true" )
84100@ IntegrationTest
85101@ Tag ("kind-parallel" )
102+ @ Tag ("oke-gate" )
86103class ItCrossDomainTransactionSecurity {
87104
88105 private static final String auxImageName1 = DOMAIN_IMAGES_PREFIX + "domain1-cdxaction-aux" ;
@@ -106,7 +123,9 @@ class ItCrossDomainTransactionSecurity {
106123 private static String domain1AdminExtSvcRouteHost = null ;
107124 private static String hostAndPort1 = null ;
108125 private static String hostHeader1 ;
109- private static Map <String , String > headers = null ;
126+ private static String nginxNamespace = null ;
127+ private static NginxParams nginxHelmParams = null ;
128+ private static int nginxNodePort ;
110129
111130
112131
@@ -128,12 +147,24 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
128147 assertNotNull (namespaces .get (1 ), "Namespace list is null" );
129148 domainNamespace = namespaces .get (1 );
130149
150+ // get a unique Nginx namespace
151+ logger .info ("Assign a unique namespace for Nginx" );
152+ assertNotNull (namespaces .get (2 ), "Namespace list is null" );
153+ nginxNamespace = namespaces .get (2 );
154+
131155 // Create the repo secret to pull the image
132156 // this secret is used only for non-kind cluster
133157 createTestRepoSecret (domainNamespace );
134158
135159 // install and verify operator
136160 installAndVerifyOperator (opNamespace , domainNamespace );
161+
162+ if (OKE_CLUSTER ) {
163+ logger .info ("Installing Nginx controller using helm" );
164+ // install and verify Nginx
165+ nginxHelmParams = installAndVerifyNginx (nginxNamespace , 0 , 0 );
166+ }
167+
137168 buildDomains ();
138169
139170 }
@@ -165,13 +196,19 @@ void testCrossDomainTransactionCommitSecurityEnable() throws UnknownHostExceptio
165196 assertNotEquals (-1 , domain1AdminServiceNodePort , "domain2 admin server default node port is not valid" );
166197 logger .info ("domain2AdminServiceNodePort is: " + domain2AdminServiceNodePort );
167198
168- hostAndPort1 = getHostAndPort (domain1AdminExtSvcRouteHost , domain1AdminServiceNodePort );
169- if (TestConstants .KIND_CLUSTER
199+ if (OKE_CLUSTER ) {
200+ createNginxIngressPathRoutingRules ();
201+ String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
202+ hostAndPort1 = getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace );
203+ } else {
204+ hostAndPort1 = getHostAndPort (domain1AdminExtSvcRouteHost , domain1AdminServiceNodePort );
205+ if (TestConstants .KIND_CLUSTER
170206 && !TestConstants .WLSIMG_BUILDER .equals (TestConstants .WLSIMG_BUILDER_DEFAULT )) {
171- hostHeader1 = createIngressHostRouting (domainNamespace , domainUid1 , adminServerName , 7001 );
172- hostAndPort1 = formatIPv6Host (getLocalHost ().getHostAddress ())
207+ hostHeader1 = createIngressHostRouting (domainNamespace , domainUid1 , adminServerName , 7001 );
208+ hostAndPort1 = formatIPv6Host (getLocalHost ().getHostAddress ())
173209 + ":" + TRAEFIK_INGRESS_HTTP_HOSTPORT ;
174210
211+ }
175212 }
176213 logger .info ("hostHeader1 for domain1 is: " + hostHeader1 );
177214 logger .info ("hostAndPort1 for domain1 is: " + hostAndPort1 );
@@ -216,7 +253,7 @@ void testCrossDomainTransactionCommitSecurityEnable() throws UnknownHostExceptio
216253 testUntil (
217254 runClientInsidePod (domain1AdminServerPodName , domainNamespace ,
218255 "/u01" , "JmsSendReceiveClient" ,
219- "t3://" + K8S_NODEPORT_HOST + ":" + t3ChannelPort1 , "receive" , "jms.admin.adminQueue" , "1" ),
256+ "t3://" + "localhost" + ":" + "7001" , "receive" , "jms.admin.adminQueue" , "1" ),
220257 logger ,
221258 "Wait for JMS Client to send/recv msg" );
222259
@@ -252,7 +289,7 @@ void testCrossDomainTransactionCommitSecurityEnable() throws UnknownHostExceptio
252289 testUntil (
253290 runClientInsidePod (domain1AdminServerPodName , domainNamespace ,
254291 "/u01" , "JmsSendReceiveClient" ,
255- "t3://" + K8S_NODEPORT_HOST + ":" + t3ChannelPort1 , "receive" , "jms.admin.adminQueue" , "0" ),
292+ "t3://" + "localhost" + ":" + "7001" , "receive" , "jms.admin.adminQueue" , "0" ),
256293 logger ,
257294 "Wait for JMS Client to send/recv msg" );
258295 }
@@ -524,5 +561,74 @@ private String getCurlResult(String curlCmd) {
524561 return result .stdout ();
525562 }
526563
564+ private static void createNginxIngressPathRoutingRules () {
565+ // create an ingress in domain namespace
566+ final int ADMIN_SERVER_PORT = 7001 ;
567+ String ingressName = domainNamespace + "-nginx-path-routing" ;
568+ String ingressClassName = nginxHelmParams .getIngressClassName ();
569+
570+ // create ingress rules for two domains
571+ List <V1IngressRule > ingressRules = new ArrayList <>();
572+ List <V1HTTPIngressPath > httpIngressPaths = new ArrayList <>();
573+
574+ V1HTTPIngressPath httpIngressPath = new V1HTTPIngressPath ()
575+ .path ("/" )
576+ .pathType ("Prefix" )
577+ .backend (new V1IngressBackend ()
578+ .service (new V1IngressServiceBackend ()
579+ .name (domainUid1 + "-admin-server" )
580+ .port (new V1ServiceBackendPort ()
581+ .number (ADMIN_SERVER_PORT )))
582+ );
583+ httpIngressPaths .add (httpIngressPath );
584+
585+ V1IngressRule ingressRule = new V1IngressRule ()
586+ .host ("" )
587+ .http (new V1HTTPIngressRuleValue ()
588+ .paths (httpIngressPaths ));
589+
590+ ingressRules .add (ingressRule );
591+
592+ createIngressAndRetryIfFail (60 , false , ingressName , domainNamespace , null , ingressClassName , ingressRules , null );
593+
594+ // check the ingress was found in the domain namespace
595+ assertThat (assertDoesNotThrow (() -> listIngresses (domainNamespace )))
596+ .as (String .format ("Test ingress %s was found in namespace %s" , ingressName , domainNamespace ))
597+ .withFailMessage (String .format ("Ingress %s was not found in namespace %s" , ingressName , domainNamespace ))
598+ .contains (ingressName );
599+
600+ logger .info ("ingress {0} was created in namespace {1}" , ingressName , domainNamespace );
601+
602+ // check the ingress is ready to route the app to the server pod
603+ String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
604+ nginxNodePort = assertDoesNotThrow (() -> Service .getServiceNodePort (nginxNamespace , nginxServiceName , "http" ),
605+ "Getting Nginx loadbalancer service node port failed" );
606+
607+ String hostAndPort = getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace ) != null
608+ ? getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace ) : K8S_NODEPORT_HOST + ":" + nginxNodePort ;
609+
610+ String curlCmd = "curl -g --silent --show-error --noproxy '*' http://" + hostAndPort
611+ + "/weblogic/ready --write-out %{http_code} -o /dev/null" ;
612+ if (OKE_CLUSTER ) {
613+ try {
614+ if (!callWebAppAndWaitTillReady (curlCmd , 60 )) {
615+ ExecResult result = ExecCommand .exec (KUBERNETES_CLI + " get all -A" );
616+ logger .info (result .stdout ());
617+ //restart core-dns service
618+ result = ExecCommand .exec (KUBERNETES_CLI + " rollout restart deployment coredns -n kube-system" );
619+ logger .info (result .stdout ());
620+ checkPodReady ("core-dns" , null , "kube-system" );
621+ result = ExecCommand .exec (curlCmd );
622+ logger .info (result .stdout ());
623+ }
624+ } catch (Exception ex ) {
625+ logger .warning (ex .getLocalizedMessage ());
626+ }
627+ }
628+
629+ logger .info ("Executing curl command {0}" , curlCmd );
630+ assertTrue (callWebAppAndWaitTillReady (curlCmd , 60 ));
631+ }
632+
527633}
528634
0 commit comments