Skip to content

Commit b538628

Browse files
authored
Merge pull request #86 from oracle/feature/integration-tests
Port integration tests
2 parents d6eefca + d8109bd commit b538628

19 files changed

+2957
-32
lines changed

build/weblogic-job.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: weblogic-job
5+
namespace: default
6+
spec:
7+
template:
8+
metadata:
9+
spec:
10+
restartPolicy: Never
11+
containers:
12+
- name: weblogic-job
13+
image: store/oracle/weblogic:12.2.1.3
14+
imagePullPolicy: IfNotPresent
15+
volumeMounts:
16+
- mountPath: /scratch
17+
name: scratch
18+
command: ["/bin/bash"]
19+
args: %ARGS%
20+
imagePullSecrets:
21+
- name: docker-store
22+
volumes:
23+
- name: scratch
24+
hostPath:
25+
path: %HOST_PATH%

kubernetes/create-operator-inputs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ image: container-registry.oracle.com/middleware/weblogic-kubernetes-operator:lat
1919
# The image pull policy for the operator docker image.
2020
imagePullPolicy: IfNotPresent
2121

22+
# Name of the Kubernetes secret to access the registry containing the operator Docker image
23+
# The presence of the secret will be validated when this parameter is enabled.
24+
#imagePullSecretName: docker-registry-secret
25+
2226
# Options for externally exposing the operator REST https interface
2327
# (i.e. outside of the Kubernetes cluster). Valid values are:
2428
#

kubernetes/create-weblogic-operator.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ function initialize {
145145

146146
validateExternalRest
147147

148+
validateImagePullSecretName
149+
148150
failIfValidationErrors
149151
}
150152

@@ -162,6 +164,47 @@ function validateRemoteDebugNodePort {
162164
fi
163165
}
164166

