1
0
mirror of https://github.com/kubernetes/autoscaler.git synced 2025-02-06 10:02:26 +00:00

Modify the e2e local scripts so they can be run on a modern Mac

This commit is contained in:
Adrian Moisey 2024-10-31 21:54:20 +02:00
parent a6a77b3ec3
commit 7bf5bb0f05
No known key found for this signature in database
GPG Key ID: 41AE4AE32747C7CF
12 changed files with 116 additions and 80 deletions

3
.gitignore vendored
View File

@ -31,3 +31,6 @@ Session.vim
# Binary files
bin/
# vertical pod autoscaler test output
vertical-pod-autoscaler/e2e/v1*/workspace/

View File

@ -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:

View File

@ -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

View File

@ -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:

View File

@ -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
@ -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}
@ -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

View File

@ -1,58 +0,0 @@
#!/bin/sh
# 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.
# Based on https://kind.sigs.k8s.io/examples/kind-with-registry.sh
set -o errexit
# Create registry container unless it already exists
reg_name='kind-registry'
reg_port='5001'
if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then
docker run \
-d --restart=always -p "127.0.0.1:${reg_port}:5000" --name "${reg_name}" \
registry:2
fi
# Create a cluster with the local registry enabled in containerd
cat <<EOF | kind create cluster --image=kindest/node:v1.26.3 --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${reg_port}"]
endpoint = ["http://${reg_name}:5000"]
EOF
# Connect the registry to the cluster network if not already connected
if [ "$(docker inspect -f='{{json .NetworkSettings.Networks.kind}}' "${reg_name}")" = 'null' ]; then
docker network connect "kind" "${reg_name}"
fi
# Document the local registry
# https://github.com/kubernetes/enhancements/tree/master/keps/sig-cluster-lifecycle/generic/1755-communicating-a-local-registry
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost:${reg_port}"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF

View File

@ -21,7 +21,7 @@ spec:
containers:
- name: metrics-pump
image: localhost:5001/write-metrics:dev
imagePullPolicy: Always
imagePullPolicy: IfNotPresent
args:
- /emit-metrics.py
- --dest

View File

@ -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

View File

@ -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}"
}

View File

@ -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:
@ -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.

View File

@ -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
@ -38,28 +43,44 @@ fi
SUITE=$1
for i in kind docker; do
if ! command -v $i 2>&1 > /dev/null
then
echo "$i could not be found"
exit 1;
fi
done
if ! docker ps 2>&1 >/dev/null
then
echo "docker isn't 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 create cluster --image=kindest/node:v1.26.3
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
;;
*)

View File

@ -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}