mirror of
https://github.com/openshift/community.okd.git
synced 2026-03-27 03:13:08 +00:00
Rewrite incluster test to only rely on bash and kubectl
This commit is contained in:
4
Makefile
4
Makefile
@@ -20,5 +20,5 @@ test-sanity: install
|
||||
test-integration: install
|
||||
molecule test
|
||||
|
||||
test-integration-incluster: install
|
||||
ANSIBLE_COLLECTIONS_PATHS=$(shell pwd) ansible-playbook ci/incluster_integration.yml
|
||||
test-integration-incluster:
|
||||
./ci/incluster_integration.sh
|
||||
|
||||
66
ci/incluster_integration.sh
Executable file
66
ci/incluster_integration.sh
Executable file
@@ -0,0 +1,66 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -x
|
||||
|
||||
# IMAGE_FORMAT be in the form $registry/$org/$image:$$component, ie
|
||||
# quay.io/openshift/release:$component
|
||||
# To test with your own image, build and push the test image
|
||||
# (using the Dockerfile in ci/Dockerfile)
|
||||
# and set the IMAGE_FORMAT environment variable so that it properly
|
||||
# resolves to your image. For example, quay.io/mynamespace/$component
|
||||
# would resolve to quay.io/mynamespace/molecule-test-runner
|
||||
component='molecule-test-runner'
|
||||
eval IMAGE=$IMAGE_FORMAT
|
||||
|
||||
PULL_POLICY=${PULL_POLICY:-IfNotPresent}
|
||||
|
||||
echo "Deleting test job if it exists"
|
||||
kubectl delete job molecule-integration-test --wait --ignore-not-found
|
||||
|
||||
echo "Creating molecule test job"
|
||||
cat << EOF | kubectl create -f -
|
||||
---
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: molecule-integration-test
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: test-runner
|
||||
image: ${IMAGE}
|
||||
imagePullPolicy: ${PULL_POLICY}
|
||||
command:
|
||||
- make
|
||||
- test-integration
|
||||
restartPolicy: Never
|
||||
backoffLimit: 3
|
||||
completions: 1
|
||||
parallelism: 1
|
||||
EOF
|
||||
|
||||
echo "Waiting for test job to report success"
|
||||
|
||||
# Ensure the child processes are killed
|
||||
trap 'kill $(jobs -p) || true' SIGINT SIGTERM EXIT
|
||||
|
||||
# Wait for job completion in background
|
||||
kubectl wait --for=condition=complete job/molecule-integration-test --timeout 5m &
|
||||
completion_pid=$!
|
||||
|
||||
# Wait for job failure in background
|
||||
kubectl wait --for=condition=failed job/molecule-integration-test --timeout 5m && exit 1 &
|
||||
failure_pid=$!
|
||||
|
||||
wait -n $completion_pid $failure_pid
|
||||
exit_code=$?
|
||||
|
||||
if (( $exit_code == 0 )); then
|
||||
echo "Molecule integration tests ran successfully"
|
||||
else
|
||||
echo "Molecule integration tests failed, see logs for more information..."
|
||||
kubectl logs job/molecule-integration-test
|
||||
fi
|
||||
|
||||
exit $exit_code
|
||||
@@ -1,66 +0,0 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
connection: local
|
||||
gather_facts: no
|
||||
|
||||
vars:
|
||||
namespace: default
|
||||
component: molecule-test-runner
|
||||
pull_policy: IfNotPresent
|
||||
# This will be in the form $registry/$org/$image:$$component, ie
|
||||
# quay.io/openshift/release:$component
|
||||
image_format: '{{ lookup("env", "IMAGE_FORMAT") }}'
|
||||
image: '{{ image_format | replace("$component", component) }}'
|
||||
|
||||
tasks:
|
||||
- name: Ensure clean environment
|
||||
community.okd.k8s:
|
||||
api_version: v1
|
||||
kind: Pod
|
||||
name: molecule-integration-test
|
||||
namespace: '{{ namespace }}'
|
||||
state: absent
|
||||
wait: yes
|
||||
|
||||
- name: Create molecule test pod
|
||||
community.okd.k8s:
|
||||
definition:
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: molecule-integration-test
|
||||
namespace: '{{ namespace }}'
|
||||
spec:
|
||||
containers:
|
||||
- name: test-runner
|
||||
image: '{{ image }}'
|
||||
imagePullPolicy: '{{ pull_policy }}'
|
||||
command:
|
||||
- make
|
||||
- test-integration
|
||||
restartPolicy: Never
|
||||
|
||||
- name: Wait for Pod to finish
|
||||
community.kubernetes.k8s_info:
|
||||
api_version: v1
|
||||
kind: Pod
|
||||
name: molecule-integration-test
|
||||
namespace: '{{ namespace }}'
|
||||
register: test_pod
|
||||
until: test_pod.resources.0.status.phase in ['Succeeded', 'Failed']
|
||||
delay: 6
|
||||
retries: 10
|
||||
|
||||
- name: Gather Pod Logs
|
||||
community.kubernetes.k8s_log:
|
||||
name: molecule-integration-test
|
||||
namespace: '{{ namespace }}'
|
||||
register: pod_log
|
||||
|
||||
- name: Exit with error on Pod failure
|
||||
fail:
|
||||
msg: |
|
||||
Molecule interation tests failed, see logs for more info
|
||||
|
||||
{{ pod_log.log }}
|
||||
when: test_pod.resources.0.status.phase == 'Failed'
|
||||
Reference in New Issue
Block a user