Skip to content

Commit eddd800

Browse files
sankarpnrjeberhard
authored andcommitted
Access secure weblogic server in istio service mesh
1 parent d846260 commit eddd800

File tree

3 files changed

+126
-22
lines changed

3 files changed

+126
-22
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItIstioProductionSecureMode.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
package oracle.weblogic.kubernetes;
55

6+
import java.net.InetAddress;
7+
import java.net.UnknownHostException;
68
import java.nio.file.Path;
79
import java.nio.file.Paths;
810
import java.util.HashMap;
@@ -31,20 +33,26 @@
3133
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
3234
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_API_VERSION;
3335
import static oracle.weblogic.kubernetes.TestConstants.IMAGE_PULL_POLICY;
36+
import static oracle.weblogic.kubernetes.TestConstants.ISTIO_HTTPS_HOSTPORT;
37+
import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST;
3438
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_NAME;
3539
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
40+
import static oracle.weblogic.kubernetes.TestConstants.OCNE;
3641
import static oracle.weblogic.kubernetes.TestConstants.SSL_PROPERTIES;
3742
import static oracle.weblogic.kubernetes.TestConstants.TEST_IMAGES_REPO_SECRET_NAME;
3843
import static oracle.weblogic.kubernetes.actions.ActionConstants.RESOURCE_DIR;
3944
import static oracle.weblogic.kubernetes.actions.TestActions.addLabelsToNamespace;
4045
import static oracle.weblogic.kubernetes.actions.TestActions.createConfigMap;
46+
import static oracle.weblogic.kubernetes.utils.ApplicationUtils.checkAppUsingHostHeader;
4147
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
48+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.formatIPv6Host;
49+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getServiceExtIPAddrtOke;
50+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
4251
import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainAndVerify;
4352
import static oracle.weblogic.kubernetes.utils.FileUtils.generateFileFromTemplate;
4453
import static oracle.weblogic.kubernetes.utils.ImageUtils.createTestRepoSecret;
4554
import static oracle.weblogic.kubernetes.utils.IstioUtils.createAdminServer;
4655
import static oracle.weblogic.kubernetes.utils.IstioUtils.deployHttpIstioGatewayAndVirtualservice;
47-
import static oracle.weblogic.kubernetes.utils.IstioUtils.deployIstioDestinationRule;
4856
import static oracle.weblogic.kubernetes.utils.IstioUtils.getIstioHttpIngressPort;
4957
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
5058
import static oracle.weblogic.kubernetes.utils.PodUtils.setPodAntiAffinity;
@@ -71,6 +79,8 @@ class ItIstioProductionSecureMode {
7179
private final String adminServerPodName = domainUid + "-admin-server";
7280
private final String managedServerPrefix = domainUid + "-managed-server";
7381
private final int replicaCount = 1;
82+
private static final String istioNamespace = "istio-system";
83+
private static final String istioIngressServiceName = "istio-ingressgateway";
7484
private static LoggingFacade logger = null;
7585

7686
/**
@@ -115,7 +125,7 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
115125
*/
116126
@Test
117127
@DisplayName("Create WebLogic SecureMode Domain with mii model with istio")
118-
void testIstioModelInImageSecureModeDomain() {
128+
void testIstioModelInImageSecureModeDomain() throws UnknownHostException {
119129

120130
// Create the repo secret to pull the image
121131
// this secret is used only for non-kind cluster
@@ -178,34 +188,36 @@ void testIstioModelInImageSecureModeDomain() {
178188
checkPodReadyAndServiceExists(managedServerPrefix + i, domainUid, domainNamespace);
179189
}
180190

181-
String clusterService = domainUid + "-cluster-" + clusterName + "." + domainNamespace + ".svc.cluster.local";
182-
183-
Map<String, String> templateMap = new HashMap<>();
191+
Map<String, String> templateMap = new HashMap<>();
184192
templateMap.put("NAMESPACE", domainNamespace);
185-
templateMap.put("DUID", domainUid);
186-
templateMap.put("ADMIN_SERVICE",adminServerPodName);
187-
templateMap.put("CLUSTER_SERVICE", clusterService);
188193

189-
Path srcHttpFile = Paths.get(RESOURCE_DIR, "istio", "istio-http-template.yaml");
194+
Path srcHttpFile = Paths.get(RESOURCE_DIR, "istio", "istio-productionsecure-tls-mode.yaml");
190195
Path targetHttpFile = assertDoesNotThrow(
191-
() -> generateFileFromTemplate(srcHttpFile.toString(), "istio-http.yaml", templateMap));
196+
() -> generateFileFromTemplate(srcHttpFile.toString(), "istio-productionsecure-tls-mode.yaml", templateMap));
192197
logger.info("Generated Http VS/Gateway file path is {0}", targetHttpFile);
193198

194199
boolean deployRes = assertDoesNotThrow(
195200
() -> deployHttpIstioGatewayAndVirtualservice(targetHttpFile));
196201
assertTrue(deployRes, "Failed to deploy Http Istio Gateway/VirtualService");
197-
198-
Path srcDrFile = Paths.get(RESOURCE_DIR, "istio", "istio-dr-template.yaml");
199-
Path targetDrFile = assertDoesNotThrow(
200-
() -> generateFileFromTemplate(srcDrFile.toString(), "istio-dr.yaml", templateMap));
201-
logger.info("Generated DestinationRule file path is {0}", targetDrFile);
202-
203-
deployRes = assertDoesNotThrow(
204-
() -> deployIstioDestinationRule(targetDrFile));
205-
assertTrue(deployRes, "Failed to deploy Istio DestinationRule");
206-
207-
int istioIngressPort = getIstioHttpIngressPort();
202+
203+
String host = formatIPv6Host(K8S_NODEPORT_HOST);
204+
int istioIngressPort = getIstioHttpIngressPort("https");
208205
logger.info("Istio Ingress Port is {0}", istioIngressPort);
206+
logger.info("host {0}", host);
207+
String hostAndPort = getServiceExtIPAddrtOke(istioIngressServiceName, istioNamespace) != null
208+
? getServiceExtIPAddrtOke(istioIngressServiceName, istioNamespace) : host + ":" + istioIngressPort;
209+
210+
if (!TestConstants.WLSIMG_BUILDER.equals(TestConstants.WLSIMG_BUILDER_DEFAULT) && !OCNE) {
211+
istioIngressPort = ISTIO_HTTPS_HOSTPORT;
212+
hostAndPort = InetAddress.getLocalHost().getHostAddress() + ":" + istioIngressPort;
213+
}
214+
String url = "https://" + hostAndPort + "/weblogic/ready";
215+
testUntil(
216+
() -> checkAppUsingHostHeader(url,
217+
"istio-mii-securemode-admin-server.NAMESPACE.svc.cluster.local".replace("NAMESPACE", domainNamespace)),
218+
logger,
219+
"application to be ready {0}",
220+
url);
209221

210222
}
211223

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/IstioUtils.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,21 @@ public static void uninstallIstio() {
139139
* @return ingress port for istio-ingressgateway
140140
*/
141141
public static int getIstioHttpIngressPort() {
142+
return getIstioHttpIngressPort("http2");
143+
}
144+
145+
/**
146+
* Get the http ingress port of istio installation.
147+
*
148+
* @param portName name of port to get
149+
* @return ingress port for istio-ingressgateway
150+
*/
151+
public static int getIstioHttpIngressPort(String portName) {
142152
LoggingFacade logger = getLogger();
143153
ExecResult result;
144154
StringBuffer getIngressPort;
145155
getIngressPort = new StringBuffer(KUBERNETES_CLI + " -n istio-system get service istio-ingressgateway ");
146-
getIngressPort.append("-o jsonpath='{.spec.ports[?(@.name==\"http2\")].nodePort}'");
156+
getIngressPort.append("-o jsonpath='{.spec.ports[?(@.name==\"" + portName.trim() + "\")].nodePort}'");
147157
logger.info("getIngressPort: " + KUBERNETES_CLI + " command {0}", new String(getIngressPort));
148158
try {
149159
result = exec(new String(getIngressPort), true);
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright (c) 2024, Oracle and/or its affiliates.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3+
4+
apiVersion: networking.istio.io/v1beta1
5+
kind: Gateway
6+
metadata:
7+
name: wls-domain-gateway
8+
namespace: NAMESPACE
9+
spec:
10+
selector:
11+
istio: ingressgateway
12+
servers:
13+
- port:
14+
number: 80
15+
name: http
16+
protocol: HTTP
17+
hosts:
18+
- "*"
19+
- port:
20+
number: 443
21+
name: https-default-admin
22+
protocol: HTTPS
23+
tls:
24+
mode: PASSTHROUGH
25+
hosts:
26+
- "*"
27+
- port:
28+
number: 9002
29+
name: https-cluster-admin
30+
protocol: HTTPS
31+
tls:
32+
mode: PASSTHROUGH
33+
hosts:
34+
- "*"
35+
- port:
36+
number: 7002
37+
name: https-cluster-ssl
38+
protocol: HTTPS
39+
tls:
40+
mode: PASSTHROUGH
41+
hosts:
42+
- "*"
43+
---
44+
apiVersion: networking.istio.io/v1beta1
45+
kind: VirtualService
46+
metadata:
47+
name: wls-domain-virtualservice
48+
namespace: NAMESPACE
49+
spec:
50+
gateways:
51+
- wls-domain-gateway
52+
hosts:
53+
- "*"
54+
tls:
55+
- match:
56+
- port: 443
57+
sniHosts:
58+
- "*"
59+
route:
60+
- destination:
61+
host: istio-mii-securemode-admin-server.NAMESPACE.svc.cluster.local
62+
port:
63+
number: 9002
64+
- match:
65+
- port: 9002
66+
sniHosts:
67+
- "*"
68+
route:
69+
- destination:
70+
host: istio-mii-securemode-cluster-cluster-1.NAMESPACE.svc.cluster.local
71+
port:
72+
number: 9002
73+
- match:
74+
- port: 7002
75+
sniHosts:
76+
- "*"
77+
route:
78+
- destination:
79+
host: istio-mii-securemode-cluster-cluster-1.NAMESPACE.svc.cluster.local
80+
port:
81+
number: 7002
82+

0 commit comments

Comments
 (0)