Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 96 additions & 23 deletions vertical-pod-autoscaler/hack/deploy-for-e2e-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,108 @@ esac
export REGISTRY=${REGISTRY:-localhost:5001}
export TAG=${TAG:-latest}

rm -f ${SCRIPT_ROOT}/hack/e2e/vpa-rbac.yaml
patch -c ${SCRIPT_ROOT}/deploy/vpa-rbac.yaml -i ${SCRIPT_ROOT}/hack/e2e/vpa-rbac.diff -o ${SCRIPT_ROOT}/hack/e2e/vpa-rbac.yaml
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/vpa-rbac.yaml
# Other-versioned CRDs are irrelevant as we're running a modern-ish cluster.
kubectl apply -f ${SCRIPT_ROOT}/deploy/vpa-v1-crd-gen.yaml
# Deploy metrics server for E2E tests
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/k8s-metrics-server.yaml

# Build and load Docker images for each component
for i in ${COMPONENTS}; do
COMPONENT_NAME=$i
Comment on lines 74 to +75
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified:

Suggested change
for i in ${COMPONENTS}; do
COMPONENT_NAME=$i
for COMPONENT_NAME in ${COMPONENTS}; do

However, I'd prefer the following:

Suggested change
for i in ${COMPONENTS}; do
COMPONENT_NAME=$i
for COMPONENT in ${COMPONENTS}; do

But I'm not strongly opinionated on that.

if [ $i == recommender-externalmetrics ] ; then
i=recommender
COMPONENT_NAME=recommender
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes sense to modify the case statement on line 50 to add:

  recommender-externalmetrics)
    COMPONENTS="recommender"
    ;;

Then this exception doesn't need to be handled here, and line 96 lower down can also be neater.

if [ $i == admission-controller ] ; then
(cd ${SCRIPT_ROOT}/pkg/${i} && bash ./gencerts.sh e2e || true)
kubectl apply -f ${SCRIPT_ROOT}/deploy/admission-controller-service.yaml
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}
ALL_ARCHITECTURES=${ARCH} make --directory ${SCRIPT_ROOT}/pkg/${COMPONENT_NAME} docker-build REGISTRY=${REGISTRY} TAG=${TAG}
docker tag ${REGISTRY}/vpa-${COMPONENT_NAME}-${ARCH}:${TAG} ${REGISTRY}/vpa-${COMPONENT_NAME}:${TAG}
kind load docker-image ${REGISTRY}/vpa-${COMPONENT_NAME}:${TAG}
done

# Prepare Helm values
HELM_CHART_PATH="${SCRIPT_ROOT}/charts/vertical-pod-autoscaler"
VALUES_FILE="${SCRIPT_ROOT}/hack/e2e/values-e2e-local.yaml"
HELM_RELEASE_NAME="vpa"
HELM_NAMESPACE="kube-system"

# Build dynamic Helm set arguments based on components
HELM_SET_ARGS=""

# Enable components based on suite
for i in ${COMPONENTS}; do
if [ $i == recommender-externalmetrics ] ; then
kubectl delete namespace monitoring --ignore-not-found=true
kubectl create namespace monitoring
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/prometheus.yaml
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/prometheus-adapter.yaml
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/metrics-pump.yaml
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/${i}-deployment.yaml
else
REGISTRY=${REGISTRY} TAG=${TAG} ${SCRIPT_ROOT}/hack/vpa-process-yaml.sh ${SCRIPT_ROOT}/deploy/${i}-deployment.yaml | kubectl apply -f -
fi
case $i in
recommender|recommender-externalmetrics)
HELM_SET_ARGS="${HELM_SET_ARGS} --set recommender.enabled=true"
HELM_SET_ARGS="${HELM_SET_ARGS} --set recommender.image.repository=${REGISTRY}/vpa-recommender"
HELM_SET_ARGS="${HELM_SET_ARGS} --set recommender.image.tag=${TAG}"
;;
updater)
HELM_SET_ARGS="${HELM_SET_ARGS} --set updater.enabled=true"
HELM_SET_ARGS="${HELM_SET_ARGS} --set updater.image.repository=${REGISTRY}/vpa-updater"
HELM_SET_ARGS="${HELM_SET_ARGS} --set updater.image.tag=${TAG}"
;;
admission-controller)
HELM_SET_ARGS="${HELM_SET_ARGS} --set admissionController.enabled=true"
HELM_SET_ARGS="${HELM_SET_ARGS} --set admissionController.image.repository=${REGISTRY}/vpa-admission-controller"
HELM_SET_ARGS="${HELM_SET_ARGS} --set admissionController.image.tag=${TAG}"
;;
esac
Comment on lines +95 to +111
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if it will be better to have a dedicated values file for each (with default configurations) , and then developers could just tweak the files as they see fit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh we already have this here: vertical-pod-autoscaler/hack/e2e/values-e2e-local.yaml , so this is just for the image repo and tag. makes sense to me.

done

# Add feature gates if specified
if [ -n "${FEATURE_GATES:-}" ]; then
# Add feature gates to each enabled component
for i in ${COMPONENTS}; do
case $i in
recommender|recommender-externalmetrics)
HELM_SET_ARGS="${HELM_SET_ARGS} --set recommender.extraArgs[0]=--feature-gates=${FEATURE_GATES}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a thought, and your PR doesn't need to address this: The helm chart could cater for feature flags, that way we don't need to use extraArgs for it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

