Skip to content

Commit

Permalink
add recommender vpa-object-namespace quick integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
phuhung273 committed Jan 25, 2025
1 parent 1c26181 commit 487ead7
Show file tree
Hide file tree
Showing 6 changed files with 446 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

# Copyright 2025 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

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/../../../..

export REGISTRY=${REGISTRY:-localhost:5001}
export TAG=${TAG:-latest}


REGISTRY=${REGISTRY} TAG=${TAG} ${SCRIPT_ROOT}/hack/vpa-process-yaml.sh ${SCRIPT_ROOT}/hack/e2e/deploy/recommender/ignored-vpa-object-namespaces.yaml | kubectl apply -f -

CHECK_CYCLES=15
CHECK_SLEEP=15

DEPLOYED=0

for i in $(seq 1 $CHECK_CYCLES); do
if [[ $(kubectl get deployments vpa-recommender -n kube-system -o jsonpath='{.status.unavailableReplicas}') -eq 0 ]]; then
echo "Verified vpa-recommender pod was scheduled and started!"
DEPLOYED=1
break
fi
echo "Assertion Loop $i/$CHECK_CYCLES, sleeping for $CHECK_SLEEP seconds"
sleep $CHECK_SLEEP
done

if [[ $DEPLOYED -eq 0 ]]; then
exit 1
fi

EXIT_STATUS=2
for i in $(seq 1 $CHECK_CYCLES); do
if kubectl describe vpa -n included-namespace included-vpa | grep Status; then
echo "Verified included namespaces are being tracked!"
EXIT_STATUS=0
break
fi
echo "Assertion Loop $i/$CHECK_CYCLES, sleeping for $CHECK_SLEEP seconds"
sleep $CHECK_SLEEP
done

if [[ $EXIT_STATUS -ne 0 ]];then
exit $EXIT_STATUS
fi

CHECK_CYCLES=5

for i in $(seq 1 $CHECK_CYCLES); do
if kubectl describe vpa -n ignored-namespace ignored-vpa | grep Status; then
echo "Failed! ignored namespaces should not be tracked!"
EXIT_STATUS=3
break
fi
echo "Assertion Loop $i/$CHECK_CYCLES, sleeping for $CHECK_SLEEP seconds"
sleep $CHECK_SLEEP
done

if [[ $EXIT_STATUS -ne 0 ]];then
exit $EXIT_STATUS
fi

echo "Verified ignored namespaces are still not tracked after wait time!"

REGISTRY=${REGISTRY} TAG=${TAG} ${SCRIPT_ROOT}/hack/vpa-process-yaml.sh ${SCRIPT_ROOT}/hack/e2e/deploy/recommender/ignored-vpa-object-namespaces.yaml | kubectl delete -f -
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: vpa-recommender
namespace: kube-system
spec:
replicas: 1
selector:
matchLabels:
app: vpa-recommender
template:
metadata:
labels:
app: vpa-recommender
spec:
serviceAccountName: vpa-recommender
securityContext:
runAsNonRoot: true
runAsUser: 65534 # nobody
containers:
- name: recommender
image: registry.k8s.io/autoscaling/vpa-recommender:1.2.2
imagePullPolicy: IfNotPresent
args:
- /recommender
- --ignored-vpa-object-namespaces=ignored-namespace
resources:
limits:
cpu: 200m
memory: 1000Mi
requests:
cpu: 50m
memory: 500Mi
ports:
- name: prometheus
containerPort: 8942
---
apiVersion: v1
kind: Namespace
metadata:
name: included-namespace
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: included-vpa
namespace: included-namespace
spec:
targetRef:
apiVersion: "apps/v1"
kind: Deployment
name: included-app
updatePolicy:
updateMode: "Auto"
---
apiVersion: v1
kind: Namespace
metadata:
name: ignored-namespace
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: ignored-vpa
namespace: ignored-namespace
spec:
targetRef:
apiVersion: "apps/v1"
kind: Deployment
name: ignored-app
updatePolicy:
updateMode: "Auto"
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

