Skip to content

Commit cc905d3

Browse files
Initial check-in (#2940)
Co-authored-by: [email protected] <[email protected]>
1 parent f2a2ea1 commit cc905d3

File tree

2 files changed

+77
-167
lines changed

2 files changed

+77
-167
lines changed

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

Lines changed: 51 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@
2323
import oracle.weblogic.kubernetes.annotations.IntegrationTest;
2424
import oracle.weblogic.kubernetes.annotations.Namespaces;
2525
import oracle.weblogic.kubernetes.logging.LoggingFacade;
26-
import org.junit.jupiter.api.AfterAll;
2726
import org.junit.jupiter.api.BeforeAll;
28-
import org.junit.jupiter.api.Disabled;
2927
import org.junit.jupiter.api.DisplayName;
30-
import org.junit.jupiter.api.MethodOrderer;
31-
import org.junit.jupiter.api.Order;
3228
import org.junit.jupiter.api.Test;
33-
import org.junit.jupiter.api.TestMethodOrder;
3429

3530
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT;
3631
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_SERVER_NAME_BASE;
@@ -50,6 +45,8 @@
5045
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.checkPodReadyAndServiceExists;
5146
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.scaleAndVerifyCluster;
5247
import static oracle.weblogic.kubernetes.utils.DomainUtils.createDomainAndVerify;
48+
import static oracle.weblogic.kubernetes.utils.OKDUtils.createRouteForOKD;
49+
import static oracle.weblogic.kubernetes.utils.OKDUtils.setTlsTerminationForRoute;
5350
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
5451
import static oracle.weblogic.kubernetes.utils.PodUtils.checkPodDoesNotExist;
5552
import static oracle.weblogic.kubernetes.utils.PodUtils.setPodAntiAffinity;
@@ -58,15 +55,13 @@
5855
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
5956
import static org.junit.jupiter.api.Assertions.assertNotNull;
6057
import static org.junit.jupiter.api.Assertions.assertTrue;
61-
import static org.junit.jupiter.api.Assertions.fail;
6258

6359
/**
64-
* The current class verifies various use cases related to domainNamespaceSelectionStrategy.
60+
* The current class verifies various use cases related to Dedicated
61+
* domainNamespaceSelectionStrategy applicable to Operator Helm Chart.
6562
* For more detail regarding the feature, please refer to
66-
* https://github.com/oracle/weblogic-kubernetes-operator/blob/develop/docs-source/content/
67-
* userguide/managing-operators/using-the-operator/using-helm.md#overall-operator-information.
63+
* https://oracle.github.io/weblogic-kubernetes-operator/userguide/managing-operators/using-helm/#weblogic-domain-management
6864
*/
69-
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
7065
@DisplayName("Test Operator and WebLogic domain with Dedicated set to true")
7166
@IntegrationTest
7267
class ItDedicatedMode {
@@ -78,11 +73,13 @@ class ItDedicatedMode {
7873
private static final String CRD_V16 = "domain-crd.yaml";
7974

8075
// domain constants
81-
private final String domainUid = "dedicated-domain-1";
76+
private final String domainUid = "dedicated-domain1";
8277
private final String clusterName = "cluster-1";
8378
private final int replicaCount = 2;
84-
private final String adminServerPodName = domainUid + "-" + ADMIN_SERVER_NAME_BASE;
85-
private final String managedServerPodPrefix = domainUid + "-" + MANAGED_SERVER_NAME_BASE;
79+
private final String adminServerPodName =
80+
domainUid + "-" + ADMIN_SERVER_NAME_BASE;
81+
private final String managedServerPodPrefix =
82+
domainUid + "-" + MANAGED_SERVER_NAME_BASE;
8683

8784
// operator constants
8885
private static HelmParams opHelmParams;
@@ -92,20 +89,22 @@ class ItDedicatedMode {
9289
private static LoggingFacade logger = null;
9390

9491
/**
95-
* Get namespaces for operator and domain2. Create CRD based on the k8s version.
96-
*
92+
* Get namespaces for operator and domain.
93+
* Create CRD based on the k8s version.
9794
* @param namespaces list of namespaces created by the IntegrationTestWatcher by the
9895
* JUnit engine parameter resolution mechanism.
9996
*/
10097
@BeforeAll
10198
public static void initAll(@Namespaces(2) List<String> namespaces) {
10299
logger = getLogger();
100+
103101
// get a unique operator namespace
104102
logger.info("Getting a unique namespace for operator");
105103
assertNotNull(namespaces.get(0), "Namespace list is null");
106104
opNamespace = namespaces.get(0);
107105

108-
// in the dedicated mode, the operator only manages domains in the operator's own namespace
106+
// in the dedicated mode, the operator only manages domains in the
107+
// operator's own namespace
109108
domain1Namespace = opNamespace;
110109

111110
// get a new unique domainNamespace
@@ -121,80 +120,66 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
121120
.chartDir(OPERATOR_CHART_DIR);
122121

123122
// delete existing CRD
124-
new Command()
123+
Command
125124
.withParams(new CommandParams()
126125
.command("kubectl delete crd domains.weblogic.oracle --ignore-not-found"))
127126
.execute();
128127

129128
// install CRD
130129
String createCrdCommand = "kubectl create -f " + ITTESTS_DIR + "/../kubernetes/crd/" + CRD_V16;
131130
logger.info("Creating CRD with command {0}", createCrdCommand);
132-
new Command()
131+
Command
133132
.withParams(new CommandParams().command(createCrdCommand))
134133
.execute();
135-
}
136134

137-
@AfterAll
138-
public void tearDownAll() {
135+
// Install the Operator in a ns (say op) with helm parameter
136+
// domainNamespaceSelectionStrategy set to Dedicated and set
137+
// domainNamespaces parameter to something other than Operator ns (say wls)
138+
logger.info("Installing and verifying operator");
139+
installAndVerifyOperator(opNamespace, opNamespace + "-sa",
140+
true, 0, opHelmParams, domainNamespaceSelectionStrategy,
141+
false, domain2Namespace);
142+
logger.info("Operator installed on namespace {0} and domainNamespaces set to {1} ", opNamespace, domain2Namespace);
143+
139144
}
140145

141146
/**
142-
* When installing the Operator via helm install,
143-
* set the Operator Helm Chart parameter domainNamespaceSelectionStrategy to Dedicated and
144-
* set domainNamespaces to something that is different from the operator's namespace.
145-
* Make sure that the domain which is not in the operator's target namespaces do not come up.
146-
* Install an Operator with a namespace and set domainNamespaces in a different namespace
147-
* from the Operator's namespace, also set domainNamespaceSelectionStrategy to Dedicated
148-
* for the Operator Helm Chart.
149-
* Verify the Operator is up and running.
150-
* Create WebLogic Domain in a namespace that is different from the Operator's namespace.
151-
* Verify that the domain does not come up.
147+
* Create WebLogic Domain in a namespace (say wls) that is different
148+
* from the Operator's namespace. Verify that the domain does not come up.
152149
*/
153150
@Test
154-
@Order(1)
155-
@DisplayName("Set domainNamespaceSelectionStrategy to Dedicated for the Operator Helm Chart and "
156-
+ "verify that a domain not deployed in operator's namespace doesn't come up")
151+
@DisplayName("Verify in Dedicated NamespaceSelectionStrategy domain on non-operator namespace does not started")
157152
void testDedicatedModeDiffNamespace() {
158-
// install and verify operator
159-
logger.info("Installing and verifying operator");
160-
installAndVerifyOperator(opNamespace, opNamespace + "-sa",
161-
true, 0, opHelmParams, domainNamespaceSelectionStrategy,
162-
false, domain2Namespace);
163-
164153
// create and verify the domain
165-
logger.info("Creating and verifying model in image domain");
154+
logger.info("Creating a domain in non-operator namespace {1}", domain2Namespace);
166155
createDomain(domain2Namespace);
167156
verifyDomainNotRunning(domain2Namespace);
157+
logger.info("WebLogic domain is not managed in non-operator namespace");
168158
}
169159

170160
/**
171-
* When installing the Operator via helm install,
172-
* set domainNamespaceSelectionStrategy to Dedicated for the Operator Helm Chart.
173-
* Make sure that the domains in the operator's target namespaces comes up.
174-
* Operator is installed in the test case testDedicatedModeDiffNamespace.
175-
* Create a WebLogic Domain with the same namespace as Operator's namespace.
176-
* Verify that the WebLogic domain whose namespace is same as Operator's namespace comes up.
161+
* Create WebLogic Domain in a namespace (say op) that is same as
162+
* Operator's namespace. Verify that the domain does come up and can be
163+
* scaled up using Operator
177164
*/
178165
@Test
179-
@Order(2)
180-
@DisplayName("Set domainNamespaceSelectionStrategy to Dedicated for the Operator Helm Chart and "
181-
+ "verify that the domain deployed in the operator's namespace comes up")
166+
@DisplayName("Verify in Dedicated NamespaceSelectionStrategy domain on operator namespace gets started")
182167
void testDedicatedModeSameNamespace() {
183-
// create and verify the domain
184-
logger.info("Creating and verifying model in image domain");
168+
169+
// This test uses the operator restAPI to scale the doamin.
170+
// To do this in OKD cluster, we need to expose the external service as
171+
// route and set tls termination to passthrough
172+
String opExternalSvc =
173+
createRouteForOKD("external-weblogic-operator-svc", opNamespace);
174+
// Patch the route just created to set tls termination to passthrough
175+
setTlsTerminationForRoute("external-weblogic-operator-svc", opNamespace);
176+
177+
logger.info("Creating a domain in perator namespace {1}", domain1Namespace);
185178
createDomain(domain1Namespace);
186179
verifyDomainRunning(domain1Namespace);
187-
}
180+
logger.info("WebLogic domain is managed in operator namespace Only");
188181

189-
/**
190-
* Test that when domainNamespaceSelectionStrategy is set to Dedicated for the Operator Helm Chart,
191-
* scaling up cluster-1 in domain1Namespace succeeds.
192-
*/
193-
@Test
194-
@Order(3)
195-
@DisplayName("Scale up cluster-1 in domain1Namespace and verify it succeeds")
196-
void testDedicatedModeSameNamespaceScale() {
197-
// scale the cluster and check domain can be managed from the operator
182+
// Scale up cluster-1 in domain1Namespace and verify it succeeds
198183
int externalRestHttpsPort = getServiceNodePort(opNamespace, "external-weblogic-operator-svc");
199184
logger.info("externalRestHttpsPort {0}", externalRestHttpsPort);
200185

@@ -206,84 +191,12 @@ void testDedicatedModeSameNamespaceScale() {
206191
"", null, null);
207192
}
208193

209-
/**
210-
* Test when domainNamespaceSelectionStrategy is set to Dedicated for the Operator Helm Chart and
211-
* the CRD with a lower than expected version is present, Operator fails with error
212-
* if it has no permission to overwrite the CRD.
213-
*/
214-
@Test
215-
@Order(4)
216-
@Disabled("Disable the test because the Operator has permission to overwrite the CRD")
217-
@DisplayName("Create a CRD with a lower than expected version and verify that Operator fails with error")
218-
void testDedicatedModeNlowerVersionCrd() {
219-
// delete existing CRD
220-
new Command()
221-
.withParams(new CommandParams()
222-
.command("kubectl delete crd domains.weblogic.oracle --ignore-not-found"))
223-
.execute();
224-
225-
// install a lower version of CRD, v2.6.0
226-
new Command()
227-
.withParams(new CommandParams()
228-
.command("kubectl create -f " + ITTESTS_DIR + "/../kubernetes/crd/domain-v1beta1-crdv7-260.yaml"))
229-
.execute();
230-
231-
try {
232-
// install latest version of operator and verify
233-
logger.info("Installing and verifying operator");
234-
installAndVerifyOperator(opNamespace, opNamespace + "-sa",
235-
false, 0, opHelmParams, domainNamespaceSelectionStrategy,
236-
false, domain2Namespace);
237-
238-
// we expect installAndVerifyOperator fails with a lower than expected version of CRD
239-
fail("Installing the Operator should fail with a lower than expected version of CRD");
240-
} catch (Exception ex) {
241-
logger.info("Installing the Operator with a lower than expected version of CRD failed as expected");
242-
} finally {
243-
// restore the test env
244-
uninstallOperatorAndVerify();
245-
}
246-
}
247-
248-
/**
249-
* Test when domainNamespaceSelectionStrategy is set to Dedicated for the Operator Helm Chart and
250-
* the CRD is not present or is deleted, Operator fails with error if it has no permission to create the CRD.
251-
*/
252-
@Test
253-
@Order(5)
254-
@Disabled("Disable the test because the Operator has permission to create the CRD")
255-
@DisplayName("Delete the CRD and verify that Operator fails with error")
256-
void testDedicatedModeNoCrd() {
257-
// delete existing CRD
258-
logger.info("Delete existing CRD");
259-
new Command()
260-
.withParams(new CommandParams()
261-
.command("kubectl delete crd domains.weblogic.oracle --ignore-not-found"))
262-
.execute();
263-
264-
try {
265-
// install and verify operator
266-
logger.info("Installing and verifying operator");
267-
installAndVerifyOperator(opNamespace, opNamespace + "-sa",
268-
false, 0, opHelmParams, domainNamespaceSelectionStrategy,
269-
false, domain2Namespace);
270-
271-
// we expect installAndVerifyOperator fails when the CRD misses
272-
fail("Installing the Operator should fail when the CRD misses");
273-
} catch (Exception ex) {
274-
logger.info("Installing the Operator failed as expected when the CRD misses");
275-
} finally {
276-
// restore the test env
277-
uninstallOperatorAndVerify();
278-
}
279-
}
280-
281194
private void createDomain(String domainNamespace) {
282195
// create secret for admin credentials
283196
logger.info("Create secret for admin credentials");
284197
String adminSecretName = "weblogic-credentials";
285-
assertDoesNotThrow(() -> createSecretWithUsernamePassword(adminSecretName,
286-
domainNamespace, ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT),
198+
assertDoesNotThrow(() -> createSecretWithUsernamePassword(adminSecretName, domainNamespace,
199+
ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT),
287200
String.format("create secret for admin credentials failed for %s", adminSecretName));
288201

289202
// create encryption secret
@@ -347,7 +260,7 @@ private void createDomainCrAndVerify(String domainNamespace,
347260
.runtimeEncryptionSecret(encryptionSecretName))));
348261
setPodAntiAffinity(domain);
349262
// create model in image domain
350-
logger.info("Creating model in image domain {0} in namespace {1} using docker image {2}",
263+
logger.info("Creating mii domain {0} in namespace {1} using image {2}",
351264
domainUid, domainNamespace, miiImage);
352265
createDomainAndVerify(domain, domainNamespace);
353266
}
@@ -396,7 +309,7 @@ private void uninstallOperatorAndVerify() {
396309
String.format("Delete service acct %s failed in namespace %s", opServiceAccount, opNamespace));
397310

398311
// delete secret/ocir-secret
399-
new Command()
312+
Command
400313
.withParams(new CommandParams()
401314
.command("kubectl delete secret/ocir-secret -n " + opNamespace + " --ignore-not-found"))
402315
.execute();

0 commit comments

Comments
 (0)