;;
updater)
HELM_SET_ARGS="${HELM_SET_ARGS} --set updater.extraArgs[0]=--feature-gates=${FEATURE_GATES}"
;;
admission-controller)
HELM_SET_ARGS="${HELM_SET_ARGS} --set admissionController.extraArgs[0]=--feature-gates=${FEATURE_GATES}"
;;
esac
done
fi

# Uninstall any existing VPA Helm release
helm uninstall ${HELM_RELEASE_NAME} --namespace ${HELM_NAMESPACE} 2>/dev/null || true

# Install VPA using Helm chart
echo " ** Installing VPA via Helm chart"
helm install ${HELM_RELEASE_NAME} ${HELM_CHART_PATH} \
--namespace ${HELM_NAMESPACE} \
--values ${VALUES_FILE} \
${HELM_SET_ARGS} \
--wait
Comment on lines +135 to +141
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is an e2e testing it may be useful to add --debug ( so you can just scroll and see what you just deployed ). not strong opinions on this, but personally I would like that.


# Handle external metrics special case
if [[ "${SUITE}" == "recommender-externalmetrics" ]]; then
echo " ** Setting up external metrics infrastructure"

# Apply extra RBAC for external metrics
rm -f ${SCRIPT_ROOT}/hack/e2e/vpa-rbac.yaml
patch -c ${SCRIPT_ROOT}/deploy/vpa-rbac.yaml -i ${SCRIPT_ROOT}/hack/e2e/vpa-rbac.diff -o ${SCRIPT_ROOT}/hack/e2e/vpa-rbac.yaml
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/vpa-rbac.yaml
Comment on lines +147 to +150
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The helm chart should handle this.
You don't need to fix this in this PR, if you don't we must just take note of that and remember to update the helm chart.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


# Deploy Prometheus and adapter for external metrics
kubectl delete namespace monitoring --ignore-not-found=true
kubectl create namespace monitoring
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/prometheus.yaml
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/prometheus-adapter.yaml
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/metrics-pump.yaml

# Upgrade Helm release with external metrics configuration
echo " ** Updating recommender with external metrics args"
# Determine starting index for external metrics args (after feature gates if set)
EXTERNAL_METRICS_START_INDEX=0
if [ -n "${FEATURE_GATES:-}" ]; then
EXTERNAL_METRICS_START_INDEX=1
fi
helm upgrade ${HELM_RELEASE_NAME} ${HELM_CHART_PATH} \
--namespace ${HELM_NAMESPACE} \
--values ${VALUES_FILE} \
${HELM_SET_ARGS} \
--set "recommender.extraArgs[${EXTERNAL_METRICS_START_INDEX}]=--use-external-metrics=true" \
--set "recommender.extraArgs[$((EXTERNAL_METRICS_START_INDEX + 1))]=--external-metrics-cpu-metric=cpu" \
--set "recommender.extraArgs[$((EXTERNAL_METRICS_START_INDEX + 2))]=--external-metrics-memory-metric=mem" \
--wait
fi
Comment on lines +144 to +174
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this block all happen before the helm install?
That way we don't need a helm install followed by a helm upgrade

1 change: 1 addition & 0 deletions vertical-pod-autoscaler/hack/dev-deploy-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ REQUIRED_COMMANDS="
docker
git
go
helm
kubectl
make
"
Expand Down
51 changes: 51 additions & 0 deletions vertical-pod-autoscaler/hack/e2e/values-e2e-local.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Helm values for local E2E testing
# Used by deploy-for-e2e-locally.sh

# Image settings - will be overridden via --set at install time
# admissionController.image.repository, admissionController.image.tag, etc.

# Pod security context
podSecurityContext:
runAsNonRoot: true
runAsUser: 65534
Comment on lines +7 to +10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do really need we need to add this?


# Component configurations optimized for local KIND cluster
admissionController:
enabled: false # Enabled dynamically based on suite
replicas: 1
image:
pullPolicy: Never
# Disable pod anti-affinity for single-node clusters
affinity: {}
podDisruptionBudget:
enabled: false
# Use Helm-managed webhook (certgen creates certificates)
registerWebhook: false
certGen:
enabled: true

recommender:
enabled: false # Enabled dynamically based on suite
replicas: 1
image:
pullPolicy: Never
# Disable pod anti-affinity for single-node clusters
affinity: {}
podDisruptionBudget:
enabled: false
# Disable leader election for single replica
leaderElection:
enabled: false

updater:
enabled: false # Enabled dynamically based on suite
replicas: 1
image:
pullPolicy: Never
# Disable pod anti-affinity for single-node clusters
affinity: {}
podDisruptionBudget:
enabled: false
# Disable leader election for single replica
leaderElection:
enabled: false
4 changes: 3 additions & 1 deletion vertical-pod-autoscaler/hack/run-e2e-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ SUITE=$1
REQUIRED_COMMANDS="
docker
go
helm
kind
kubectl
make
Expand Down Expand Up @@ -97,7 +98,8 @@ fi

case ${SUITE} in
recommender|recommender-externalmetrics|updater|admission-controller|actuation|full-vpa)
${SCRIPT_ROOT}/hack/vpa-down.sh
# Cleanup any existing VPA Helm release
helm uninstall vpa --namespace kube-system 2>/dev/null || true
echo " ** Deploying for suite ${SUITE}"
${SCRIPT_ROOT}/hack/deploy-for-e2e-locally.sh ${SUITE}

Expand Down