Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5799 from ldoktor/kube
Browse files Browse the repository at this point in the history
ci/openshift-ci: Tweak test.sh to run with kubernetes
  • Loading branch information
gkurz authored Jan 19, 2024
2 parents da8b88d + 7df4483 commit cfea72b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .ci/openshift-ci/cluster/install_kata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ debug_pod() {
oc logs "$pod"
}

oc project default
oc config set-context --current --namespace=default

worker_nodes=$(oc get nodes | awk '{if ($3 == "worker") { print $1 } }')
num_nodes=$(echo $worker_nodes | wc -w)
Expand Down
36 changes: 25 additions & 11 deletions .ci/openshift-ci/run_smoke_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ oc apply -f ${script_dir}/smoke/${pod}.yaml || \
# Check it eventually goes to 'running'
#
wait_time=600
sleep_time=10
sleep_time=5
cmd="oc get pod/${pod} -o jsonpath='{.status.containerStatuses[0].state}' | \
grep running > /dev/null"
info "Wait until the pod gets running"
Expand All @@ -40,13 +40,24 @@ hello_msg='Hello World'
oc exec ${pod} -- sh -c "echo $hello_msg > $hello_file"

info "Creating the service and route"
oc apply -f ${script_dir}/smoke/service.yaml
sleep 60
if oc apply -f ${script_dir}/smoke/service.yaml; then
# Likely on OCP, use service
is_ocp=1
host=$(oc get route/http-server-route -o jsonpath={.spec.host})
port=80
else
# Likely on plain kubernetes, test using another container
is_ocp=0
info "Failed to create service, likely not on OCP, trying via NodePort"
oc apply -f "${script_dir}/smoke/service_kubernetes.yaml"
# For some reason kcli's cluster lists external IP as internal IP, try both
host=$(oc get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="ExternalIP")].address}')
[ -z "$host"] && host=$(oc get nodes -o jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')
port=$(oc get service/http-server-service -o jsonpath='{.spec.ports[0].nodePort}')
fi

curl "${host}:${port}${hello_file}" -s -o hello_msg.txt --retry 60 --retry-delay 1 --retry-all-errors

host=$(oc get route/http-server-route -o jsonpath={.spec.host})
# The route to port 80 should work and it should serve the pod's '/' filesystem
#
curl ${host}:80${hello_file} -s -o hello_msg.txt
grep "${hello_msg}" hello_msg.txt > /dev/null
test_status=$?
if [ $test_status -eq 0 ]; then
Expand All @@ -55,11 +66,14 @@ else
info "HTTP server is unreachable"
fi

info "Deleting resources created"
oc delete -f ${script_dir}/smoke/service.yaml

# Delete the pod.
# Delete the resources.
#
info "Deleting the service/route"
if [ "$is_ocp" -eq 0 ]; then
oc delete -f ${script_dir}/smoke/service_kubernetes.yaml
else
oc delete -f ${script_dir}/smoke/service.yaml
fi
info "Deleting the ${pod} pod"
oc delete pod/${pod} || test_status=$?

Expand Down
18 changes: 18 additions & 0 deletions .ci/openshift-ci/smoke/service_kubernetes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2020 Red Hat, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# Create the service on port 80 for the http-server app.
---
apiVersion: v1
kind: Service
metadata:
name: http-server-service
spec:
selector:
app: http-server-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: NodePort

0 comments on commit cfea72b

Please sign in to comment.