33
44package oracle .weblogic .kubernetes ;
55
6+ import java .net .InetAddress ;
7+ import java .net .UnknownHostException ;
68import java .nio .file .Path ;
79import java .nio .file .Paths ;
810import java .util .ArrayList ;
4547import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_API_VERSION ;
4648import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_VERSION ;
4749import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
50+ import static oracle .weblogic .kubernetes .TestConstants .IT_EXTERNALLB_TUNNELING_HTTPS_CONAINERPORT ;
51+ import static oracle .weblogic .kubernetes .TestConstants .IT_EXTERNALLB_TUNNELING_HTTPS_HOSTPORT ;
52+ import static oracle .weblogic .kubernetes .TestConstants .IT_EXTERNALLB_TUNNELING_HTTP_CONAINERPORT ;
53+ import static oracle .weblogic .kubernetes .TestConstants .IT_EXTERNALLB_TUNNELING_HTTP_HOSTPORT ;
4854import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
4955import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOSTNAME ;
5056import static oracle .weblogic .kubernetes .TestConstants .KUBERNETES_CLI ;
5763import static oracle .weblogic .kubernetes .TestConstants .TRAEFIK_RELEASE_NAME ;
5864import static oracle .weblogic .kubernetes .actions .ActionConstants .RESOURCE_DIR ;
5965import static oracle .weblogic .kubernetes .actions .TestActions .createDomainCustomResource ;
60- import static oracle .weblogic .kubernetes .actions .TestActions .getServiceNodePort ;
6166import static oracle .weblogic .kubernetes .actions .TestActions .getServicePort ;
6267import static oracle .weblogic .kubernetes .actions .TestActions .uninstallTraefik ;
6368import static oracle .weblogic .kubernetes .assertions .TestAssertions .domainExists ;
6469import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
70+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .formatIPv6Host ;
6571import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getHostAndPort ;
6672import static oracle .weblogic .kubernetes .utils .CommonTestUtils .getNextFreePort ;
6773import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
@@ -130,6 +136,7 @@ class ItExternalLbTunneling {
130136 private static Path jksTrustFile ;
131137 private static String tlsSecretName = domainUid + "-test-tls-secret" ;
132138 private String clusterSvcRouteHost = null ;
139+ private static String hostAddress = K8S_NODEPORT_HOST ;
133140
134141 /**
135142 * Install Operator.
@@ -138,9 +145,13 @@ class ItExternalLbTunneling {
138145 JUnit engine parameter resolution mechanism
139146 */
140147 @ BeforeAll
141- public static void initAll (@ Namespaces (3 ) List <String > namespaces ) {
148+ public static void initAll (@ Namespaces (3 ) List <String > namespaces ) throws UnknownHostException {
142149 logger = getLogger ();
143150 logger .info ("K8S_NODEPORT_HOSTNAME {0} K8S_NODEPORT_HOST {1}" , K8S_NODEPORT_HOSTNAME , K8S_NODEPORT_HOST );
151+ if (TestConstants .KIND_CLUSTER
152+ && !TestConstants .WLSIMG_BUILDER .equals (TestConstants .WLSIMG_BUILDER_DEFAULT )) {
153+ hostAddress = formatIPv6Host (InetAddress .getLocalHost ().getHostAddress ());
154+ }
144155
145156 // get a new unique opNamespace
146157 logger .info ("Assigning unique namespace for Operator" );
@@ -177,7 +188,7 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
177188 // Prepare the config map sparse model file from the template by replacing
178189 // Public Address of the custom channel with K8S_NODEPORT_HOST
179190 Map <String , String > configTemplateMap = new HashMap <>();
180- configTemplateMap .put ("INGRESS_HOST" , K8S_NODEPORT_HOST );
191+ configTemplateMap .put ("INGRESS_HOST" , hostAddress );
181192
182193 Path srcFile = Paths .get (RESOURCE_DIR ,
183194 "wdt-models" , "tunneling.model.template.yaml" );
@@ -207,11 +218,12 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
207218
208219 if (!OKD ) {
209220 logger .info ("Installing Traefik controller using helm" );
210- traefikHelmParams = installAndVerifyTraefik (traefikNamespace , 0 , 0 ).getHelmParams ();
221+ traefikHelmParams = installAndVerifyTraefik (traefikNamespace ,
222+ IT_EXTERNALLB_TUNNELING_HTTP_CONAINERPORT , IT_EXTERNALLB_TUNNELING_HTTPS_CONAINERPORT ).getHelmParams ();
211223 }
212224
213225 // Create SSL certificate and key using openSSL with SAN extension
214- createCertKeyFiles (K8S_NODEPORT_HOST );
226+ createCertKeyFiles (hostAddress );
215227 // Create kubernates secret using genereated certificate and key
216228 createSecretWithTLSCertKey (tlsSecretName );
217229 // Import the tls certificate into a JKS truststote to be used while
@@ -262,7 +274,7 @@ void testExternalRmiAccessThruTraefik() {
262274 templateMap .put ("DOMAIN_NS" , domainNamespace );
263275 templateMap .put ("DOMAIN_UID" , domainUid );
264276 templateMap .put ("CLUSTER" , clusterName );
265- templateMap .put ("INGRESS_HOST" , K8S_NODEPORT_HOST );
277+ templateMap .put ("INGRESS_HOST" , hostAddress );
266278
267279 Path srcTraefikHttpFile = Paths .get (RESOURCE_DIR ,
268280 "tunneling" , "traefik.tunneling.template.yaml" );
@@ -281,11 +293,14 @@ void testExternalRmiAccessThruTraefik() {
281293
282294 // Get the ingress service nodeport corresponding to non-tls service
283295 // Get the Traefik Service Name traefik-release-{ns}
284- String service =
285- TRAEFIK_RELEASE_NAME + "-" + traefikNamespace .substring (3 );
296+ String service
297+ = TRAEFIK_RELEASE_NAME + "-" + traefikNamespace .substring (3 );
286298 logger .info ("TRAEFIK_SERVICE {0} in {1}" , service , traefikNamespace );
287- int httpTunnelingPort =
288- getServiceNodePort (traefikNamespace , service , "web" );
299+ int httpTunnelingPort = IT_EXTERNALLB_TUNNELING_HTTP_CONAINERPORT ;
300+ if (TestConstants .KIND_CLUSTER
301+ && !TestConstants .WLSIMG_BUILDER .equals (TestConstants .WLSIMG_BUILDER_DEFAULT )) {
302+ httpTunnelingPort = IT_EXTERNALLB_TUNNELING_HTTP_HOSTPORT ;
303+ }
289304 assertNotEquals (-1 , httpTunnelingPort ,
290305 "Could not get the Traefik HttpTunnelingPort service node port" );
291306 logger .info ("HttpTunnelingPort for Traefik {0}" , httpTunnelingPort );
@@ -320,7 +335,7 @@ void testExternalRmiAccessThruTraefikHttpsTunneling() {
320335 templateMap .put ("DOMAIN_UID" , domainUid );
321336 templateMap .put ("CLUSTER" , clusterName );
322337 templateMap .put ("TLS_CERT" , tlsSecretName );
323- templateMap .put ("INGRESS_HOST" , K8S_NODEPORT_HOST );
338+ templateMap .put ("INGRESS_HOST" , hostAddress );
324339
325340 Path srcTraefikHttpsFile = Paths .get (RESOURCE_DIR ,
326341 "tunneling" , "traefik.tls.tunneling.template.yaml" );
@@ -339,11 +354,14 @@ void testExternalRmiAccessThruTraefikHttpsTunneling() {
339354
340355 // Get the ingress service nodeport corresponding to tls service
341356 // Get the Traefik Service Name traefik-release-{ns}
342- String service =
343- TRAEFIK_RELEASE_NAME + "-" + traefikNamespace .substring (3 );
357+ String service
358+ = TRAEFIK_RELEASE_NAME + "-" + traefikNamespace .substring (3 );
344359 logger .info ("TRAEFIK_SERVICE {0} in {1}" , service , traefikNamespace );
345- int httpsTunnelingPort =
346- getServiceNodePort (traefikNamespace , service , "websecure" );
360+ int httpsTunnelingPort = IT_EXTERNALLB_TUNNELING_HTTPS_CONAINERPORT ;
361+ if (TestConstants .KIND_CLUSTER
362+ && !TestConstants .WLSIMG_BUILDER .equals (TestConstants .WLSIMG_BUILDER_DEFAULT )) {
363+ httpsTunnelingPort = IT_EXTERNALLB_TUNNELING_HTTPS_HOSTPORT ;
364+ }
347365 assertNotEquals (-1 , httpsTunnelingPort ,
348366 "Could not get the Traefik HttpsTunnelingPort service node port" );
349367 logger .info ("HttpsTunnelingPort for Traefik {0}" , httpsTunnelingPort );
@@ -441,8 +459,7 @@ private void runExtHttpsClient(String routeHost, int httpsTunnelingPort, int ser
441459 logger .info ("java command to be run {0}" , javasCmd .toString ());
442460
443461 // Note it takes a couples of iterations before the client success
444- testUntil (
445- runJmsClient (new String (javasCmd )),
462+ testUntil (runJmsClient (new String (javasCmd )),
446463 logger ,
447464 "Wait for Https JMS Client to access WLS" );
448465 }
@@ -503,7 +520,7 @@ private void runExtClient(String routeHost, int httpTunnelingPort, int serverCou
503520 javaCmd .append (String .valueOf (checkConnection ));
504521 logger .info ("java command to be run {0}" , javaCmd .toString ());
505522
506- // Note it takes a couples of iterations before the client success
523+ // Note it takes a couples of iterations before the client success
507524 testUntil (runJmsClient (new String (javaCmd )), logger , "Wait for Http JMS Client to access WLS" );
508525 }
509526
@@ -604,7 +621,7 @@ public void tearDownAll() {
604621 private static void createCertKeyFiles (String cn ) {
605622
606623 Map <String , String > sanConfigTemplateMap = new HashMap <>();
607- sanConfigTemplateMap .put ("INGRESS_HOST" , K8S_NODEPORT_HOST );
624+ sanConfigTemplateMap .put ("INGRESS_HOST" , hostAddress );
608625
609626 Path srcFile = Paths .get (RESOURCE_DIR ,
610627 "tunneling" , "san.config.template.txt" );
0 commit comments