Skip to content

Commit

Permalink
Merge pull request #7456 from adrianmoisey/vpa-e2e-tests-local
Browse files Browse the repository at this point in the history
Modify the e2e local scripts so they can be run on a modern Mac
  • Loading branch information
k8s-ci-robot authored Nov 11, 2024
2 parents c9970a4 + 82e8002 commit adba590
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 80 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ Session.vim

# Binary files
bin/

# vertical pod autoscaler test output
vertical-pod-autoscaler/e2e/v1*/workspace/
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
containers:
- name: admission-controller
image: registry.k8s.io/autoscaling/vpa-admission-controller:1.2.1
imagePullPolicy: Always
imagePullPolicy: IfNotPresent
env:
- name: NAMESPACE
valueFrom:
Expand Down
2 changes: 1 addition & 1 deletion vertical-pod-autoscaler/deploy/recommender-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
containers:
- name: recommender
image: registry.k8s.io/autoscaling/vpa-recommender:1.2.1
imagePullPolicy: Always
imagePullPolicy: IfNotPresent
resources:
limits:
cpu: 200m
Expand Down
2 changes: 1 addition & 1 deletion vertical-pod-autoscaler/deploy/updater-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
containers:
- name: updater
image: registry.k8s.io/autoscaling/vpa-updater:1.2.1
imagePullPolicy: Always
imagePullPolicy: IfNotPresent
env:
- name: NAMESPACE
valueFrom:
Expand Down
24 changes: 19 additions & 5 deletions vertical-pod-autoscaler/hack/deploy-for-e2e-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
BASE_NAME=$(basename $0)
source "${SCRIPT_ROOT}/hack/lib/util.sh"

ARCH=$(kube::util::host_arch)

function print_help {
echo "ERROR! Usage: deploy-for-e2e-locally.sh [suite]*"
echo "ERROR! Usage: $BASE_NAME [suite]*"
echo "<suite> should be one of:"
echo " - recommender"
echo " - recommender-externalmetrics"
echo " - updater"
echo " - admission-controller"
echo " - full-vpa"
}

if [ $# -eq 0 ]; then
Expand All @@ -40,16 +47,19 @@ fi
SUITE=$1

case ${SUITE} in
recommender|recommender-externalmetrics)
recommender|recommender-externalmetrics|updater|admission-controller)
COMPONENTS="${SUITE}"
;;
full-vpa)
COMPONENTS="recommender updater admission-controller"
;;
*)
print_help
exit 1
;;
esac

# Local KIND-hosted registry
# Local KIND images
export REGISTRY=${REGISTRY:-localhost:5001}
export TAG=${TAG:-latest}

Expand All @@ -64,8 +74,12 @@ for i in ${COMPONENTS}; do
if [ $i == recommender-externalmetrics ] ; then
i=recommender
fi
ALL_ARCHITECTURES=amd64 make --directory ${SCRIPT_ROOT}/pkg/${i} release REGISTRY=${REGISTRY} TAG=${TAG}
kind load docker-image ${REGISTRY}/vpa-${i}-amd64:${TAG}
if [ $i == admission-controller ] ; then
(cd ${SCRIPT_ROOT}/pkg/${i} && bash ./gencerts.sh e2e || true)
fi
ALL_ARCHITECTURES=${ARCH} make --directory ${SCRIPT_ROOT}/pkg/${i} docker-build REGISTRY=${REGISTRY} TAG=${TAG}
docker tag ${REGISTRY}/vpa-${i}-${ARCH}:${TAG} ${REGISTRY}/vpa-${i}:${TAG}
kind load docker-image ${REGISTRY}/vpa-${i}:${TAG}
done


Expand Down
58 changes: 0 additions & 58 deletions vertical-pod-autoscaler/hack/e2e/kind-with-registry.sh

This file was deleted.

2 changes: 1 addition & 1 deletion vertical-pod-autoscaler/hack/e2e/metrics-pump.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
containers:
- name: metrics-pump
image: localhost:5001/write-metrics:dev
imagePullPolicy: Always
imagePullPolicy: IfNotPresent
args:
- /emit-metrics.py
- --dest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ spec:
runAsUser: 65534 # nobody
containers:
- name: recommender
image: localhost:5001/vpa-recommender-amd64:latest
image: localhost:5001/vpa-recommender:latest
imagePullPolicy: Never
args:
- /recommender-amd64
- /recommender
- --use-external-metrics=true
- --external-metrics-cpu-metric=cpu
- --external-metrics-memory-metric=mem
Expand Down
53 changes: 53 additions & 0 deletions vertical-pod-autoscaler/hack/lib/util.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

# Copyright 2024 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.

kube::util::host_arch() {
local host_arch
case "$(uname -m)" in
x86_64*)
host_arch=amd64
;;
i?86_64*)
host_arch=amd64
;;
amd64*)
host_arch=amd64
;;
aarch64*)
host_arch=arm64
;;
arm64*)
host_arch=arm64
;;
arm*)
host_arch=arm
;;
i?86*)
host_arch=x86
;;
s390x*)
host_arch=s390x
;;
ppc64le*)
host_arch=ppc64le
;;
*)
kube::log::error "Unsupported host arch. Must be x86_64, 386, arm, arm64, s390x or ppc64le."
exit 1
;;
esac
echo "${host_arch}"
}
3 changes: 2 additions & 1 deletion vertical-pod-autoscaler/hack/local-cluster.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Running Integration Tests locally