# Copyright 2025 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

SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/../../../..

export REGISTRY=${REGISTRY:-localhost:5001}
export TAG=${TAG:-latest}


REGISTRY=${REGISTRY} TAG=${TAG} ${SCRIPT_ROOT}/hack/vpa-process-yaml.sh ${SCRIPT_ROOT}/hack/e2e/deploy/recommender/vpa-object-namespace.yaml | kubectl apply -f -

CHECK_CYCLES=15
CHECK_SLEEP=15

DEPLOYED=0

for i in $(seq 1 $CHECK_CYCLES); do
if [[ $(kubectl get deployments vpa-recommender -n kube-system -o jsonpath='{.status.unavailableReplicas}') -eq 0 ]]; then
echo "Verified vpa-recommender pod was scheduled and started!"
DEPLOYED=1
break
fi
sleep $CHECK_SLEEP
done

if [[ $DEPLOYED -eq 0 ]]; then
exit 1
fi

EXIT_STATUS=2
for i in $(seq 1 $CHECK_CYCLES); do
if kubectl describe vpa -n included-namespace included-vpa | grep Status; then
echo "Verified included namespaces are being tracked!"
EXIT_STATUS=0
break
fi
echo "Assertion Loop $i/$CHECK_CYCLES, sleeping for $CHECK_SLEEP seconds"
sleep $CHECK_SLEEP
done

if [[ $EXIT_STATUS -ne 0 ]];then
exit $EXIT_STATUS
fi

CHECK_CYCLES=5

for i in $(seq 1 $CHECK_CYCLES); do
if kubectl describe vpa -n ignored-namespace ignored-vpa | grep Status; then
echo "Failed! ignored namespaces should not be tracked!"
EXIT_STATUS=3
break
fi
echo "Assertion Loop $i/$CHECK_CYCLES, sleeping for $CHECK_SLEEP seconds"
sleep $CHECK_SLEEP
done

if [[ $EXIT_STATUS -ne 0 ]];then
exit $EXIT_STATUS
fi

echo "Verified ignored namespaces are still not tracked after wait time!"

REGISTRY=${REGISTRY} TAG=${TAG} ${SCRIPT_ROOT}/hack/vpa-process-yaml.sh ${SCRIPT_ROOT}/hack/e2e/deploy/recommender/vpa-object-namespace.yaml | kubectl delete -f -
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: vpa-recommender
namespace: kube-system
spec:
replicas: 1
selector:
matchLabels:
app: vpa-recommender
template:
metadata:
labels:
app: vpa-recommender
spec:
serviceAccountName: vpa-recommender
securityContext:
runAsNonRoot: true
runAsUser: 65534 # nobody
containers:
- name: recommender
image: registry.k8s.io/autoscaling/vpa-recommender:1.2.2
imagePullPolicy: IfNotPresent
args:
- /recommender
- --vpa-object-namespace=included-namespace
resources:
limits:
cpu: 200m
memory: 1000Mi
requests:
cpu: 50m
memory: 500Mi
ports:
- name: prometheus
containerPort: 8942
---
apiVersion: v1
kind: Namespace
metadata:
name: included-namespace
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: included-vpa
namespace: included-namespace
spec:
targetRef:
apiVersion: "apps/v1"
kind: Deployment
name: included-app
updatePolicy:
updateMode: "Auto"
---
apiVersion: v1
kind: Namespace
metadata:
name: ignored-namespace
---
apiVersion: autoscaling.k8s.io/v1
kind: VerticalPodAutoscaler
metadata:
name: ignored-vpa
namespace: ignored-namespace
spec:
targetRef:
apiVersion: "apps/v1"
kind: Deployment
name: ignored-app
updatePolicy:
updateMode: "Auto"
4 changes: 4 additions & 0 deletions vertical-pod-autoscaler/hack/local-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ 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.

# Quick Integration Tests

`run-integration-locally.sh` is a quicker way to integration test compared to `run-e2e-locally.sh`. Only used for simple tests.
Loading

0 comments on commit 487ead7

Please sign in to comment.