167+
#
168+
# Function to validate the image pull secret name
169+
#
170+
function validateImagePullSecretName {
171+
IMAGE_PULL_SECRET_EXISTS=false
172+
if [ ! -z ${imagePullSecretName} ]; then
173+
IMAGE_PULL_SECRET_EXISTS=true
174+
imagePullSecretPrefix=""
175+
else
176+
# Set name blank when not specified, and comment out the yaml
177+
imagePullSecretName=""
178+
imagePullSecretPrefix="#"
179+
fi
180+
}
181+
182+
#
183+
# Function to validate the image pull secret exists
184+
#
185+
function validateImagePullSecret {
186+
187+
# The kubernetes secret for pulling images from the docker store is optional.
188+
# If it was specified, make sure it exists.
189+
if [ "${IMAGE_PULL_SECRET_EXISTS}" = true ]; then
190+
validateSecretExists ${imagePullSecretName} ${namespace}
191+
failIfValidationErrors
192+
fi
193+
}
194+
195+
#
196+
# Function to validate a kubernetes secret exists
197+
# $1 - the name of the secret
198+
# $2 - namespace
199+
function validateSecretExists {
200+
# Verify the secret exists
201+
echo "Checking to see if the secret ${1} exists in namespace ${2}"
202+
local SECRET=`kubectl get secret ${1} -n ${2} | grep ${1} | wc | awk ' { print $1; }'`
203+
if [ "${SECRET}" != "1" ]; then
204+
validationError "The registry secret ${1} was not found in namespace ${2}"
205+
fi
206+
}
207+
165208
#
166209
# Function to validate that the java logging level has been properly configured
167210
#
@@ -357,6 +400,8 @@ function createYamlFiles {
357400
sed -i -e "s|%ACCOUNT_NAME%|$serviceAccount|g" ${oprOutput}
358401
sed -i -e "s|%IMAGE%|$image|g" ${oprOutput}
359402
sed -i -e "s|%IMAGE_PULL_POLICY%|$imagePullPolicy|g" ${oprOutput}
403+
sed -i -e "s:%DOCKER_STORE_REGISTRY_SECRET%:${imagePullSecretName}:g" ${oprOutput}
404+
sed -i -e "s:%IMAGE_PULL_SECRET_PREFIX%:${imagePullSecretPrefix}:g" ${oprOutput}
360405
sed -i -e "s|%EXTERNAL_OPERATOR_SERVICE_PREFIX%|$externalOperatorServicePrefix|g" ${oprOutput}
361406
sed -i -e "s|%EXTERNAL_REST_HTTPS_PORT%|$externalRestHttpsPort|g" ${oprOutput}
362407
sed -i -e "s|%EXTERNAL_DEBUG_HTTP_PORT%|$externalDebugHttpPort|g" ${oprOutput}

kubernetes/internal/weblogic-operator-template.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ spec:
9999
%ELK_INTEGRATION_PREFIX%- name: log-dir
100100
%ELK_INTEGRATION_PREFIX% persistentVolumeClaim:
101101
%ELK_INTEGRATION_PREFIX% claimName: elk-pvc
102-
# Update the imagePullSecrets with the name of your Kubernetes secret containing
103-
# your credentials for the Oracle Container Registry.
104-
imagePullSecrets:
105-
- name: my-registry-secret
102+
%IMAGE_PULL_SECRET_PREFIX%imagePullSecrets:
103+
%IMAGE_PULL_SECRET_PREFIX%- name: %DOCKER_STORE_REGISTRY_SECRET%
106104

107105
---
108106
%EXTERNAL_OPERATOR_SERVICE_PREFIX%apiVersion: v1

pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,6 @@
277277
<artifactId>build-helper-maven-plugin</artifactId>
278278
<version>3.0.0</version>
279279
<executions>
280-
<execution>
281-
<id>add-main-source</id>
282-
<phase>generate-sources</phase>
283-
<goals>
284-
<goal>add-source</goal>
285-
</goals>
286-
<configuration>
287-
<sources>
288-
<source>${src-generated-swagger}</source>
289-
<source>${project.build.sourceDirectory}</source>
290-
<source>${basedir}/src/build/java</source>
291-
</sources>
292-
</configuration>
293-
</execution>
294280
<execution>
295281
<id>add-test-source</id>
296282
<phase>generate-test-resources</phase>

src/integration-tests/bash/cleanup.sh

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
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+
# This script does a best-effort k8s delete of run.sh integration test k8s artifacts.
6+
# It double checks whether its deletes are succeeding, and if not reports an "Error" and continue regardless.
7+
#
8+
# Note that it deletes elk and WL domain PV directories (as root).
9+
10+
DOMAINS=(domain1 domain2 domain3 domain4)
11+
DOMAIN_NAMESPACES=(default default test test2)
12+
DCOUNT=${#DOMAINS[@]}
13+
14+
OPER_NAMESPACES=(weblogic-operator weblogic-operator-2)
15+
OCOUNT=${#OPER_NAMESPACES[@]}
16+
17+
echo @@ Cleaning up $OCOUNT operators
18+
19+
export HOST_PATH=${HOST_PATH:-/scratch}
20+
21+
SCRIPTPATH="$( cd "$(dirname "$0")" > /dev/null 2>&1 ; pwd -P )"
22+
export PROJECT_ROOT="$SCRIPTPATH/../../.."
23+
export RESULT_ROOT=${RESULT_ROOT:-/scratch/k8s_dir}
24+
export RESULT_DIR="$RESULT_ROOT/acceptance_test_tmp"
25+
export HOST_DIR="/scratch/k8s_dir/acceptance_test_tmp"
26+
mkdir -m 777 -p $RESULT_DIR
27+
28+
function waitForDelete {
29+
maxwaitsecs=120
30+
echo "@@ Waiting up to $maxwaitsecs seconds for ${1:?} that contain string ${2:?} to delete."
31+
32+
artcount=1
33+
mstart=`date +%s`
34+
while : ; do
35+
kubectl get $1 --show-labels=true --all-namespaces=true > $RESULT_DIR/kinv.out.tmp 2>&1
36+
egrep -e "($2)" $RESULT_DIR/kinv.out.tmp > $RESULT_DIR/kinv.out2.tmp
37+
artcount="`cat $RESULT_DIR/kinv.out2.tmp | wc -l`"
38+
mnow=`date +%s`
39+
echo
40+
echo "@@ Waiting for $artcount artifacts to delete. Wait time $((mnow - mstart)) seconds (max=$maxwaitsecs). Waiting for:"
41+
cat $RESULT_DIR/kinv.out2.tmp
42+
if [ $((artcount)) -eq 0 ]; then
43+
echo "@@ No artifacts found."
44+
break
45+
fi
46+
if [ $((mnow - mstart)) -gt $((maxwaitsecs)) ]; then
47+
echo "@@ Error: $maxwaitsecs seconds reached. Giving up."
48+
break
49+
fi
50+
sleep 5
51+
done
52+
}
53+
54+
for ((i=0;i<DCOUNT;i++)); do
55+
curdomain=${DOMAINS[i]}
56+
curns=${DOMAIN_NAMESPACES[i]}
57+
58+
echo @@ Deleting domain ${curdomain} in namespace $curn
59+
kubectl -n $curns delete domain $curdomain --ignore-not-found=true
60+
61+
# Give operator some time to digest the domain deletion
62+
sleep 3
63+
64+
echo @@ Deleting create domain ${curdomain} job in namespace $curns
65+
kubectl -n $curns delete job domain-${curdomain}-job --ignore-not-found=true
66+
67+
echo @@ Deleting domain pv and pvc for domain ${curdomain} in namespace $curns
68+
kubectl delete pv ${curdomain}-pv --ignore-not-found=true
69+
kubectl -n $curns delete pvc ${curdomain}-pv-claim --ignore-not-found=true
70+
71+
echo @@ Deleting ${curdomain}-weblogic-credentials secret in namespace $curns
72+
kubectl -n $curns delete secret ${curdomain}-weblogic-credentials --ignore-not-found=true
73+
74+
#echo @@ Deleting ${curdomain} traefik in namespace $curns
75+
#kubectl delete -f $RESULT_DIR/${curns}-${curdomain}/traefik-deployment.yaml --ignore-not-found=true
76+
#kubectl delete -f $RESULT_DIR/${curns}-${curdomain}/traefik-rbac.yaml --ignore-not-found=true
77+
kubectl -n $curns delete deploy ${curdomain}-cluster-1-traefik --ignore-not-found=true
78+
kubectl -n $curns delete service ${curdomain}-cluster-1-traefik --ignore-not-found=true
79+
kubectl -n $curns delete service ${curdomain}-cluster-1-traefik-dashboard --ignore-not-found=true
80+
kubectl -n $curns delete cm ${curdomain}-cluster-1-traefik --ignore-not-found=true
81+
kubectl -n $curns delete serviceaccount ${curdomain}-cluster-1-traefik --ignore-not-found=true
82+
kubectl -n $curns delete clusterrole ${curdomain}-cluster-1-traefik --ignore-not-found=true
83+
kubectl -n $curns delete clusterrolebinding ${curdomain}-cluster-1-traefik --ignore-not-found=true
84+
85+
done
86+
87+
for ((i=0;i<OCOUNT;i++)); do
88+
opns=${OPER_NAMESPACES[i]}
89+
echo @@ Deleting operator in namespace $opns
90+
#kubectl delete -f $RESULT_DIR/${opns}/weblogic-operator.yaml
91+
kubectl delete deploy weblogic-operator -n ${opns} --ignore-not-found=true
92+
sleep 10
93+
done
94+
95+
for ((i=0;i<DCOUNT;i++)); do
96+
curdomain=${DOMAINS[i]}
97+
curns=${DOMAIN_NAMESPACES[i]}
98+
kubectl -n $curns delete rolebinding weblogic-operator-rolebinding --ignore-not-found=true
99+
kubectl -n $curns delete rolebinding weblogic-operator-operator-rolebinding --ignore-not-found=true
100+
done
101+
102+
kubectl delete clusterrole \
103+
weblogic-operator-cluster-role-nonresource \
104+
weblogic-operator-namespace-role \
105+
weblogic-operator-cluster-role --ignore-not-found=true
106+
107+
for ((i=0;i<OCOUNT;i++)); do
108+
opns=${OPER_NAMESPACES[i]}
109+
echo @@ Deleting clusterrolebindings for operator in $opns
110+
kubectl -n $opns delete clusterrolebinding \
111+
${opns}-operator-rolebinding-auth-delegator \
112+
${opns}-operator-rolebinding-discovery \
113+
${opns}-operator-rolebinding-nonresource \
114+
${opns}-operator-rolebinding --ignore-not-found=true
115+
done
116+
117+
118+
echo @@ Deleting crd
119+
kubectl delete crd domains.weblogic.oracle --ignore-not-found=true
120+
121+
#echo @@ Deleting security
122+
#kubectl delete -f $PROJECT_ROOT/kubernetes/rbac.yaml --ignore-not-found=true
123+
124+
#echo @@ Deleting kibani, logstash, and elasticsearch artifacts.
125+
kubectl delete -f $PROJECT_ROOT/src/integration-tests/kubernetes/kibana.yaml --ignore-not-found=true
126+
kubectl delete -f $PROJECT_ROOT/src/integration-tests/kubernetes/logstash.yaml --ignore-not-found=true
127+
kubectl delete -f $PROJECT_ROOT/src/integration-tests/kubernetes/elasticsearch.yaml --ignore-not-found=true
128+
129+
echo @@ Deleting elk pv and pvc
130+
# TBD The next line can be deleted once the fix
131+
# to have uniquely scoped pv/pvc per operator is in place
132+
kubectl delete pv elk-pv --ignore-not-found=true
133+
for ((i=0;i<OCOUNT;i++)); do
134+
curns=${OPER_NAMESPACES[i]}
135+
kubectl delete pv elk-pv-${curns} --ignore-not-found=true
136+
kubectl -n ${curns} delete pvc elk-pvc --ignore-not-found=true
137+
done
138+
139+
for ((i=0;i<OCOUNT;i++)); do
140+
opns=${OPER_NAMESPACES[i]}
141+
echo @@ Deleting weblogic-operator namespace
142+
kubectl delete namespace $opns --ignore-not-found=true
143+
sleep 1 # wait in case above needs below
144+
done
145+
146+
echo @@ Deleting test namespace
147+
kubectl delete namespace test --ignore-not-found=true
148+
kubectl delete namespace test2 --ignore-not-found=true
149+
150+
for ((i=0;i<DCOUNT;i++)); do
151+
curdomain=${DOMAINS[i]}
152+
curns=${DOMAIN_NAMESPACES[i]}
153+
echo @@ Deleting configmap domain-domain1-scripts in namespace $curns
154+
kubectl -n $curns delete cm domain-${curdomain}-scripts --ignore-not-found=true
155+
done
156+
157+
JOB_NAME="weblogic-job"
158+
kubectl delete job $JOB_NAME --ignore-not-found=true
159+
160+
waitForDelete "all,crd,cm,pv,pvc,ns,roles,rolebindings,clusterroles,clusterrolebindings,secrets" "logstash|kibana|elastisearch|weblogic|elk|domain"
161+
162+
# clean-up volumes
163+
cp $PROJECT_ROOT/build/weblogic-job.yaml $RESULT_ROOT/domain-cleanup-job.yaml
164+
sed -i -e "s:%HOST_PATH%:$HOST_PATH:g" $RESULT_ROOT/domain-cleanup-job.yaml
165+
sed -i -e "s:%ARGS%:[\"-c\", \"rm -rf $HOST_DIR ; mkdir -m 777 -p $HOST_DIR\"]:g" $RESULT_ROOT/domain-cleanup-job.yaml
166+
167+
kubectl create -f $RESULT_ROOT/domain-cleanup-job.yaml
168+
echo "Waiting for the job to complete..."
169+
JOB_STATUS="0"
170+
max=10
171+
count=0
172+
while [ "$JOB_STATUS" != "Completed" -a $count -lt $max ] ; do
173+
sleep 30
174+
count=`expr $count + 1`
175+
JOB_STATUS=`kubectl get pods --show-all | grep "$JOB_NAME" | awk ' { print $3; } '`
176+
JOB_INFO=`kubectl get pods --show-all | grep "$JOB_NAME" | awk ' { print "pod", $1, "status is", $3; } '`
177+
echo "status on iteration $count of $max"
178+
echo "$JOB_INFO"
179+
180+
done
181+
182+
# Confirm the job pod is status completed
183+
JOB_POD=`kubectl get pods --show-all | grep "$JOB_NAME" | awk ' { print $1; } '`
184+
if [ "$JOB_STATUS" != "Completed" ]; then
185+
echo The cleanup job is not showing status completed after waiting 300 seconds
186+
echo Check the log output for errors
187+
kubectl logs jobs/$JOB_NAME
188+
fail "Exiting due to failure"
189+
fi
190+
191+
kubectl delete job $JOB_NAME --ignore-not-found=true
192+

0 commit comments

Comments
 (0)