Skip to content

Commit c0136fe

Browse files
authored
backport from 33 (#2923)
1 parent adefdba commit c0136fe

File tree

3 files changed

+168
-38
lines changed

3 files changed

+168
-38
lines changed

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

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package oracle.weblogic.kubernetes;
55

6+
import java.nio.file.Path;
67
import java.time.OffsetDateTime;
78
import java.util.ArrayList;
89
import java.util.HashMap;
@@ -39,6 +40,9 @@
3940
import org.junit.jupiter.api.Test;
4041
import org.junit.jupiter.api.TestMethodOrder;
4142

43+
import static java.nio.file.Files.createDirectories;
44+
import static java.nio.file.Files.write;
45+
import static java.nio.file.Paths.get;
4246
import static java.util.concurrent.TimeUnit.MINUTES;
4347
import static java.util.concurrent.TimeUnit.SECONDS;
4448
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT;
@@ -54,12 +58,14 @@
5458
import static oracle.weblogic.kubernetes.TestConstants.OPERATOR_CHART_DIR;
5559
import static oracle.weblogic.kubernetes.TestConstants.OPERATOR_RELEASE_NAME;
5660
import static oracle.weblogic.kubernetes.TestConstants.OPERATOR_SERVICE_NAME;
61+
import static oracle.weblogic.kubernetes.TestConstants.RESULTS_ROOT;
5762
import static oracle.weblogic.kubernetes.TestConstants.WLS_DOMAIN_TYPE;
5863
import static oracle.weblogic.kubernetes.actions.TestActions.createServiceAccount;
5964
import static oracle.weblogic.kubernetes.actions.TestActions.deleteDomainCustomResource;
6065
import static oracle.weblogic.kubernetes.actions.TestActions.deleteSecret;
6166
import static oracle.weblogic.kubernetes.actions.TestActions.deleteServiceAccount;
6267
import static oracle.weblogic.kubernetes.actions.TestActions.getOperatorImageName;
68+
import static oracle.weblogic.kubernetes.actions.TestActions.getOperatorPodName;
6369
import static oracle.weblogic.kubernetes.actions.TestActions.getPodCreationTimestamp;
6470
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
6571
import static oracle.weblogic.kubernetes.actions.TestActions.helmValuesToString;
@@ -89,6 +95,7 @@
8995
import static oracle.weblogic.kubernetes.utils.SecretUtils.createExternalRestIdentitySecret;
9096
import static oracle.weblogic.kubernetes.utils.SecretUtils.createSecretWithUsernamePassword;
9197
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
98+
import static org.apache.commons.io.FileUtils.deleteDirectory;
9299
import static org.assertj.core.api.Assertions.assertThat;
93100
import static org.awaitility.Awaitility.with;
94101
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -110,6 +117,7 @@ class ItUsabilityOperatorHelmChart {
110117

111118
private static String opNamespace = null;
112119
private static String op2Namespace = null;
120+
private static String op3Namespace = null;
113121
private static String domain1Namespace = null;
114122
private static String domain2Namespace = null;
115123
private static String domain3Namespace = null;
@@ -147,7 +155,7 @@ class ItUsabilityOperatorHelmChart {
147155
* JUnit engine parameter resolution mechanism
148156
*/
149157
@BeforeAll
150-
public static void initAll(@Namespaces(6) List<String> namespaces) {
158+
public static void initAll(@Namespaces(7) List<String> namespaces) {
151159
logger = getLogger();
152160
// get a unique operator namespace
153161
logger.info("Getting a unique namespace for operator");
@@ -178,6 +186,11 @@ public static void initAll(@Namespaces(6) List<String> namespaces) {
178186
logger.info("Getting a unique namespace for operator 2");
179187
assertNotNull(namespaces.get(5), "Namespace list is null");
180188
op2Namespace = namespaces.get(5);
189+
190+
// get a unique operator 3 namespace
191+
logger.info("Getting a unique namespace for operator 3");
192+
assertNotNull(namespaces.get(6), "Namespace list is null");
193+
op3Namespace = namespaces.get(6);
181194
}
182195

183196
@AfterAll
@@ -797,15 +810,15 @@ void testTwoDomainsInSameNameSpaceOnOperator() {
797810

798811
String opReleaseName = OPERATOR_RELEASE_NAME;
799812
HelmParams op1HelmParams = new HelmParams().releaseName(opReleaseName)
800-
.namespace(op2Namespace)
813+
.namespace(op3Namespace)
801814
.chartDir(OPERATOR_CHART_DIR);
802815
try {
803816
// install operator
804-
String opServiceAccount = op2Namespace + "-sa";
805-
HelmParams opHelmParams = installAndVerifyOperator(op2Namespace, opServiceAccount, true,
806-
0, op1HelmParams, domain4Namespace).getHelmParams();
817+
String opServiceAccount = op3Namespace + "-sa";
818+
HelmParams opHelmParams = installAndVerifyOperator(op3Namespace, opServiceAccount, true,
819+
0, "FINE", op1HelmParams, domain4Namespace).getHelmParams();
807820
assertNotNull(opHelmParams, "Can't install operator");
808-
int externalRestHttpsPort = getServiceNodePort(op2Namespace, "external-weblogic-operator-svc");
821+
int externalRestHttpsPort = getServiceNodePort(op3Namespace, "external-weblogic-operator-svc");
809822
assertTrue(externalRestHttpsPort != -1,
810823
"Could not get the Operator external service node port");
811824
logger.info("externalRestHttpsPort {0}", externalRestHttpsPort);
@@ -818,7 +831,7 @@ void testTwoDomainsInSameNameSpaceOnOperator() {
818831
"can't start or verify domain5 in namespace " + domain4Namespace);
819832

820833
assertTrue(scaleClusterWithRestApi(domain4Uid, clusterName,3,
821-
externalRestHttpsPort,op2Namespace, opServiceAccount),
834+
externalRestHttpsPort,op3Namespace, opServiceAccount),
822835
"Domain4 " + domain4Namespace + " scaling operation failed");
823836
String managedServerPodName1 = domain4Uid + managedServerPrefix + 3;
824837
logger.info("Checking that the managed server pod {0} exists in namespace {1}",
@@ -829,21 +842,21 @@ void testTwoDomainsInSameNameSpaceOnOperator() {
829842
logger.info("Domain4 scaled to 3 servers");
830843

831844
assertTrue(scaleClusterWithRestApi(domain5Uid, clusterName,3,
832-
externalRestHttpsPort,op2Namespace, opServiceAccount),
833-
"Domain2 " + domain4Namespace + " scaling operation failed");
845+
externalRestHttpsPort,op3Namespace, opServiceAccount),
846+
"Domain5 " + domain4Namespace + " scaling operation failed");
834847
String managedServerPodName2 = domain5Uid + managedServerPrefix + 3;
835848
logger.info("Checking that the managed server pod {0} exists in namespace {1}",
836849
managedServerPodName2, domain4Namespace);
837850
assertDoesNotThrow(() ->
838851
checkPodExists(managedServerPodName2, domain5Uid, domain4Namespace),
839-
"operator failed to manage domain2, scaling was not succeeded");
852+
"operator failed to manage domain5, scaling was not succeeded");
840853

841-
logger.info("Domain4 scaled to 3 servers");
854+
logger.info("Domain5 scaled to 3 servers");
842855

843856
assertDoesNotThrow(() ->
844857
TestActions.scaleClusterWithScalingActionScript(clusterName, domain4Uid, domain4Namespace,
845858
"/u01/domains/" + domain4Uid, "scaleDown", 1,
846-
op2Namespace,opServiceAccount),
859+
op3Namespace, opServiceAccount),
847860
"scaling was not succeeded");
848861
assertDoesNotThrow(() ->
849862
checkPodDoesNotExist(managedServerPodName1, domain4Uid, domain4Namespace),
@@ -852,17 +865,36 @@ void testTwoDomainsInSameNameSpaceOnOperator() {
852865
assertDoesNotThrow(() ->
853866
TestActions.scaleClusterWithScalingActionScript(clusterName, domain5Uid, domain4Namespace,
854867
"/u01/domains/" + domain5Uid, "scaleDown", 1,
855-
op2Namespace,opServiceAccount),
868+
op3Namespace, opServiceAccount),
856869
" scaling via scalingAction.sh script was not succeeded for domain5");
857870

858871
assertDoesNotThrow(() ->
859872
checkPodDoesNotExist(managedServerPodName2, domain5Uid, domain4Namespace),
860873
" scaling via scalingAction.sh script was not succeeded for domain5");
861874
logger.info("Domain5 scaled to 2 servers");
862875
} finally {
876+
try {
877+
String operatorPodName =
878+
assertDoesNotThrow(() -> getOperatorPodName(OPERATOR_RELEASE_NAME, op3Namespace),
879+
"Can't get operator's pod name");
880+
Path logDirPath = get(RESULTS_ROOT, this.getClass().getSimpleName());
881+
assertDoesNotThrow(() -> deleteDirectory(logDirPath.toFile()),
882+
"Delete directory failed");
883+
assertDoesNotThrow(() -> createDirectories(logDirPath),
884+
"Create directory failed");
885+
String podLog = assertDoesNotThrow(() -> TestActions.getPodLog(operatorPodName, op3Namespace));
886+
Path pathToLog =
887+
get(RESULTS_ROOT, this.getClass().getSimpleName(),
888+
"/TwoDomainsInSameNameSpaceOnOperatorOpLog" + op3Namespace + ".log");
889+
890+
assertDoesNotThrow(() -> write(pathToLog, podLog.getBytes()),
891+
"Can't write to file " + pathToLog);
892+
} catch (Exception ex) {
893+
logger.info("Failed to collect operator log");
894+
}
863895
uninstallOperator(op1HelmParams);
864-
deleteSecret(OCIR_SECRET_NAME,op2Namespace);
865-
cleanUpSA(op2Namespace);
896+
deleteSecret(OCIR_SECRET_NAME, op3Namespace);
897+
cleanUpSA(op3Namespace);
866898
}
867899
}
868900

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/Domain.java

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import static oracle.weblogic.kubernetes.assertions.impl.ClusterRole.clusterRoleExists;
5555
import static oracle.weblogic.kubernetes.assertions.impl.ClusterRoleBinding.clusterRoleBindingExists;
5656
import static oracle.weblogic.kubernetes.assertions.impl.RoleBinding.roleBindingExists;
57+
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.testUntil;
5758
import static oracle.weblogic.kubernetes.utils.ThreadSafeLogger.getLogger;
5859
import static org.awaitility.Awaitility.with;
5960
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -986,37 +987,52 @@ private static void scaleViaScript(String opNamespace, String domainNamespace,
986987
.append(" --scaling_size=")
987988
.append(scalingSize)
988989
.append(" --kubernetes_master=")
989-
.append("https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT");
990+
.append("https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_SERVICE_PORT")
991+
.append(" 2>> /u01/scalingAction.out ");
990992

991993

992994
String commandToExecuteInsidePod = scalingCommand.toString();
995+
ExecResult result = null;
996+
try {
997+
result = assertDoesNotThrow(() -> Kubernetes.exec(adminPod, null, true,
998+
"/bin/sh", "-c", commandToExecuteInsidePod),
999+
String.format("Could not execute the command %s in pod %s, namespace %s",
1000+
commandToExecuteInsidePod, adminPod.getMetadata().getName(), domainNamespace));
1001+
logger.info("Command {0} returned with exit value {1}, stderr {2}, stdout {3}",
1002+
commandToExecuteInsidePod, result.exitValue(), result.stderr(), result.stdout());
1003+
} catch (Error err) {
1004+
logger.info("Command {0} returned with exit value {1}, stderr {2}, stdout {3}",
1005+
commandToExecuteInsidePod, result.exitValue(), result.stderr(), result.stdout());
1006+
copyScalingActionLogs(domainUid, domainNamespace, adminPod);
1007+
throw err;
9931008

994-
ExecResult result = assertDoesNotThrow(() -> Kubernetes.exec(adminPod, null, true,
995-
"/bin/sh", "-c", commandToExecuteInsidePod),
996-
String.format("Could not execute the command %s in pod %s, namespace %s",
997-
commandToExecuteInsidePod, adminPod.getMetadata().getName(), domainNamespace));
998-
logger.info("Command {0} returned with exit value {1}, stderr {2}, stdout {3}",
999-
commandToExecuteInsidePod, result.exitValue(), result.stderr(), result.stdout());
1000-
1001-
// copy scalingAction.log to local
1002-
withStandardRetryPolicy
1003-
.conditionEvaluationListener(
1004-
condition -> logger.info("Copying scalingAction.log from admin server pod, waiting for success "
1005-
+ "(elapsed time {0}ms, remaining time {1}ms)",
1006-
condition.getElapsedTimeInMS(),
1007-
condition.getRemainingTimeInMS()))
1008-
.until(() -> {
1009-
return copyFileFromPod(domainNamespace, adminPod.getMetadata().getName(), null,
1010-
domainHomeLocation + "/bin/scripts/scalingAction.log",
1011-
Paths.get(RESULTS_ROOT + "/" + domainUid + "-scalingAction.log"));
1012-
});
1009+
}
1010+
copyScalingActionLogs(domainUid, domainNamespace, adminPod);
10131011

10141012
// checking for exitValue 0 for success fails sometimes as k8s exec api returns non-zero exit value even on success,
10151013
// so checking for exitValue non-zero and stderr not empty for failure, otherwise its success
10161014

10171015
assertFalse(result.exitValue() != 0 && result.stderr() != null && !result.stderr().isEmpty(),
1018-
String.format("Command %s failed with exit value %s, stderr %s, stdout %s",
1019-
commandToExecuteInsidePod, result.exitValue(), result.stderr(), result.stdout()));
1016+
String.format("Command %s failed with exit value %s, stderr %s, stdout %s",
1017+
commandToExecuteInsidePod, result.exitValue(), result.stderr(), result.stdout()));
1018+
1019+
}
10201020

1021+
private static void copyScalingActionLogs(String domainUid, String domainNamespace, V1Pod adminPod) {
1022+
LoggingFacade logger = getLogger();
1023+
// copy scalingAction.log to result dir
1024+
testUntil(
1025+
() -> copyFileFromPod(domainNamespace, adminPod.getMetadata().getName(), null,
1026+
"/u01/scalingAction.log",
1027+
Paths.get(RESULTS_ROOT + "/" + domainUid + "-scalingAction.log")),
1028+
logger,
1029+
"Copying scalingAction.log from admin server pod");
1030+
// copy scalingAction.out to result dir
1031+
testUntil(
1032+
() -> copyFileFromPod(domainNamespace, adminPod.getMetadata().getName(), null,
1033+
"/u01/scalingAction.out",
1034+
Paths.get(RESULTS_ROOT + "/" + domainUid + "-scalingAction.out")),
1035+
logger,
1036+
"Copying scalingAction.out from admin server pod");
10211037
}
10221038
}

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

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ public static OperatorParams installAndVerifyOperator(String opNamespace,
126126
* @param opServiceAccount the service account name for operator
127127
* @param withRestAPI whether to use REST API
128128
* @param externalRestHttpsPort the node port allocated for the external operator REST HTTPS interface
129-
* @param elkIntegrationEnabled boolean value indicating elk enabled or not
130129
* @param domainNamespace the list of the domain namespaces which will be managed by the operator
131130
* @return the operator Helm installation parameters
132131
*/
@@ -145,6 +144,41 @@ public static OperatorParams installAndVerifyOperator(String opNamespace,
145144

146145
}
147146

147+
/**
148+
* Install WebLogic operator and wait up to five minutes until the operator pod is ready.
149+
*
150+
* @param opNamespace the operator namespace in which the operator will be installed
151+
* @param opServiceAccount the service account name for operator
152+
* @param withRestAPI whether to use REST API
153+
* @param externalRestHttpsPort the node port allocated for the external operator REST HTTPS interface
154+
* @param opHelmParams the Helm parameters to install operator
155+
* @param loggingLevel operator logging level
156+
* @param domainNamespace the list of the domain namespaces which will be managed by the operator
157+
* @return the operator Helm installation parameters
158+
*/
159+
public static OperatorParams installAndVerifyOperator(String opNamespace,
160+
String opServiceAccount,
161+
boolean withRestAPI,
162+
int externalRestHttpsPort,
163+
String loggingLevel,
164+
HelmParams opHelmParams,
165+
String... domainNamespace) {
166+
167+
return installAndVerifyOperator(opNamespace,
168+
opServiceAccount,
169+
withRestAPI,
170+
externalRestHttpsPort,
171+
opHelmParams,
172+
false,
173+
null,
174+
null,
175+
false,
176+
loggingLevel,
177+
-1,
178+
-1,
179+
domainNamespace);
180+
}
181+
148182
/**
149183
* Install WebLogic operator and wait up to five minutes until the operator pod is ready.
150184
*
@@ -247,6 +281,53 @@ public static OperatorParams installAndVerifyOperator(String opNamespace,
247281
int domainPresenceFailureRetryMaxCount,
248282
int domainPresenceFailureRetrySeconds,
249283
String... domainNamespace) {
284+
return installAndVerifyOperator(opNamespace,
285+
opServiceAccount,
286+
withRestAPI,
287+
externalRestHttpsPort,
288+
opHelmParams,
289+
elkIntegrationEnabled,
290+
domainNamespaceSelectionStrategy,
291+
domainNamespaceSelector,
292+
enableClusterRoleBinding,
293+
"INFO",
294+
domainPresenceFailureRetryMaxCount,
295+
domainPresenceFailureRetrySeconds,
296+
domainNamespace);
297+
}
298+
299+
/**
300+
* Install WebLogic operator and wait up to five minutes until the operator pod is ready.
301+
*
302+
* @param opNamespace the operator namespace in which the operator will be installed
303+
* @param opServiceAccount the service account name for operator
304+
* @param withRestAPI whether to use REST API
305+
* @param externalRestHttpsPort the node port allocated for the external operator REST HTTPS interface
306+
* @param opHelmParams the Helm parameters to install operator
307+
* @param elkIntegrationEnabled true to enable ELK Stack, false otherwise
308+
* @param domainNamespaceSelectionStrategy SelectLabel, RegExp or List, value to tell the operator
309+
* how to select the set of namespaces that it will manage
310+
* @param domainNamespaceSelector the label or expression value to manage namespaces
311+
* @param enableClusterRoleBinding operator cluster role binding
312+
* @param loggingLevel logging level of operator
313+
* @param domainPresenceFailureRetryMaxCount the number of introspector job retries for a Domain
314+
* @param domainPresenceFailureRetrySeconds the interval in seconds between these retries
315+
* @param domainNamespace the list of the domain namespaces which will be managed by the operator
316+
* @return the operator Helm installation parameters
317+
*/
318+
public static OperatorParams installAndVerifyOperator(String opNamespace,
319+
String opServiceAccount,
320+
boolean withRestAPI,
321+
int externalRestHttpsPort,
322+
HelmParams opHelmParams,
323+
boolean elkIntegrationEnabled,
324+
String domainNamespaceSelectionStrategy,
325+
String domainNamespaceSelector,
326+
boolean enableClusterRoleBinding,
327+
String loggingLevel,
328+
int domainPresenceFailureRetryMaxCount,
329+
int domainPresenceFailureRetrySeconds,
330+
String... domainNamespace) {
250331
LoggingFacade logger = getLogger();
251332

252333
// Create a service account for the unique opNamespace
@@ -277,6 +358,7 @@ public static OperatorParams installAndVerifyOperator(String opNamespace,
277358
.helmParams(opHelmParams)
278359
.imagePullSecrets(secretNameMap)
279360
.domainNamespaces(Arrays.asList(domainNamespace))
361+
.javaLoggingLevel(loggingLevel)
280362
.serviceAccount(opServiceAccount);
281363

282364
if (domainNamespaceSelectionStrategy != null) {

0 commit comments

Comments
 (0)