4242import oracle .weblogic .domain .DomainResource ;
4343import oracle .weblogic .domain .DomainSpec ;
4444import oracle .weblogic .domain .ServerPod ;
45+ import oracle .weblogic .kubernetes .actions .impl .NginxParams ;
46+ import oracle .weblogic .kubernetes .actions .impl .Service ;
4547import oracle .weblogic .kubernetes .actions .impl .primitive .Kubernetes ;
4648import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
4749import oracle .weblogic .kubernetes .annotations .Namespaces ;
6668import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
6769import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
6870import static oracle .weblogic .kubernetes .TestConstants .KUBERNETES_CLI ;
71+ import static oracle .weblogic .kubernetes .TestConstants .OKE_CLUSTER_PRIVATEIP ;
6972import static oracle .weblogic .kubernetes .TestConstants .RESULTS_TEMPFILE ;
7073import static oracle .weblogic .kubernetes .TestConstants .TRAEFIK_INGRESS_HTTP_HOSTPORT ;
7174import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_12213 ;
9396import static oracle .weblogic .kubernetes .utils .CommonTestUtils .createIngressHostRouting ;
9497import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getHostAndPort ;
9598import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
99+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getServiceExtIPAddrtOke ;
96100import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getUniqueName ;
97101import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
98102import static oracle .weblogic .kubernetes .utils .CommonTestUtils .withLongRetryPolicy ;
105109import static oracle .weblogic .kubernetes .utils .ImageUtils .createBaseRepoSecret ;
106110import static oracle .weblogic .kubernetes .utils .JobUtils .createDomainJob ;
107111import static oracle .weblogic .kubernetes .utils .JobUtils .getIntrospectJobName ;
112+ import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .createNginxIngressPathRoutingRules ;
113+ import static oracle .weblogic .kubernetes .utils .LoadBalancerUtils .installAndVerifyNginx ;
108114import static oracle .weblogic .kubernetes .utils .MySQLDBUtils .createMySQLDB ;
109115import static oracle .weblogic .kubernetes .utils .OKDUtils .createRouteForOKD ;
110116import static oracle .weblogic .kubernetes .utils .OperatorUtils .installAndVerifyOperator ;
133139@ DisplayName ("Verify the overrideDistributionStrategy applies the overrides accordingly to the value set" )
134140@ Tag ("kind-parallel" )
135141@ Tag ("okd-wls-mrg" )
136- @ Tag ("oke-sequential " )
142+ @ Tag ("oke-gate " )
137143@ IntegrationTest
138144@ Tag ("olcne-mrg" )
139145class ItConfigDistributionStrategy {
140146
141147 private static String opNamespace = null ;
142148 private static String domainNamespace = null ;
149+ private static String nginxNamespace = null ;
150+ private static NginxParams nginxHelmParams = null ;
143151
144152 final String domainUid = "mydomain" ;
145153 final String clusterName = "mycluster" ;
@@ -155,6 +163,7 @@ class ItConfigDistributionStrategy {
155163 final String wlSecretName = "weblogic-credentials" ;
156164 final String managedServerPodNamePrefix = domainUid + "-" + managedServerNameBase ;
157165 int replicaCount = 2 ;
166+ static String hostAndPort ;
158167
159168 static Path clusterViewAppPath ;
160169 String overridecm = "configoverride-cm" ;
@@ -166,12 +175,13 @@ class ItConfigDistributionStrategy {
166175 static String dsUrl2 ;
167176 static String mysql1SvcEndpoint = null ;
168177 static String mysql2SvcEndpoint = null ;
178+ private static String ingressIP = null ;
169179
170180 String dsName0 = "JdbcTestDataSource-0" ;
171181 String dsName1 = "JdbcTestDataSource-1" ;
172182 String dsSecret = domainUid .concat ("-mysql-secret" );
173183 String adminSvcExtHost = null ;
174- static String hostHeader ;
184+ static String hostHeader ;
175185
176186 private static LoggingFacade logger = null ;
177187
@@ -187,7 +197,7 @@ class ItConfigDistributionStrategy {
187197 * @param namespaces injected by JUnit
188198 */
189199 @ BeforeAll
190- public void initAll (@ Namespaces (2 ) List <String > namespaces ) throws ApiException , IOException {
200+ public void initAll (@ Namespaces (3 ) List <String > namespaces ) throws ApiException , IOException {
191201 logger = getLogger ();
192202
193203 logger .info ("Assign a unique namespace for operator" );
@@ -196,10 +206,20 @@ public void initAll(@Namespaces(2) List<String> namespaces) throws ApiException,
196206 logger .info ("Assign a unique namespace for domain namspace" );
197207 assertNotNull (namespaces .get (1 ), "Namespace is null" );
198208 domainNamespace = namespaces .get (1 );
209+ assertNotNull (namespaces .get (2 ), "Namespace is null" );
210+ nginxNamespace = namespaces .get (2 );
199211
200212 // install operator and verify its running in ready state
201213 installAndVerifyOperator (opNamespace , domainNamespace );
214+ ingressIP = K8S_NODEPORT_HOST ;
215+ if (OKE_CLUSTER_PRIVATEIP ) {
216+ // install and verify NGINX
217+ nginxHelmParams = installAndVerifyNginx (nginxNamespace , 0 , 0 );
218+ String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
219+ ingressIP = getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace ) != null
220+ ? getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace ) : K8S_NODEPORT_HOST ;
202221
222+ }
203223 // create pull secrets for WebLogic image when running in non Kind Kubernetes cluster
204224 // this secret is used only for non-kind cluster
205225 createBaseRepoSecret (domainNamespace );
@@ -232,6 +252,14 @@ public void initAll(@Namespaces(2) List<String> namespaces) throws ApiException,
232252
233253 //create and start WebLogic domain
234254 createDomain ();
255+ if (OKE_CLUSTER_PRIVATEIP ) {
256+ String ingressClassName = nginxHelmParams .getIngressClassName ();
257+ String serviceName = domainUid + "-admin-server" ;
258+ final int ADMIN_SERVER_PORT = 7001 ;
259+ String hostAndPort = getHostAndPortOKE ();
260+ createNginxIngressPathRoutingRules (domainNamespace , ingressClassName ,
261+ serviceName , ADMIN_SERVER_PORT , hostAndPort );
262+ }
235263
236264 // Expose the admin service external node port as a route for OKD
237265 adminSvcExtHost = createRouteForOKD (getExternalServicePodName (adminServerPodName ), domainNamespace );
@@ -286,6 +314,9 @@ public void afterEach() {
286314 headers .put ("host" , hostHeader );
287315 }
288316 boolean ipv6 = K8S_NODEPORT_HOST .contains (":" );
317+ if (OKE_CLUSTER_PRIVATEIP ) {
318+ hostAndPort = ingressIP ;
319+ }
289320 String baseUri = "http://" + hostAndPort + "/clusterview/" ;
290321 String serverListUri = "ClusterViewServlet?user=" + ADMIN_USERNAME_DEFAULT
291322 + "&password=" + ADMIN_PASSWORD_DEFAULT + "&ipv6=" + ipv6 ;
@@ -688,6 +719,9 @@ private Callable<Boolean> configUpdated(String maxMessageSize) {
688719 headers = new HashMap <>();
689720 headers .put ("host" , hostHeader );
690721 }
722+ if (OKE_CLUSTER_PRIVATEIP ) {
723+ hostAndPort = ingressIP ;
724+ }
691725 String url = "http://" + hostAndPort + appURI ;
692726 HttpResponse <String > response = OracleHttpClient .get (url , headers , true );
693727 assertEquals (200 , response .statusCode (), "Status code not equals to 200" );
@@ -714,6 +748,9 @@ private void verifyConfigXMLOverride(boolean configUpdated) {
714748 headers = new HashMap <>();
715749 headers .put ("host" , hostHeader );
716750 }
751+ if (OKE_CLUSTER_PRIVATEIP ) {
752+ hostAndPort = getHostAndPortOKE ();
753+ }
717754 String baseUri = "http://" + hostAndPort + "/clusterview/" ;
718755 HttpResponse <String > response = OracleHttpClient .get (baseUri + configUri , headers , true );
719756 if (response .statusCode () != 200 ) {
@@ -746,6 +783,9 @@ private void verifyResourceJDBC0Override(boolean configUpdated) {
746783 headers = new HashMap <>();
747784 headers .put ("host" , hostHeader );
748785 }
786+ if (OKE_CLUSTER_PRIVATEIP ) {
787+ hostAndPort = getHostAndPortOKE ();
788+ }
749789 logger .info ("hostAndPort = {0} " , hostAndPort );
750790 String baseUri = "http://" + hostAndPort + "/clusterview/ConfigServlet?" ;
751791 //verify datasource attributes of JdbcTestDataSource-0
@@ -786,7 +826,7 @@ private void verifyResourceJDBC0Override(boolean configUpdated) {
786826 testDatasource (appURI );
787827 }
788828 }
789-
829+
790830 private void testDatasource (String appURI ) {
791831 int port = getServiceNodePort (domainNamespace , getExternalServicePodName (adminServerPodName ), "default" );
792832 testUntil (
@@ -799,6 +839,9 @@ private void testDatasource(String appURI) {
799839 headers = new HashMap <>();
800840 headers .put ("host" , hostHeader );
801841 }
842+ if (OKE_CLUSTER_PRIVATEIP ) {
843+ hostAndPort = getHostAndPortOKE ();
844+ }
802845 logger .info ("hostAndPort = {0} " , hostAndPort );
803846 String baseUri = "http://" + hostAndPort + "/clusterview/ConfigServlet?" ;
804847
@@ -837,11 +880,14 @@ private void verifyResourceJDBC1Override(boolean configUpdated) {
837880 headers = new HashMap <>();
838881 headers .put ("host" , hostHeader );
839882 }
883+ if (OKE_CLUSTER_PRIVATEIP ) {
884+ hostAndPort = getHostAndPortOKE ();
885+ }
840886 String baseUri = "http://" + hostAndPort + "/clusterview/ConfigServlet?" ;
841887
842888 //verify datasource attributes of JdbcTestDataSource-0
843889 String appURI = "resTest=true&resName=" + dsName1 ;
844- String dsOverrideTestUrl = baseUri + appURI ;
890+ String dsOverrideTestUrl = baseUri + appURI ;
845891 HttpResponse <String > response = OracleHttpClient .get (dsOverrideTestUrl , headers , true );
846892 if (response .statusCode () != 200 ) {
847893 logger .info ("Response code is not 200 retrying..." );
@@ -891,6 +937,9 @@ private void verifyResourceJDBC1Override(boolean configUpdated) {
891937 headers = new HashMap <>();
892938 headers .put ("host" , hostHeader );
893939 }
940+ if (OKE_CLUSTER_PRIVATEIP ) {
941+ hostAndPort = getHostAndPortOKE ();
942+ }
894943 String baseUri = "http://" + hostAndPort + "/clusterview/ConfigServlet?" ;
895944 String appURI = "dsTest=true&dsName=" + dsName1 + "&" + "serverName=" + managedServerNameBase + i ;
896945 String dsConnectionPoolTestUrl = baseUri + appURI ;
@@ -934,7 +983,7 @@ private void verifyIntrospectorRuns() {
934983
935984 //create a standard WebLogic domain.
936985 private void createDomain () {
937-
986+
938987 String uniquePath = "/shared/" + domainNamespace + "/domains" ;
939988
940989 // create WebLogic domain credential secret
@@ -959,7 +1008,7 @@ private void createDomain() {
9591008 p .setProperty ("admin_server_port" , "7001" );
9601009 p .setProperty ("admin_username" , ADMIN_USERNAME_DEFAULT );
9611010 p .setProperty ("admin_password" , ADMIN_PASSWORD_DEFAULT );
962- p .setProperty ("admin_t3_public_address" , K8S_NODEPORT_HOST );
1011+ p .setProperty ("admin_t3_public_address" , ingressIP );
9631012 p .setProperty ("admin_t3_channel_port" , Integer .toString (t3ChannelPort ));
9641013 p .setProperty ("number_of_ms" , "2" );
9651014 p .setProperty ("managed_server_name_base" , managedServerNameBase );
@@ -1166,7 +1215,7 @@ private void createJdbcDataSource(String dsName, String user, String password, S
11661215 * @param namespace name of the domain namespace in which the job is created
11671216 */
11681217 private void createDomainOnPVUsingWlst (Path wlstScriptFile , Path domainPropertiesFile ,
1169- String pvName , String pvcName , String namespace ) {
1218+ String pvName , String pvcName , String namespace ) {
11701219 logger .info ("Preparing to run create domain job using WLST" );
11711220
11721221 List <Path > domainScriptFiles = new ArrayList <>();
@@ -1290,4 +1339,13 @@ private void createFileInPod(String podName, String namespace, String password)
12901339 assertEquals (0 , result .exitValue (), "mysql execution fails" );
12911340 }
12921341
1342+ private static String getHostAndPortOKE () {
1343+ String nginxServiceName = nginxHelmParams .getHelmParams ().getReleaseName () + "-ingress-nginx-controller" ;
1344+ int nginxNodePort = assertDoesNotThrow (() -> Service .getServiceNodePort (nginxNamespace , nginxServiceName , "http" ),
1345+ "Getting Nginx loadbalancer service node port failed" );
1346+
1347+ hostAndPort = getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace ) != null
1348+ ? getServiceExtIPAddrtOke (nginxServiceName , nginxNamespace ) : K8S_NODEPORT_HOST + ":" + nginxNodePort ;
1349+ return hostAndPort ;
1350+ }
12931351}
0 commit comments