Skip to content

Commit 8c7b52b

Browse files
author
Tom Barnes
committed
Introspect mock/unit test enhancement: run introspector as a pod instead of as a job. (Helps with debugging.).
1 parent 8bb351a commit 8c7b52b

File tree

3 files changed

+184
-1
lines changed

3 files changed

+184
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
/weblogic-operator/scripts/introspectDomain.sh
6+
7+
# the introspectTest.sh script looks for this exact line:
8+
echo "INTROSPECT_DOMAIN_EXIT=$?"
9+
10+
echo In "$0" SLEEPING
11+
12+
while [ 1 -eq 1 ]; do
13+
sleep 10
14+
done

src/integration-tests/introspector/introspectTest.sh

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ function deployTestScriptConfigMap() {
336336
cp ${SOURCEPATH}/operator/src/main/resources/scripts/traceUtils* ${test_home}/test-scripts || exit 1
337337
cp ${SCRIPTPATH}/createDomain.sh ${test_home}/test-scripts || exit 1
338338
cp ${SCRIPTPATH}/createTestRoot.sh ${test_home}/test-scripts || exit 1
339+
cp ${SCRIPTPATH}/introspectDomainProxy.sh ${test_home}/test-scripts || exit 1
339340

340341
if [ "$CREATE_DOMAIN" = "true" ]; then
341342
rm -f ${test_home}/scripts/createDomain.py
@@ -454,6 +455,7 @@ function deployCreateDomainJob() {
454455
# - this emulates what the operator pod would do prior to start wl-pods
455456
#
456457

458+
# Alternatively, run deployIntrospectJobPod() instead.
457459
function deployIntrospectJob() {
458460
local introspect_output_cm_name=${DOMAIN_UID}-weblogic-domain-introspect-cm
459461

@@ -484,6 +486,105 @@ function deployIntrospectJob() {
484486

485487
}
486488

489+
# Here we emulate the introspect job by directly starting an introspect pod and monitoring it.
490+
# deployIntrospectJob() does about the same thing, but starts a pod via a job
491+
# (Running a pod directly is helpful for debugging.)
492+
493+
function deployIntrospectJobPod() {
494+
local introspect_output_cm_name=${DOMAIN_UID}-weblogic-domain-introspect-cm
495+
local target_yaml=${test_home}/wl-introspect-pod.yaml
496+
local pod_name=${DOMAIN_UID}--introspect-domain-pod
497+
local job_name=$pod_name
498+
499+
trace "Info: Run introspection job, parse its output to files, and put files in configmap '$introspect_output_cm_name'."
500+
501+
# delete anything left over from a previous invocation of this function
502+
503+
kubectl -n $NAMESPACE delete cm $introspect_output_cm_name \
504+
--ignore-not-found \
505+
2>&1 | tracePipe "Info: kubectl output: "
506+
507+
if [ -f "${target_yaml}" ]; then
508+
kubectl -n $NAMESPACE delete -f ${target_yaml} \
509+
--ignore-not-found \
510+
2>&1 | tracePipe "Info: kubectl output: "
511+
rm -f ${target_yaml}
512+
fi
513+
514+
trace "Info: Deploying job pod '$pod_name' and waiting for it to be ready."
515+
516+
(
517+
export SERVER_NAME=introspect
518+
export JOB_NAME=${DOMAIN_UID}--introspect-domain-pod
519+
export JOB_SCRIPT=/test-scripts/introspectDomainProxy.sh
520+
export SERVICE_NAME=`toDNS1123Legal ${DOMAIN_UID}-${server_name}`
521+
export AS_SERVICE_NAME=`toDNS1123Legal ${DOMAIN_UID}-${ADMIN_NAME}`
522+
if [ "${SERVER_NAME}" = "${ADMIN_NAME}" ]; then
523+
export LOCAL_SERVER_DEFAULT_PORT=$ADMIN_PORT
524+
else
525+
export LOCAL_SERVER_DEFAULT_PORT=$MANAGED_SERVER_PORT
526+
fi
527+
${SCRIPTPATH}/util_subst.sh -g wl-introspect-pod.yamlt ${target_yaml} || exit 1
528+
) || exit 1
529+
530+
kubectl create -f ${target_yaml} \
531+
2>&1 | tracePipe "Info: kubectl output: " || exit 1
532+
533+
# Wait for pod to come up successfully
534+
535+
# TBD make the following a helper fn since this is the second place
536+
# we wait for a pod to start, and the code is exactly the same...
537+
local status="0/1"
538+
local startsecs=$SECONDS
539+
local maxsecs=180
540+
tracen "Info: Waiting up to $maxsecs seconds for pod '$pod_name' readiness"
541+
while [ "${status}" != "1/1" ] ; do
542+
if [ $((SECONDS - startsecs)) -gt $maxsecs ]; then
543+
echo
544+
trace "Error: pod $pod_name failed to start within $maxsecs seconds. kubectl describe:"
545+
kubectl -n $NAMESPACE describe pod $pod_name
546+
trace "Error: pod $pod_name failed to start within $maxsecs seconds. kubectl log:"
547+
kubectl -n $NAMESPACE logs $pod_name
548+
exit 1
549+
fi
550+
echo -n "."
551+
sleep 1
552+
status=`kubectl -n $NAMESPACE get pods 2>&1 | egrep $pod_name | awk '{print $2}'`
553+
done
554+
echo " ($((SECONDS - startsecs)) seconds)"
555+
556+
local startSecs=$SECONDS
557+
local maxsecs=30
558+
local exitString=""
559+
tracen "Info: Waiting up to $maxsecs seconds for pod '$pod_name' to run the introspectDomain.py script."
560+
printdots_start
561+
while [ $((SECONDS - startSecs)) -lt $maxsecs ] && [ "$exitString" = "" ]; do
562+
exitString="`kubectl -n $NAMESPACE logs $pod_name 2>&1 | grep INTROSPECT_DOMAIN_EXIT`"
563+
sleep 1
564+
done
565+
printdots_end
566+
if [ "$exitString" = "" ]; then
567+
trace "Error: Introspector timed out, see 'kubectl -n $NAMESPACE logs $pod_name'."
568+
exit 1
569+
fi
570+
if [ ! "$exitString" = "INTROSPECT_DOMAIN_EXIT=0" ]; then
571+
trace "Error: Introspector pod script failed, see 'kubectl -n $NAMESPACE logs $pod_name'."
572+
exit 1
573+
fi
574+
575+
# parse job pod's output files
576+
577+
kubectl -n $NAMESPACE logs $pod_name > ${test_home}/job-${DOMAIN_UID}-introspect-domain-pod-job.out
578+
579+
${SCRIPTPATH}/util_fsplit.sh \
580+
${test_home}/job-${DOMAIN_UID}-introspect-domain-pod-job.out \
581+
${test_home}/jobfiles || exit 1
582+
583+
# put the outputfile in a cm
584+
585+
createConfigMapFromDir $introspect_output_cm_name ${test_home}/jobfiles
586+
}
587+
487588
#############################################################################
488589
#
489590
# Launch pod and wait up to 180 seconds for it to succeed, also launch
@@ -664,7 +765,8 @@ if [ ! "$RERUN_INTROSPECT_ONLY" = "true" ]; then
664765
createTestRootPVDir
665766
deployWebLogic_PV_PVC_and_Secret
666767
deployCreateDomainJob
667-
deployIntrospectJob
768+
#deployIntrospectJob
769+
deployIntrospectJobPod
668770
deployPod ${ADMIN_NAME?}
669771
deploySinglePodService ${ADMIN_NAME?} ${ADMIN_PORT?} 30701
670772
deployPod ${MANAGED_SERVER_NAME_BASE?}1
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
apiVersion: v1
5+
kind: Pod
6+
metadata:
7+
labels:
8+
weblogic.createdByOperator: "true"
9+
weblogic.domainUID: ${DOMAIN_UID}
10+
weblogic.resourceVersion: domain-v2
11+
name: ${JOB_NAME}
12+
namespace: ${NAMESPACE}
13+
spec:
14+
containers:
15+
- command:
16+
- ${JOB_SCRIPT}
17+
env:
18+
- name: NAMESPACE
19+
value: "${NAMESPACE}"
20+
- name: DOMAIN_UID
21+
value: "${DOMAIN_UID}"
22+
- name: DOMAIN_HOME
23+
value: "${DOMAIN_HOME}"
24+
- name: NODEMGR_HOME
25+
value: "${NODEMGR_HOME}"
26+
- name: LOG_HOME
27+
value: "${LOG_HOME}"
28+
- name: CREDENTIALS_SECRET_NAME
29+
value: "${WEBLOGIC_CREDENTIALS_SECRET_NAME}"
30+
image: "${WEBLOGIC_IMAGE_NAME}:${WEBLOGIC_IMAGE_TAG}"
31+
imagePullPolicy: ${WEBLOGIC_IMAGE_PULL_POLICY}
32+
name: weblogic-server
33+
volumeMounts:
34+
- name: weblogic-credentials-volume
35+
mountPath: /weblogic-operator/secrets
36+
readOnly: true
37+
- name: weblogic-domain-cm-volume
38+
mountPath: /weblogic-operator/scripts
39+
readOnly: true
40+
- name: ${DOMAIN_UID}-mycustom-overrides-cm-volume
41+
mountPath: /weblogic-operator/config-overrides
42+
readOnly: true
43+
- name: test-script-cm-volume
44+
mountPath: /test-scripts
45+
readOnly: true
46+
${PVCOMMENT}- mountPath: /shared
47+
${PVCOMMENT} name: weblogic-domain-storage-volume
48+
volumes:
49+
- name: weblogic-credentials-volume
50+
secret:
51+
defaultMode: 420
52+
secretName: ${WEBLOGIC_CREDENTIALS_SECRET_NAME}
53+
- name: weblogic-domain-cm-volume
54+
configMap:
55+
defaultMode: 365
56+
name: weblogic-domain-cm
57+
- name: ${DOMAIN_UID}-mycustom-overrides-cm-volume
58+
configMap:
59+
defaultMode: 365
60+
name: ${DOMAIN_UID}-mycustom-overrides-cm
61+
- name: test-script-cm-volume
62+
configMap:
63+
defaultMode: 365
64+
name: test-script-cm
65+
${PVCOMMENT}- name: weblogic-domain-storage-volume
66+
${PVCOMMENT} persistentVolumeClaim:
67+
${PVCOMMENT} claimName: ${DOMAIN_UID}-weblogic-domain-pvc

0 commit comments

Comments
 (0)