Skip to content

Commit a99932a

Browse files
committed
VPA: Allow deploying InPlaceOrRecreate in local e2e and ci
Allows you to specify an env var FEATURE_GATES which adds feature gates to all vpa components during vpa-up and e2e tests. Also allows local e2e tests to run kind with a new kind-config file which enables KEP-1287 InPlacePodVerticalScaling feature gate. Separates the admission-controller service into a separate deploy manifest. Signed-off-by: Max Cao <[email protected]>
1 parent de4a5b7 commit a99932a

File tree

9 files changed

+55
-19
lines changed

9 files changed

+55
-19
lines changed

vertical-pod-autoscaler/deploy/admission-controller-deployment.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,3 @@ spec:
4747
- name: tls-certs
4848
secret:
4949
secretName: vpa-tls-certs
50-
---
51-
apiVersion: v1
52-
kind: Service
53-
metadata:
54-
name: vpa-webhook
55-
namespace: kube-system
56-
spec:
57-
ports:
58-
- port: 443
59-
targetPort: 8000
60-
selector:
61-
app: vpa-admission-controller
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: vpa-webhook
5+
namespace: kube-system
6+
spec:
7+
ports:
8+
- port: 443
9+
targetPort: 8000
10+
selector:
11+
app: vpa-admission-controller