Included in parallel with `run-e2e.sh` and `deploy-for-e2e.sh` are two alternate versions
with `-locally` as part of their names. They use Kubernetes in Docker (`kind`) to run a local
cluster in Docker. Using them will require `docker` and `kind` in your `PATH`.

## External Metrics Tests

The external metrics tests (`recommender-externalmetrics`, available on the `-locally` variants)
use a stack of 4 additional programs to support testing:

Expand All @@ -29,4 +31,3 @@ The local test cases support running the `recommender` with external metrics. T
additional permissions we don't want to automatically enable for all customers via the
configuration given in `deploy/vpa-rbac.yaml`. The scripts use a context diff `hack/e2e/vpa-rbac.diff`
to enable those permission when running locally.

50 changes: 42 additions & 8 deletions vertical-pod-autoscaler/hack/run-e2e-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@
set -o nounset
set -o pipefail

BASE_NAME=$(basename $0)
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..

function print_help {
echo "ERROR! Usage: run-e2e.sh <suite>"
echo "ERROR! Usage: $BASE_NAME <suite>"
echo "<suite> should be one of:"
echo " - recommender"
echo " - recommender-externalmetrics"
echo " - updater"
echo " - admission-controller"
echo " - full-vpa"

}

if [ $# -eq 0 ]; then
Expand All @@ -37,29 +42,58 @@ if [ $# -gt 1 ]; then
fi

SUITE=$1
REQUIRED_COMMANDS="
docker
go
kind
kubectl
make
"

for i in $REQUIRED_COMMANDS; do
if ! command -v $i > /dev/null 2>&1
then
echo "$i could not be found, please ensure it is installed"
echo
echo "The following commands are required to run these tests:"
echo $REQUIRED_COMMANDS
exit 1;
fi
done

if ! docker ps >/dev/null 2>&1
then
echo "docker isn't running"
echo
echo "Please ensure that docker is running"
exit 1
fi


echo "Deleting KIND cluster 'kind'."
kind delete cluster -n kind -q

echo "Creating KIND cluster 'kind' with builtin registry."
${SCRIPT_ROOT}/hack/e2e/kind-with-registry.sh
echo "Creating KIND cluster 'kind'"
KIND_VERSION="kindest/node:v1.26.3"
kind create cluster --image=${KIND_VERSION}

echo "Building metrics-pump image"
docker build -t localhost:5001/write-metrics:dev -f ${SCRIPT_ROOT}/hack/e2e/Dockerfile.externalmetrics-writer ${SCRIPT_ROOT}/hack
echo " pushing image to local registry"
docker push localhost:5001/write-metrics:dev
echo " loading image into kind"
kind load docker-image localhost:5001/write-metrics:dev


case ${SUITE} in
recommender|recommender-externalmetrics)
recommender|recommender-externalmetrics|updater|admission-controller|full-vpa)
${SCRIPT_ROOT}/hack/vpa-down.sh
echo " ** Deploying for suite ${SUITE}"
${SCRIPT_ROOT}/hack/deploy-for-e2e-locally.sh ${SUITE}

echo " ** Running suite ${SUITE}"
if [ ${SUITE} == recommender-externalmetrics ]; then
${SCRIPT_ROOT}/hack/run-e2e-tests.sh recommender
WORKSPACE=./workspace/_artifacts ${SCRIPT_ROOT}/hack/run-e2e-tests.sh recommender
else
${SCRIPT_ROOT}/hack/run-e2e-tests.sh ${SUITE}
WORKSPACE=./workspace/_artifacts ${SCRIPT_ROOT}/hack/run-e2e-tests.sh ${SUITE}
fi
;;
*)
Expand Down
6 changes: 4 additions & 2 deletions vertical-pod-autoscaler/hack/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ SUITE=$1

export GO111MODULE=on

export WORKSPACE=${WORKSPACE:-/workspace/_artifacts}

case ${SUITE} in
recommender|updater|admission-controller|actuation|full-vpa)
export KUBECONFIG=$HOME/.kube/config
pushd ${SCRIPT_ROOT}/e2e
go test -mod vendor ./v1beta2/*go -v --test.timeout=90m --args --ginkgo.v=true --ginkgo.focus="\[VPA\] \[${SUITE}\]" --report-dir=/workspace/_artifacts --disable-log-dump --ginkgo.timeout=90m
go test -mod vendor ./v1beta2/*go -v --test.timeout=90m --args --ginkgo.v=true --ginkgo.focus="\[VPA\] \[${SUITE}\]" --report-dir=${WORKSPACE} --disable-log-dump --ginkgo.timeout=90m
V1BETA2_RESULT=$?
go test -mod vendor ./v1/*go -v --test.timeout=90m --args --ginkgo.v=true --ginkgo.focus="\[VPA\] \[${SUITE}\]" --report-dir=/workspace/_artifacts --disable-log-dump --ginkgo.timeout=90m
go test -mod vendor ./v1/*go -v --test.timeout=90m --args --ginkgo.v=true --ginkgo.focus="\[VPA\] \[${SUITE}\]" --report-dir=${WORKSPACE} --disable-log-dump --ginkgo.timeout=90m
V1_RESULT=$?
popd
echo v1beta2 test result: ${V1BETA2_RESULT}
Expand Down

0 comments on commit adba590

Please sign in to comment.