Skip to content

Commit 3dab5db

Browse files
committed
Merge branch 'develop' of https://github.com/oracle/weblogic-kubernetes-operator into feature/helm_operator_1_1
2 parents c6f780f + 6259044 commit 3dab5db

File tree

17 files changed

+602
-95
lines changed

17 files changed

+602
-95
lines changed

integration-tests/README.md

Lines changed: 293 additions & 0 deletions
Large diffs are not rendered by default.

integration-tests/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@
9191
<executable>${resource-integration-test}/setupenv.sh</executable>
9292
</configuration>
9393
</execution>
94+
<execution><!-- dump pod, domain, etc logs -->
95+
<id>statedump</id>
96+
<phase>post-integration-test</phase>
97+
<goals>
98+
<goal>exec</goal>
99+
</goals>
100+
<configuration>
101+
<executable>${resource-integration-test}/statedump.sh</executable>
102+
</configuration>
103+
</execution>
94104
</executions>
95105
</plugin>
96106
<plugin>

integration-tests/src/test/java/oracle/kubernetes/operator/BaseTest.java

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import java.nio.file.Files;
88
import java.nio.file.Paths;
99
import java.util.Properties;
10+
import java.util.logging.FileHandler;
1011
import java.util.logging.Logger;
12+
import java.util.logging.SimpleFormatter;
1113
import oracle.kubernetes.operator.utils.ExecCommand;
1214
import oracle.kubernetes.operator.utils.ExecResult;
1315
import oracle.kubernetes.operator.utils.TestUtils;
@@ -21,7 +23,7 @@ public class BaseTest {
2123

2224
private static String resultRoot = "";
2325
private static String pvRoot = "";
24-
// private static String resultDir = "";
26+
private static String resultDir = "";
2527
private static String userProjectsDir = "";
2628
private static String projectRoot = "";
2729
private static String username = "weblogic";
@@ -61,8 +63,8 @@ public static void initialize(String appPropsFile) throws Exception {
6163
if (System.getenv("LEASE_ID") != null) {
6264
leaseId = System.getenv("LEASE_ID");
6365
}
64-
// resultDir = resultRoot + "/acceptance_test_tmp";
65-
userProjectsDir = resultRoot + "/acceptance_test_tmp/user-projects";
66+
resultDir = resultRoot + "/acceptance_test_tmp";
67+
userProjectsDir = resultDir + "/user-projects";
6668
projectRoot = System.getProperty("user.dir") + "/..";
6769

6870
// BRANCH_NAME var is used in Jenkins job
@@ -72,6 +74,44 @@ public static void initialize(String appPropsFile) throws Exception {
7274
branchName = TestUtils.getGitBranchName();
7375
}
7476

77+
// for manual/local run, do cleanup
78+
if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) {
79+
80+
// delete k8s artifacts created if any, delete PV directories
81+
ExecResult clnResult = cleanup();
82+
if (clnResult.exitValue() != 0) {
83+
throw new RuntimeException(
84+
"FAILED: Command to call cleanup script failed " + clnResult.stderr());
85+
}
86+
logger.info(
87+
"Command to call cleanup script returned "
88+
+ clnResult.stdout()
89+
+ "\n"
90+
+ clnResult.stderr());
91+
}
92+
// create resultRoot, PVRoot, etc
93+
Files.createDirectories(Paths.get(resultRoot));
94+
Files.createDirectories(Paths.get(resultDir));
95+
Files.createDirectories(Paths.get(userProjectsDir));
96+
97+
// create file handler
98+
FileHandler fh = new FileHandler(resultDir + "/java_test_suite.out");
99+
SimpleFormatter formatter = new SimpleFormatter();
100+
fh.setFormatter(formatter);
101+
logger.addHandler(fh);
102+
logger.info("Adding file handler, logging to file at " + resultDir + "/java_test_suite.out");
103+
104+
// for manual/local run, create file handler, create PVROOT
105+
if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) {
106+
logger.info("Creating PVROOT " + pvRoot);
107+
Files.createDirectories(Paths.get(pvRoot));
108+
ExecResult result = ExecCommand.exec("chmod 777 " + pvRoot);
109+
if (result.exitValue() != 0) {
110+
throw new RuntimeException(
111+
"FAILURE: Couldn't change permissions for PVROOT " + result.stderr());
112+
}
113+
}
114+
75115
logger.info("RESULT_ROOT =" + resultRoot);
76116
logger.info("PV_ROOT =" + pvRoot);
77117
logger.info("userProjectsDir =" + userProjectsDir);
@@ -90,23 +130,6 @@ public static void initialize(String appPropsFile) throws Exception {
90130
logger.info(
91131
"Env var IMAGE_PULL_SECRET_WEBLOGIC " + System.getenv("IMAGE_PULL_SECRET_WEBLOGIC"));
92132
logger.info("Env var BRANCH_NAME " + System.getenv("BRANCH_NAME"));
93-
94-
// create resultRoot, PVRoot, etc
95-
Files.createDirectories(Paths.get(resultRoot));
96-
97-
if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) {
98-
logger.info("Creating PVROOT " + pvRoot);
99-
Files.createDirectories(Paths.get(pvRoot));
100-
ExecResult result = ExecCommand.exec("chmod 777 " + pvRoot);
101-
if (result.exitValue() != 0) {
102-
throw new RuntimeException(
103-
"FAILURE: Couldn't change permissions for PVROOT " + result.stderr());
104-
}
105-
}
106-
107-
// Files.createDirectories(Paths.get(resultDir));
108-
109-
Files.createDirectories(Paths.get(userProjectsDir));
110133
}
111134

