Skip to content

Commit

Permalink
add test case for bin-packing scoring strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanad committed Aug 12, 2024
1 parent c489b41 commit 67b2632
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/e2e/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ source test/e2e/webhook_ready.sh
source test/e2e/no-rogue-finalizer/test.sh
source test/e2e/delete-chaperon/test.sh
source test/e2e/delete-delegate/test.sh
source test/e2e/plugin-config-scoring-strategy/test.sh

argo_setup_once
cert_manager_setup_once
Expand Down Expand Up @@ -79,6 +80,7 @@ virtual-node-labels_test 1 2
cleanup_test 1
delete-chaperon_test 1
delete-delegate_test 1 2
plugin-config-scoring-strategy_test 1 2
no-reservation_test

no-rogue-finalizer_test
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
2 changes: 1 addition & 1 deletion test/e2e/kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ kind_setup() {
CLUSTER=cluster$i

if ! kind get clusters | grep $CLUSTER; then
kind create cluster --name $CLUSTER --wait 5m --image "${kind_images["$K8S_VERSION"]}"
kind create cluster --name $CLUSTER --wait 5m --image "${kind_images["$K8S_VERSION"]}" --config test/e2e/kind-config.yaml
fi
NODE_IP=$(docker inspect "${CLUSTER}-control-plane" --format "{{ .NetworkSettings.Networks.kind.IPAddress }}")
kind get kubeconfig --name $CLUSTER --internal | \
Expand Down
56 changes: 56 additions & 0 deletions test/e2e/plugin-config-scoring-strategy/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash
#
# Copyright 2024 The Multicluster-Scheduler 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 -euo pipefail

source test/e2e/aliases.sh

plugin-config-scoring-strategy_test() {
i=$1
j=$2
k $j label node --all a=b --overwrite

# Find the node with the highest CPU utilization
nodes=$(k $j get nodes -o name | sed s/"node\/"//)
most_allocated=""
most_cpu_requests="0"
for node in $nodes; do
cpu_requests=$(k $j describe node "$node" | grep -A5 "Allocated" | awk '{print $3}' | sed -n '5p' | tr -d '()%')
echo "node: $node, cpu requests: $cpu_requests"
if [[ "$cpu_requests" -ge "$most_cpu_requests" ]]
then
most_cpu_requests=$cpu_requests
most_allocated=$node
fi
done

k $i apply -f test/e2e/plugin-config-scoring-strategy/test.yaml
k $i wait pod test-scoring-strategy --for=condition=PodScheduled

node_scheduled="$(k $j get pod -o json | jq -er '.items[0].spec.nodeName')"
k $i delete -f test/e2e/plugin-config-scoring-strategy/test.yaml
k $j label node --all a-
if [ "$node_scheduled" != "$most_allocated" ]
then
echo "delegate pod was assigned to an unexpected node. Expected node $most_allocated, got assigned to $node_scheduled"
exit 1
fi
}

if [[ "${BASH_SOURCE[0]:-}" == "${0}" ]]; then
plugin-config-scoring-strategy_test "${@}"
fi
15 changes: 15 additions & 0 deletions test/e2e/plugin-config-scoring-strategy/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: test-scoring-strategy
annotations:
multicluster.admiralty.io/elect: ""
spec:
nodeSelector:
a: b
containers:
- name: pause
image: gcr.io/google_containers/pause
resources:
requests:
cpu: 1m
10 changes: 10 additions & 0 deletions test/e2e/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ controllerManager:
scheduler:
securityContext:
runAsUser: 1000
# Scoring config favors the node with the highest cpu
candidate:
pluginConfig:
- name: NodeResourcesFit
args:
scoringStrategy:
resources:
- name: cpu
weight: 10
type: MostAllocated

postDeleteJob:
securityContext:
Expand Down

0 comments on commit 67b2632

Please sign in to comment.