Skip to content

Commit 6d5c27f

Browse files
committed
Merge branch 'backport-oke-lasttwo' into 'release/4.2'
[OKE] [backport] internal OKE conversion for ItConfigDistributionStrategy & ItIntrospectVersion on main into release/4.2 See merge request weblogic-cloud/weblogic-kubernetes-operator!4741
2 parents 224c0ce + 1aeaa4e commit 6d5c27f

File tree

3 files changed

+128
-11
lines changed

3 files changed

+128
-11
lines changed

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

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import oracle.weblogic.domain.DomainResource;
4343
import oracle.weblogic.domain.DomainSpec;
4444
import oracle.weblogic.domain.ServerPod;
45+
import oracle.weblogic.kubernetes.actions.impl.NginxParams;
46+
import oracle.weblogic.kubernetes.actions.impl.Service;
4547
import oracle.weblogic.kubernetes.actions.impl.primitive.Kubernetes;
4648
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
4749
import oracle.weblogic.kubernetes.annotations.Namespaces;
@@ -66,6 +68,7 @@
6668
import static oracle.weblogic.kubernetes.TestConstants.IMAGE_PULL_POLICY;
6769
import static oracle.weblogic.kubernetes.TestConstants.K8S_NODEPORT_HOST;
6870
import static oracle.weblogic.kubernetes.TestConstants.KUBERNETES_CLI;
71+
import static oracle.weblogic.kubernetes.TestConstants.OKE_CLUSTER_PRIVATEIP;
6972
import static oracle.weblogic.kubernetes.TestConstants.RESULTS_TEMPFILE;
7073
import static oracle.weblogic.kubernetes.TestConstants.TRAEFIK_INGRESS_HTTP_HOSTPORT;
7174
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_12213;
@@ -93,6 +96,7 @@
9396
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createIngressHostRouting;
9497
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getHostAndPort;
9598
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getNextFreePort;
99+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getServiceExtIPAddrtOke;
96100
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.getUniqueName;
97101
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
98102
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.withLongRetryPolicy;
@@ -105,6 +109,8 @@
105109
import static oracle.weblogic.kubernetes.utils.ImageUtils.createBaseRepoSecret;
106110
import static oracle.weblogic.kubernetes.utils.JobUtils.createDomainJob;
107111
import 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;
108114
import static oracle.weblogic.kubernetes.utils.MySQLDBUtils.createMySQLDB;
109115
import static oracle.weblogic.kubernetes.utils.OKDUtils.createRouteForOKD;
110116
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
@@ -133,13 +139,15 @@
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")
139145
class 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
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
@Tag("olcne-srg")
173173
@Tag("kind-parallel")
174174
@Tag("okd-wls-mrg")
175-
@Tag("oke-sequential1")
175+
@Tag("oke-gate")
176176
@Tag("oke-arm")
177177
class ItIntrospectVersion {
178178

@@ -1369,7 +1369,6 @@ private static void verifyMemberHealth(String adminServerPodName, List<String> m
13691369
} else {
13701370
// In non-internal OKE env, verifyMemberHealth using adminSvcExtHost by sending HTTP request from local VM
13711371

1372-
// TEST, HERE
13731372
String extSvcPodName = getExternalServicePodName(adminServerPodName);
13741373
logger.info("**** adminServerPodName={0}", adminServerPodName);
13751374
logger.info("**** extSvcPodName={0}", extSvcPodName);
@@ -1588,5 +1587,4 @@ private void updateIngressBackendServicePort(int newAdminPort) throws ApiExcepti
15881587
fail("Ingress is null, failed to update ingress");
15891588
}
15901589
}
1591-
15921590
}

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@
1515

1616
import io.kubernetes.client.custom.IntOrString;
1717
import io.kubernetes.client.openapi.ApiException;
18+
import io.kubernetes.client.openapi.models.V1HTTPIngressPath;
19+
import io.kubernetes.client.openapi.models.V1HTTPIngressRuleValue;
20+
import io.kubernetes.client.openapi.models.V1IngressBackend;
1821
import io.kubernetes.client.openapi.models.V1IngressRule;
22+
import io.kubernetes.client.openapi.models.V1IngressServiceBackend;
1923
import io.kubernetes.client.openapi.models.V1IngressTLS;
2024
import io.kubernetes.client.openapi.models.V1ObjectMeta;
2125
import io.kubernetes.client.openapi.models.V1Service;
26+
import io.kubernetes.client.openapi.models.V1ServiceBackendPort;
2227
import io.kubernetes.client.openapi.models.V1ServicePort;
2328
import io.kubernetes.client.openapi.models.V1ServiceSpec;
2429
import oracle.weblogic.kubernetes.TestConstants;
@@ -460,6 +465,62 @@ public static List<String> createIngressForDomainAndVerify(String domainUid,
460465
return ingressHostList;
461466
}
462467

468+
/**
469+
* Creates Nginx Ingress Path Routing for service.
470+
* @param domainNamespace - domain namespace
471+
* @param ingressClassName - class name
472+
* @param serviceName - service name
473+
* @param servicePort -service port
474+
* @param hostAndPort - host and port for url
475+
*/
476+
public static void createNginxIngressPathRoutingRules(String domainNamespace,
477+
String ingressClassName,
478+
String serviceName,
479+
int servicePort,
480+
String hostAndPort) {
481+
// create an ingress in domain namespace
482+
String ingressName = domainNamespace + "-nginx-path-routing";
483+
484+
// create ingress rules for two domains
485+
List<V1IngressRule> ingressRules = new ArrayList<>();
486+
List<V1HTTPIngressPath> httpIngressPaths = new ArrayList<>();
487+
488+
V1HTTPIngressPath httpIngressPath = new V1HTTPIngressPath()
489+
.path("/")
490+
.pathType("Prefix")
491+
.backend(new V1IngressBackend()
492+
.service(new V1IngressServiceBackend()
493+
.name(serviceName)
494+
.port(new V1ServiceBackendPort()
495+
.number(servicePort)))
496+
);
497+
httpIngressPaths.add(httpIngressPath);
498+
499+
V1IngressRule ingressRule = new V1IngressRule()
500+
.host("")
501+
.http(new V1HTTPIngressRuleValue()
502+
.paths(httpIngressPaths));
503+
504+
ingressRules.add(ingressRule);
505+
506+
createIngressAndRetryIfFail(60, false, ingressName, domainNamespace, null, ingressClassName, ingressRules, null);
507+
508+
// check the ingress was found in the domain namespace
509+
assertThat(assertDoesNotThrow(() -> listIngresses(domainNamespace)))
510+
.as(String.format("Test ingress %s was found in namespace %s", ingressName, domainNamespace))
511+
.withFailMessage(String.format("Ingress %s was not found in namespace %s", ingressName, domainNamespace))
512+
.contains(ingressName);
513+
LoggingFacade logger = getLogger();
514+
logger.info("ingress {0} was created in namespace {1}", ingressName, domainNamespace);
515+
516+
// check the ingress is ready to route the app to the server pod
517+
String curlCmd = "curl -g --silent --show-error --noproxy '*' http://" + hostAndPort
518+
+ "/weblogic/ready --write-out %{http_code} -o /dev/null";
519+
520+
logger.info("Executing curl command {0}", curlCmd);
521+
assertTrue(callWebAppAndWaitTillReady(curlCmd, 60));
522+
}
523+
463524
/**
464525
* Create an ingress for the domain with domainUid in the specified namespace.
465526
*

0 commit comments

Comments
 (0)