Skip to content

Commit

Permalink
run e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aojea committed Feb 28, 2023
1 parent 65d33bd commit 9f585bb
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
69 changes: 69 additions & 0 deletions hack/boskos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

# acquires a project from boskos
acquire_project() {
local project=""
local project_type="gce-project"

boskos_response=$(curl -X POST "http://boskos.test-pods.svc.cluster.local/acquire?type=${project_type}&state=free&dest=busy&owner=${JOB_NAME}")

if project=$(echo "${boskos_response}" | jq -r '.name'); then
echo "Using GCP project: ${project}"
GCP_PROJECT="${project}"
export GCP_PROJECT
heartbeat_project_forever &
BOSKOS_HEARTBEAT_PID=$!
export BOSKOS_HEARTBEAT_PID
else
(>&2 echo "ERROR: failed to acquire GCP project. boskos response was: ${boskos_response}")
exit 1
fi
}

# release the project back to boskos
release_project() {
curl -X POST "http://boskos/release?name=${GCP_PROJECT}&owner=${JOB_NAME}&dest=dirty"
}

# send a heartbeat to boskos for the project
heartbeat_project() {
curl -X POST "http://boskos/update?name=${GCP_PROJECT}&state=busy&owner=${JOB_NAME}" > /dev/null 2>&1
}

# heartbeat_project in an infinite loop
heartbeat_project_forever() {
set +x;
local heartbeat_seconds=10
while :
do
# always heartbeat, ignore failures
heartbeat_project || true
sleep ${heartbeat_seconds}
done
}

cleanup_boskos () {
# stop heartbeating
kill "${BOSKOS_HEARTBEAT_PID}" || true
# mark the project as dirty
release_project
}
79 changes: 79 additions & 0 deletions hack/run-e2e-gce.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# Copyright 2023 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


set -o errexit
set -o nounset
set -o pipefail
set -o xtrace

export GOPATH="$(go env GOPATH)"
KUBE_REPO_ROOT=$GOPATH/src/k8s.io/kubernetes
REPO_ROOT=$(git rev-parse --show-toplevel)
cd ${REPO_ROOT}



# Setup our cleanup function; as we allocate resources we set a variable to indicate they should be cleaned up
function cleanup {
if [[ "${CLEANUP_BOSKOS:-}" == "true" ]]; then
cleanup_boskos
fi
# shellcheck disable=SC2153
if [[ "${DELETE_CLUSTER:-}" == "true" ]]; then
kubetest2 ${KUBETEST2_ARGS} --down || echo "kubetest2 down failed"
fi
}
trap cleanup EXIT

# Ensure we have a project; get one from boskos if one not provided in GCP_PROJECT
source "${REPO_ROOT}"/hack/boskos.sh
if [[ -z "${GCP_PROJECT:-}" ]]; then
echo "GCP_PROJECT not set, acquiring project from boskos"
acquire_project
CLEANUP_BOSKOS="true"
fi
echo "GCP_PROJECT=${GCP_PROJECT}"

# IMAGE_REPO is used to upload images
if [[ -z "${IMAGE_REPO:-}" ]]; then
IMAGE_REPO="gcr.io/${GCP_PROJECT}"
fi
echo "IMAGE_REPO=${IMAGE_REPO}"

cd ${REPO_ROOT}
export KO_DOCKER_REPO="${IMAGE_REPO}"
if [[ -z "${IMAGE_TAG:-}" ]]; then
IMAGE_TAG=$(git rev-parse --short HEAD)-$(date +%Y%m%dT%H%M%S)
fi

export GCE_GLBC_IMAGE=$(go run github.com/google/ko@v0.12.0 build --tags ${IMAGE_TAG} --base-import-paths --push=true ./cmd/glbc/)
echo "GCE_GLBC_IMAGE=${GCE_GLBC_IMAGE}"

go install sigs.k8s.io/kubetest2@latest
go install sigs.k8s.io/kubetest2/kubetest2-gce@latest
go install sigs.k8s.io/kubetest2/kubetest2-tester-ginkgo@latest
kubetest2 gce -v 2 \
--repo-root ${KUBE_REPO_ROOT} \
--gcp-project=${GCP_PROJECT} \
--legacy-mode \
--build \
--up \
--down \
--test=ginkgo \
-- \
--focus-regex=='\[Feature:Ingress\]|\[Feature:NEG\]' \
--use-built-binaries

0 comments on commit 9f585bb

Please sign in to comment.