12
12
import java .util .Arrays ;
13
13
import java .util .Collections ;
14
14
import java .util .List ;
15
- import java .util .Map ;
16
15
17
16
import 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 ;
18
22
import io .kubernetes .client .openapi .models .V1LocalObjectReference ;
23
+ import io .kubernetes .client .openapi .models .V1ServiceBackendPort ;
19
24
import oracle .weblogic .domain .AuxiliaryImage ;
20
25
import oracle .weblogic .domain .Channel ;
21
26
import oracle .weblogic .domain .ClusterList ;
22
27
import oracle .weblogic .domain .ClusterSpec ;
23
28
import oracle .weblogic .domain .DomainResource ;
24
29
import oracle .weblogic .kubernetes .actions .impl .AppParams ;
25
30
import oracle .weblogic .kubernetes .actions .impl .Cluster ;
31
+ import oracle .weblogic .kubernetes .actions .impl .NginxParams ;
32
+ import oracle .weblogic .kubernetes .actions .impl .Service ;
26
33
import oracle .weblogic .kubernetes .actions .impl .primitive .WitParams ;
27
34
import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
28
35
import oracle .weblogic .kubernetes .annotations .Namespaces ;
42
49
import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
43
50
import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
44
51
import 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 ;
45
54
import static oracle .weblogic .kubernetes .TestConstants .RESULTS_ROOT ;
46
55
import static oracle .weblogic .kubernetes .TestConstants .TRAEFIK_INGRESS_HTTP_HOSTPORT ;
47
56
import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_IMAGE_TO_USE_IN_SPEC ;
51
60
import static oracle .weblogic .kubernetes .actions .TestActions .buildAppArchive ;
52
61
import static oracle .weblogic .kubernetes .actions .TestActions .defaultAppParams ;
53
62
import 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 ;
54
65
import static oracle .weblogic .kubernetes .utils .AuxiliaryImageUtils .createAndPushAuxiliaryImage ;
55
66
import static oracle .weblogic .kubernetes .utils .ClusterUtils .createClusterAndVerify ;
56
67
import static oracle .weblogic .kubernetes .utils .ClusterUtils .createClusterResource ;
60
71
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getDateAndTimeStamp ;
61
72
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getHostAndPort ;
62
73
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
74
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getServiceExtIPAddrtOke ;
63
75
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .runClientInsidePod ;
64
76
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .runJavacInsidePod ;
65
77
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
66
78
import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainAndVerify ;
67
79
import static oracle .weblogic .kubernetes .utils .FileUtils .copyFileToPod ;
68
80
import 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 ;
69
83
import static oracle .weblogic .kubernetes .utils .OperatorUtils .installAndVerifyOperator ;
84
+ import static oracle .weblogic .kubernetes .utils .PodUtils .checkPodReady ;
70
85
import static oracle .weblogic .kubernetes .utils .PodUtils .getExternalServicePodName ;
71
86
import static oracle .weblogic .kubernetes .utils .PodUtils .setPodAntiAffinity ;
72
87
import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretWithUsernamePassword ;
73
88
import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretsForImageRepos ;
74
89
import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
90
+ import static org .assertj .core .api .Assertions .assertThat ;
75
91
import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
76
92
import static org .junit .jupiter .api .Assertions .assertNotEquals ;
77
93
import static org .junit .jupiter .api .Assertions .assertNotNull ;
83
99
@ DisplayName ("Verify cross domain transaction is successful with CrossDomainSecurityEnabled set to true" )
84
100
@ IntegrationTest
85
101
@ Tag ("kind-parallel" )
102
+ @ Tag ("oke-gate" )
86
103
class ItCrossDomainTransactionSecurity {
87
104
88
105
private static final String auxImageName1 = DOMAIN_IMAGES_PREFIX + "domain1-cdxaction-aux" ;
@@ -106,7 +123,9 @@ class ItCrossDomainTransactionSecurity {
106
123
private static String domain1AdminExtSvcRouteHost = null ;
107
124
private static String hostAndPort1 = null ;
108
125
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 ;
110
129
111
130
112
131
@@ -128,12 +147,24 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
128
147
assertNotNull (namespaces .get (1 ), "Namespace list is null" );
129
148
domainNamespace = namespaces .get (1 );
130
149
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
+
131
155
// Create the repo secret to pull the image
132
156
// this secret is used only for non-kind cluster
133
157
createTestRepoSecret (domainNamespace );
134
158
135
159
// install and verify operator
136
160
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
+
137
168
buildDomains ();
138
169
139
170
}
@@ -165,13 +196,19 @@ void testCrossDomainTransactionCommitSecurityEnable() throws UnknownHostExceptio
165
196
assertNotEquals (-1 , domain1AdminServiceNodePort , "domain2 admin server default node port is not valid" );
166
197
logger .info ("domain2AdminServiceNodePort is: " + domain2AdminServiceNodePort );
167
198
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
170
206
&& !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 ())
173
209
+ ":" + TRAEFIK_INGRESS_HTTP_HOSTPORT ;
174
210
211
+ }
175
212
}
176
213
logger .info ("hostHeader1 for domain1 is: " + hostHeader1 );
177
214
logger .info ("hostAndPort1 for domain1 is: " + hostAndPort1 );
@@ -216,7 +253,7 @@ void testCrossDomainTransactionCommitSecurityEnable() throws UnknownHostExceptio
216
253
testUntil (
217
254
runClientInsidePod (domain1AdminServerPodName , domainNamespace ,
218
255
"/u01" , "JmsSendReceiveClient" ,
219
- "t3://" + K8S_NODEPORT_HOST + ":" + t3ChannelPort1 , "receive" , "jms.admin.adminQueue" , "1" ),
256
+ "t3://" + "localhost" + ":" + "7001" , "receive" , "jms.admin.adminQueue" , "1" ),
220
257
logger ,
221
258
"Wait for JMS Client to send/recv msg" );
222
259
@@ -252,7 +289,7 @@ void testCrossDomainTransactionCommitSecurityEnable() throws UnknownHostExceptio
252
289
testUntil (
253
290
runClientInsidePod (domain1AdminServerPodName , domainNamespace ,
254
291
"/u01" , "JmsSendReceiveClient" ,
255
- "t3://" + K8S_NODEPORT_HOST + ":" + t3ChannelPort1 , "receive" , "jms.admin.adminQueue" , "0" ),
292
+ "t3://" + "localhost" + ":" + "7001" , "receive" , "jms.admin.adminQueue" , "0" ),
256
293
logger ,
257
294
"Wait for JMS Client to send/recv msg" );
258
295
}
@@ -524,5 +561,74 @@ private String getCurlResult(String curlCmd) {
524
561
return result .stdout ();
525
562
}
526
563
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
+
527
633
}
528
634
0 commit comments