vertical-pod-autoscaler/docs/installation.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ To print YAML contents with all resources that would be understood by
138138
The output of that command won't include secret information generated by
139139
[pkg/admission-controller/gencerts.sh](https://github.com/kubernetes/autoscaler/tree/master/vertical-pod-autoscaler/pkg/admission-controller/gencerts.sh) script.
140140

141+
### Feature gates
142+
143+
To install VPA with feature gates, you can specify the environment variable `$FEATURE_GATES`.
144+
145+
For example, to enable the `InPlaceOrRecreate` feature gate:
146+
147+
```console
148+
FEATURE_GATES="InPlaceOrRecreate=true" ./hack/vpa-up.sh
149+
```
150+
141151
## Tear down
142152

143153
Note that if you stop running VPA in your cluster, the resource requests

vertical-pod-autoscaler/hack/deploy-for-e2e-locally.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ for i in ${COMPONENTS}; do
8080
fi
8181
if [ $i == admission-controller ] ; then
8282
(cd ${SCRIPT_ROOT}/pkg/${i} && bash ./gencerts.sh e2e || true)
83+
kubectl apply -f ${SCRIPT_ROOT}/deploy/admission-controller-service.yaml
8384
fi
8485
ALL_ARCHITECTURES=${ARCH} make --directory ${SCRIPT_ROOT}/pkg/${i} docker-build REGISTRY=${REGISTRY} TAG=${TAG}
8586
docker tag ${REGISTRY}/vpa-${i}-${ARCH}:${TAG} ${REGISTRY}/vpa-${i}:${TAG}
8687
kind load docker-image ${REGISTRY}/vpa-${i}:${TAG}
8788
done
8889

89-
9090
for i in ${COMPONENTS}; do
9191
if [ $i == recommender-externalmetrics ] ; then
9292
kubectl delete namespace monitoring --ignore-not-found=true
@@ -96,6 +96,6 @@ for i in ${COMPONENTS}; do
9696
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/metrics-pump.yaml
9797
kubectl apply -f ${SCRIPT_ROOT}/hack/e2e/${i}-deployment.yaml
9898
else
99-
REGISTRY=${REGISTRY} TAG=${TAG} ${SCRIPT_ROOT}/hack/vpa-process-yaml.sh ${SCRIPT_ROOT}/deploy/${i}-deployment.yaml | kubectl apply -f -
99+
REGISTRY=${REGISTRY} TAG=${TAG} ${SCRIPT_ROOT}/hack/vpa-process-yaml.sh ${SCRIPT_ROOT}/deploy/${i}-deployment.yaml | kubectl apply -f -
100100
fi
101101
done

vertical-pod-autoscaler/hack/deploy-for-e2e.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ gcloud auth configure-docker -q
6969
for i in ${COMPONENTS}; do
7070
if [ $i == admission-controller ] ; then
7171
(cd ${SCRIPT_ROOT}/pkg/${i} && bash ./gencerts.sh e2e || true)
72+
kubectl apply -f ${SCRIPT_ROOT}/deploy/admission-controller-service.yaml
7273
fi
7374
ALL_ARCHITECTURES=amd64 make --directory ${SCRIPT_ROOT}/pkg/${i} release
7475
done
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
featureGates:
4+
InPlacePodVerticalScaling: true

vertical-pod-autoscaler/hack/run-e2e-locally.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ kind delete cluster -n kind -q
7575

7676
echo "Creating KIND cluster 'kind'"
7777
KIND_VERSION="kindest/node:v1.32.0"
78-
if ! kind create cluster --image=${KIND_VERSION}; then
78+
if ! kind create cluster --image=${KIND_VERSION} --config ${SCRIPT_ROOT}/hack/kind-config.yaml; then
7979
echo "Failed to create KIND cluster. Exiting. Make sure kind version is updated."
8080
echo "Available versions: https://github.com/kubernetes-sigs/kind/releases"
8181
exit 1

vertical-pod-autoscaler/hack/vpa-process-yaml.sh

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,34 @@ set -o errexit
1818
set -o nounset
1919
set -o pipefail
2020

21-
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/..
22-
2321
function print_help {
2422
echo "ERROR! Usage: vpa-process-yaml.sh <YAML files>+"
2523
echo "Script will output content of YAML files separated with YAML document"
2624
echo "separator and substituting REGISTRY and TAG for pod images"
2725
}
2826

27+
# Requires input from stdin, otherwise hangs. Checks for "admission-controller", "updater", or "recommender", and
28+
# applies the respective kubectl patch command to add the feature gates specified in the FEATURE_GATES environment variable.
29+
# e.g. cat file.yaml | apply_feature_gate
30+
function apply_feature_gate() {
31+
local input=""
32+
while IFS= read -r line; do
33+
input+="$line"$'\n'
34+
done
35+
36+
if [ -n "${FEATURE_GATES}" ]; then
37+
if echo "$input" | grep -q "admission-controller"; then
38+
echo "$input" | kubectl patch --type=json --local -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--feature-gates='"${FEATURE_GATES}"'"}]' -o yaml -f -
39+
elif echo "$input" | grep -q "updater" || echo "$input" | grep -q "recommender"; then
40+
echo "$input" | kubectl patch --type=json --local -p='[{"op": "add", "path": "/spec/template/spec/containers/0/args", "value": ["--feature-gates='"${FEATURE_GATES}"'"]}]' -o yaml -f -
41+
else
42+
echo "$input"
43+
fi
44+
else
45+
echo "$input"
46+
fi
47+
}
48+
2949
if [ $# -eq 0 ]; then
3050
print_help
3151
exit 1
@@ -36,6 +56,7 @@ DEFAULT_TAG="1.3.0"
3656

3757
REGISTRY_TO_APPLY=${REGISTRY-$DEFAULT_REGISTRY}
3858
TAG_TO_APPLY=${TAG-$DEFAULT_TAG}
59+
FEATURE_GATES=${FEATURE_GATES:-""}
3960

4061
if [ "${REGISTRY_TO_APPLY}" != "${DEFAULT_REGISTRY}" ]; then
4162
(>&2 echo "WARNING! Using image repository from REGISTRY env variable (${REGISTRY_TO_APPLY}) instead of ${DEFAULT_REGISTRY}.")
@@ -46,7 +67,6 @@ if [ "${TAG_TO_APPLY}" != "${DEFAULT_TAG}" ]; then
4667
fi
4768

4869
for i in $*; do
49-
sed -e "s,${DEFAULT_REGISTRY}/\([a-z-]*\):.*,${REGISTRY_TO_APPLY}/\1:${TAG_TO_APPLY}," $i
50-
echo ""
70+
sed -e "s,${DEFAULT_REGISTRY}/\([a-z-]*\):.*,${REGISTRY_TO_APPLY}/\1:${TAG_TO_APPLY}," $i | apply_feature_gate
5171
echo "---"
5272
done

vertical-pod-autoscaler/hack/vpa-process-yamls.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ for i in $COMPONENTS; do
6666
if [[ ${ACTION} == create || ${ACTION} == apply ]] ; then
6767
# Allow gencerts to fail silently if certs already exist
6868
(bash ${SCRIPT_ROOT}/pkg/admission-controller/gencerts.sh || true)
69+
kubectl apply -f ${SCRIPT_ROOT}/deploy/admission-controller-service.yaml
6970
elif [ ${ACTION} == delete ] ; then
7071
(bash ${SCRIPT_ROOT}/pkg/admission-controller/rmcerts.sh || true)
7172
(bash ${SCRIPT_ROOT}/pkg/admission-controller/delete-webhook.sh || true)
73+
kubectl delete -f ${SCRIPT_ROOT}/deploy/admission-controller-service.yaml
7274
fi
7375
fi
7476
if [[ ${ACTION} == print ]]; then

0 commit comments

Comments
 (0)