112135
public static String getResultRoot() {

integration-tests/src/test/java/oracle/kubernetes/operator/ITFirstDomain.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import java.util.Properties;
88
import oracle.kubernetes.operator.utils.Domain;
9-
import oracle.kubernetes.operator.utils.ExecResult;
109
import oracle.kubernetes.operator.utils.Operator;
1110
import oracle.kubernetes.operator.utils.TestUtils;
1211
import org.junit.AfterClass;
@@ -49,22 +48,11 @@ public class ITFirstDomain extends BaseTest {
4948
*/
5049
@BeforeClass
5150
public static void staticPrepare() throws Exception {
52-
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
53-
logger.info("BEGIN");
54-
5551
// initialize test properties and create the directories
5652
initialize(appPropsFile);
5753

58-
// delete k8s artifacts created if any, delete PV directories
59-
if (System.getenv("WERCKER") == null && System.getenv("JENKINS") == null) {
60-
ExecResult result = cleanup();
61-
if (result.exitValue() != 0) {
62-
throw new RuntimeException(
63-
"FAILED: Command to call cleanup script failed " + result.stderr());
64-
}
65-
logger.info(
66-
"Command to call cleanup script returned " + result.stdout() + "\n" + result.stderr());
67-
}
54+
logger.info("+++++++++++++++++++++++++++++++++---------------------------------+");
55+
logger.info("BEGIN");
6856

6957
// renew lease at the begining for every test method, leaseId is set only for Wercker
7058
TestUtils.renewK8sClusterLease(getProjectRoot(), getLeaseId());

integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ public static String getExternalOperatorCertificate(String operatorNS, String us
271271
throws Exception {
272272

273273
File certFile =
274-
new File(
275-
TestUtils.class.getClassLoader().getResource(".").getFile() + "/../operator.cert.pem");
274+
new File(userProjectsDir + "/weblogic-operators/" + operatorNS + "/../operator.cert.pem");
276275

277276
StringBuffer opCertCmd = new StringBuffer("grep externalOperatorCert ");
278277
opCertCmd
@@ -304,8 +303,7 @@ public static String getExternalOperatorCertificate(String operatorNS, String us
304303
public static String getExternalOperatorKey(String operatorNS, String userProjectsDir)
305304
throws Exception {
306305
File keyFile =
307-
new File(
308-
TestUtils.class.getClassLoader().getResource(".").getFile() + "/../operator.key.pem");
306+
new File(userProjectsDir + "/weblogic-operators/" + operatorNS + "/../operator.key.pem");
309307

310308
StringBuffer opKeyCmd = new StringBuffer("grep externalOperatorKey ");
311309
opKeyCmd
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
4+
5+
6+
#
7+
# state_dump
8+
# - called at the end of a run
9+
# - places k8s logs, descriptions, etc in directory $RESULT_DIR/state-dump-logs
10+
# - calls archive.sh on RESULT_DIR locally, and on PV_ROOT via a job
11+
# - IMPORTANT: this method should not rely on exports
12+
#
13+
function state_dump {
14+
local RESULT_DIR="$RESULT_ROOT/acceptance_test_tmp"
15+
local PV_ROOT="$PV_ROOT"
16+
local PROJECT_ROOT="$PROJECT_ROOT"
17+
local SCRIPTPATH="$PROJECT_ROOT/src/integration-tests/bash"
18+
local LEASE_ID="$LEASE_ID"
19+
20+
if [ ! -d "$RESULT_DIR" ]; then
21+
echo State dump exiting early. RESULT_DIR \"$RESULT_DIR\" does not exist or is not a directory.
22+
return
23+
fi
24+
25+
local DUMP_DIR=$RESULT_DIR/state-dump-logs
26+
echo Starting state dump. Dumping state to directory ${DUMP_DIR}
27+
28+
mkdir -p ${DUMP_DIR}
29+
30+
# Test output is captured to ${TESTOUT} when run.sh is run stand-alone
31+
# if [ -f ${TESTOUT:-NoSuchFile.out} ]; then
32+
# echo Copying ${TESTOUT} to ${DUMP_DIR}/test_suite.out
33+
# cp ${TESTOUT} ${DUMP_DIR}/test_suite.out
34+
# fi
35+
36+
# dumping kubectl state
37+
# get domains is in its own command since this can fail if domain CRD undefined
38+
39+
echo Dumping kubectl gets to kgetmany.out and kgetdomains.out in ${DUMP_DIR}
40+
kubectl get all,crd,cm,pv,pvc,ns,roles,rolebindings,clusterroles,clusterrolebindings,secrets --show-labels=true --all-namespaces=true 2>&1 | tee ${DUMP_DIR}/kgetmany.out
41+
kubectl get domains --show-labels=true --all-namespaces=true 2>&1 | tee ${DUMP_DIR}/kgetdomains.out
42+
43+
# Get all pod logs and redirect/copy to files
44+
45+
set +x
46+
local namespaces="`kubectl get namespaces | egrep -v -e "(STATUS|kube)" | awk '{ print $1 }'`"
47+
set -x
48+
49+
local namespace
50+
echo "Copying logs and describes to pod-log.NAMESPACE.PODNAME and pod-describe.NAMESPACE.PODNAME in ${DUMP_DIR}"
51+
for namespace in $namespaces; do
52+
set +x
53+
local pods="`kubectl get pods -n $namespace --ignore-not-found | egrep -v -e "(STATUS)" | awk '{print $1}'`"
54+
set -x
55+
local pod
56+
for pod in $pods; do
57+
local logfile=${DUMP_DIR}/pod-log.${namespace}.${pod}
58+
local descfile=${DUMP_DIR}/pod-describe.${namespace}.${pod}
59+
kubectl log $pod -n $namespace 2>&1 | tee $logfile
60+
kubectl describe pod $pod -n $namespace 2>&1 | tee $descfile
61+
done
62+
done
63+
64+
# use a job to archive PV, /scratch mounts to PV_ROOT in the K8S cluster
65+
echo "Archiving pv directory using a kubernetes job. Look for it on k8s cluster in $PV_ROOT/acceptance_test_pv_archive"
66+
local outfile=${DUMP_DIR}/archive_pv_job.out
67+
$SCRIPTPATH/job.sh "/scripts/archive.sh /scratch/acceptance_test_pv /scratch/acceptance_test_pv_archive" 2>&1 | tee ${outfile}
68+
if [ "$?" = "0" ]; then
69+
echo Job complete.
70+
else
71+
echo Job failed. See ${outfile}.
72+
fi
73+
74+
if [ ! "$LEASE_ID" = "" ]; then
75+
# release the lease if we own it
76+
${SCRIPTPATH}/lease.sh -d "$LEASE_ID" 2>&1 | tee ${RESULT_DIR}/release_lease.out
77+
if [ "$?" = "0" ]; then
78+
echo Lease released.
79+
else
80+
echo Lease could not be released:
81+
cat /${RESULT_DIR}/release_lease.out
82+
fi
83+
fi
84+
85+
# now archive all the local test files
86+
$SCRIPTPATH/archive.sh "${RESULT_DIR}" "${RESULT_DIR}_archive"
87+
88+
echo Done with state dump
89+
}
90+
91+
export SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
92+
export PROJECT_ROOT="$SCRIPTPATH/../../../.."
93+
export RESULT_ROOT=${RESULT_ROOT:-/scratch/$USER/wl_k8s_test_results}
94+
export PV_ROOT=${PV_ROOT:-$RESULT_ROOT}
95+
echo "RESULT_ROOT$RESULT_ROOT PV_ROOT$PV_ROOT"
96+
97+
state_dump

kubernetes/create-weblogic-domain-inputs.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ loadBalancer: TRAEFIK
102102
# This defines the /location in the built-in Apache plugin configuration module for WebLogic
103103
loadBalancerAppPrepath: /
104104

105-
# Docker volume path for APACHE. By default, it is empty, which causes the volume mount be
106-
# disabled and, thereforem the built-in Apache plugin config be used.
107-
# Use this to provide your own Apache plugin configuration as needed; simply define this
108-
# path and put your own custom_mod_wl_apache.conf file under this path.
105+
# Docker volume path for APACHE.
106+
# By default, the path is empty, and therefore, the built-in default Apache plugin
107+
# configuration is used.
108+
# Use this to provide your own Apache plugin configuration as needed; simply define
109+
# this path and put your own custom_mod_wl_apache.conf file under this path.
110+
# If specified path does not exist, or customer_mod_wl_apache.conf file is missing
111+
# under the specified path, the create domain script will fail with a validation error.
109112
loadBalancerVolumePath:
110113

111114
# Boolean to indicate if the admin port is going to be exposed for APACHE. By default, it is false.

kubernetes/internal/create-weblogic-domain.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,20 @@ function createYamlFiles {
604604
enableLoadBalancerExposeAdminPortPrefix="${disabledPrefix}"
605605
fi
606606

607+
enableLoadBalancerVolumePathPrefix="${disabledPrefix}"
608+
apacheConfigFileName="custom_mod_wl_apache.conf"
607609
if [ ! -z "${loadBalancerVolumePath}" ]; then
608-
enableLoadBalancerVolumePathPrefix="${enabledPrefix}"
609-
sed -i -e "s:%LOAD_BALANCER_VOLUME_PATH%:${loadBalancerVolumePath}:g" ${apacheOutput}
610-
else
611-
enableLoadBalancerVolumePathPrefix="${disabledPrefix}"
610+
if [ ! -d ${loadBalancerVolumePath} ]; then
611+
echo -e "\nERROR - The specified loadBalancerVolumePath $loadBalancerVolumePath does not exist! \n"
612+
fail "Exiting due to a validation error"
613+
elif [ ! -f ${loadBalancerVolumePath}/${apacheConfigFileName} ]; then
614+
echo -e "\nERROR - The required file ${apacheConfigFileName} does not exist under the specified loadBalancerVolumePath $loadBalancerVolumePath! \n"
615+
fail "Exiting due to a validation error"
616+
else
617+
enableLoadBalancerVolumePathPrefix="${enabledPrefix}"
618+
sed -i -e "s:%LOAD_BALANCER_VOLUME_PATH%:${loadBalancerVolumePath}:g" ${apacheOutput}
619+
620+
fi
612621
fi
613622

614623
sed -i -e "s:%ENABLE_LOAD_BALANCER_EXPOSE_ADMIN_PORT%:${enableLoadBalancerExposeAdminPortPrefix}:g" ${apacheOutput}

kubernetes/src/test/java/oracle/kubernetes/operator/create/CreateDomainInputsValidationTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class CreateDomainInputsValidationTest {
5858
private static final String PARAM_LOAD_BALANCER = "loadBalancer";
5959
private static final String PARAM_LOAD_BALANCER_WEB_PORT = "loadBalancerWebPort";
6060
private static final String PARAM_LOAD_BALANCER_DASHBOARD_PORT = "loadBalancerDashboardPort";
61+
private static final String PARAM_LOAD_BALANCER_VOLUME_PATH = "loadBalancerVolumePath";
6162
private static final String PARAM_JAVA_OPTIONS = "javaOptions";
6263
private static final String PARAM_VERSION = "version";
6364

@@ -554,6 +555,26 @@ public void createDomain_with_invalidLoadBalancerDashboardPort_failsAndReturnsEr
554555
failsAndPrints(invalidIntegerParamValueError(PARAM_LOAD_BALANCER_DASHBOARD_PORT, val)));
555556
}
556557

558+
@Test
559+
public void createDomain_with_invalidLoadBalancerVolumePath_failsAndReturnsError()
560+
throws Exception {
561+
String val = "invalid-load-balancer-volume-path";
562+
assertThat(
563+
execCreateDomain(
564+
newInputs().loadBalancer(LOAD_BALANCER_APACHE).loadBalancerVolumePath(val)),
565+
failsAndPrints(missingDirectoryError(PARAM_LOAD_BALANCER_VOLUME_PATH, val)));
566+
}
567+
568+
public void createDomain_with_invalidLoadBalancerVolumePath_missingFile_failsAndReturnsError()
569+
throws Exception {
570+
String val = "/";
571+
assertThat(
572+
execCreateDomain(
573+
newInputs().loadBalancer(LOAD_BALANCER_APACHE).loadBalancerVolumePath(val)),
574+
failsAndPrints(
575+
missingFileError(PARAM_LOAD_BALANCER_VOLUME_PATH, val, "custom-mod-wl-apache.conf")));
576+
}
577+
557578
// TBD - shouldn't we allow empty java options?
558579
@Test
559580
public void createDomain_with_missingJavaOptions_failsAndReturnsError() throws Exception {
@@ -613,6 +634,14 @@ private String invalidRelatedParamValueError(
613634
return errorRegexp("Invalid.*" + param + ".*" + val + " with " + param2 + ".*" + val2);
614635
}
615636

637+
private String missingDirectoryError(String param, String val) {
638+
return errorRegexp(param + ".*" + val + ".*" + "does not exist!");
639+
}
640+
641+
private String missingFileError(String param, String val, String dir) {
642+
return errorRegexp(param + ".*" + val + ".*" + "does not exist under" + ".*" + dir + ".*");
643+
}
644+
616645
private String paramMissingError(String param) {
617646
return errorRegexp(param + ".*missing");
618647
}

0 commit comments

Comments
 (0)