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

Commit

Permalink
Merge pull request #1369 from adrianludwin/e2e-prow
Browse files Browse the repository at this point in the history
Create e2e test image for Prow
  • Loading branch information
k8s-ci-robot authored Feb 1, 2021
2 parents c22e3ec + 8f0e4ee commit 059c1f3
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
26 changes: 26 additions & 0 deletions incubator/hnc/hack/prow-e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM golang:1.14.2-alpine
WORKDIR /repo

# Since go modules isn't enabled by default.
ENV GO111MODULE=on

# Build static binaries; otherwise go test complains.
ENV CGO_ENABLED=0

# Install all basic dependencies. Bash is there in case you need to debug.
# Curl, Docker, git and make are not included in the golang image.
RUN apk add --no-cache bash curl docker git make
# bash curl docker gcc git jq make openssh-client

# Install Kind
RUN go get sigs.k8s.io/kind@v0.9.0

# Install kubectl and make sure it's available in the PATH.
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
RUN chmod +x ./kubectl
RUN mv ./kubectl /bin

# Add the actual script and set it as the default command for this image.
COPY run-e2e.sh run-e2e.sh
RUN chmod +x ./run-e2e.sh
CMD ["./run-e2e.sh"]
20 changes: 20 additions & 0 deletions incubator/hnc/hack/prow-e2e/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
IMG_NAME ?= gcr.io/k8s-staging-multitenancy/hnc-postsubmit-tests:latest

build:
docker build . -t ${IMG_NAME}

# This is for local debugging. The '-it' arg is needed to allow you to hit
# ctrl-c while the tests are still running.
run: build
@echo STARTING THE POSTSUBMIT TESTS IN THE CONTAINER
docker run -v /var/run/docker.sock:/var/run/docker.sock --network="host" -it ${IMG_NAME}

# After calling 'make run', the Kind cluster will still be present on the
# *host* even though the Docker container has exited. Run this to find and
# delete any Kind cluster starting with 'hnc-postsubmit-'
clean:
kind get clusters | grep hnc-postsubmit- | xargs kind delete clusters

# You need permission to push to k8s-staging-multitenancy for this to work.
push: build
docker push ${IMG_NAME}
14 changes: 14 additions & 0 deletions incubator/hnc/hack/prow-e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This directory contains the files required to run HNC e2e tests on Prow using
Kind.

Files:
* Makefile: contains `build`, `run` and `clean` targets. `run` includes `build`.
* Also 'push', which requires that you have permission to push to
gcr.io/k8s-staging-multitenancy.
* Dockerfile: creates the image that contains Kind and everything else required
to run the tests.
* run-e2e.sh: included in the Docker image; pulls the repo, creates a Kind
cluster, deploys HNC and runs the tests.

To run the tests in the container (i.e., debug the container), type `make run`,
followed by `make clean` if it doesn't finish successfully.
62 changes: 62 additions & 0 deletions incubator/hnc/hack/prow-e2e/run-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
# This script is designed to be run in the hnc-postsubmit-tests container. See
# https://github.com/kubernetes-sigs/multi-tenancy/blob/master/incubator/hnc/hack/prow-e2e/README.md
# for details.

set -euf -o pipefail

start_time="$(date -u +%s)"
echo
echo "Starting at $(date +%Y-%m-%d\ %H:%M:%S)"

echo
echo "Cloning repo into ${PWD}"
git clone https://github.com/kubernetes-sigs/multi-tenancy
cd multi-tenancy/incubator/hnc

# No-one else seems to clean up their Kind clusters, so I don't think we need to
# either? Does Prow handle it? To make it easier to debug locally, let's just
# give the cluster a random name (max 32k). This should match the name we look
# for in the "clean" target in the Makefile in this directory in the git repo.
CLUSTERNAME="hnc-postsubmit-${RANDOM}"
echo
echo "Creating KIND cluster '${CLUSTERNAME}' and setting kubectl context"
kind create cluster --name ${CLUSTERNAME}

echo
echo "Building HNC artifacts"
# Because we don't use the default Kind cluster name, the builtin "docker push"
# in the makefile won't work here.
CONFIG=kind make manifests
CONFIG=kind make kubectl
CONFIG=kind make docker-build

# Load image into Kind and deploy
export HNC_REPAIR="${PWD}/manifests/hnc-manager.yaml"
echo
echo "Setting HNC_REPAIR to ${HNC_REPAIR} and deploying HNC"
# Assume the default value of ${HNC_IMG} in the makefile is used
kind load docker-image --name ${CLUSTERNAME} hnc-manager:kind-local
kubectl apply -f ${HNC_REPAIR}

# The webhooks take about 30 load
echo
echo "Waiting 30s for HNC to be alive"
sleep 10
echo "... still waiting ..."
sleep 10
echo "... almost done ..."
sleep 10

echo
echo "Running the tests"
make test-e2e

# Note that this won't run if the tests fail - see above. But we may as well
# *try* to clean up after ourselves.
kind delete clusters ${CLUSTERNAME}

echo "Finished at $(date +%Y-%m-%d\ %H:%M:%S)"
end_time="$(date -u +%s)"
elapsed="$(($end_time-$start_time))"
echo "Script took $elapsed seconds"

0 comments on commit 059c1f3

Please sign in to comment.