From 67b2632c4b86df9b7616ded78f7beba2c8ed0f95 Mon Sep 17 00:00:00 2001 From: Marwan Ahmed Date: Sun, 11 Aug 2024 13:11:57 -0700 Subject: [PATCH] add test case for bin-packing scoring strategy --- test/e2e/e2e.sh | 2 + test/e2e/kind-config.yaml | 6 ++ test/e2e/kind.sh | 2 +- .../plugin-config-scoring-strategy/test.sh | 56 +++++++++++++++++++ .../plugin-config-scoring-strategy/test.yaml | 15 +++++ test/e2e/values.yaml | 10 ++++ 6 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 test/e2e/kind-config.yaml create mode 100644 test/e2e/plugin-config-scoring-strategy/test.sh create mode 100644 test/e2e/plugin-config-scoring-strategy/test.yaml diff --git a/test/e2e/e2e.sh b/test/e2e/e2e.sh index 7334509e..270aa806 100755 --- a/test/e2e/e2e.sh +++ b/test/e2e/e2e.sh @@ -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 @@ -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 diff --git a/test/e2e/kind-config.yaml b/test/e2e/kind-config.yaml new file mode 100644 index 00000000..ae8cd304 --- /dev/null +++ b/test/e2e/kind-config.yaml @@ -0,0 +1,6 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: + - role: control-plane + - role: worker + - role: worker diff --git a/test/e2e/kind.sh b/test/e2e/kind.sh index 05313e23..2797539b 100755 --- a/test/e2e/kind.sh +++ b/test/e2e/kind.sh @@ -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 | \ diff --git a/test/e2e/plugin-config-scoring-strategy/test.sh b/test/e2e/plugin-config-scoring-strategy/test.sh new file mode 100644 index 00000000..27b3a3e4 --- /dev/null +++ b/test/e2e/plugin-config-scoring-strategy/test.sh @@ -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 diff --git a/test/e2e/plugin-config-scoring-strategy/test.yaml b/test/e2e/plugin-config-scoring-strategy/test.yaml new file mode 100644 index 00000000..765a7998 --- /dev/null +++ b/test/e2e/plugin-config-scoring-strategy/test.yaml @@ -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 \ No newline at end of file diff --git a/test/e2e/values.yaml b/test/e2e/values.yaml index b4cfc9d8..42c95377 100644 --- a/test/e2e/values.yaml +++ b/test/e2e/values.yaml @@ -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: