Skip to content

Commit e7b3bfe

Browse files
committed
replace scripts with Chainsaw assertions in deployment policy tests
1 parent 30274a3 commit e7b3bfe

File tree

24 files changed

+400
-905
lines changed

24 files changed

+400
-905
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
3+
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
set -e
20+
21+
# Usage: label-nodes.sh <operation> <node_range> <label1=value1> [label2=value2] ...
22+
# Examples:
23+
# label-nodes.sh add 0-4 priority=critical skyhook.nvidia.com/test-node=skyhooke2e
24+
# label-nodes.sh remove 0-14 priority env region
25+
# label-nodes.sh clean-all skyhook.nvidia.com/test-node
26+
27+
OPERATION=$1
28+
shift
29+
30+
if [ "$OPERATION" = "clean-all" ]; then
31+
LABEL_PREFIX=$1
32+
echo "Cleaning all labels matching: $LABEL_PREFIX"
33+
kubectl label nodes --all "${LABEL_PREFIX}-" --overwrite 2>/dev/null || true
34+
echo "✓ Cleanup complete"
35+
exit 0
36+
fi
37+
38+
NODE_RANGE=$1
39+
shift
40+
41+
# Get all worker nodes (excluding control-plane)
42+
WORKERS=($(kubectl get nodes --no-headers -o custom-columns=NAME:.metadata.name | grep -v control-plane | sort))
43+
44+
# Parse node range
45+
if [[ $NODE_RANGE == *-* ]]; then
46+
START=$(echo $NODE_RANGE | cut -d'-' -f1)
47+
END=$(echo $NODE_RANGE | cut -d'-' -f2)
48+
else
49+
START=$NODE_RANGE
50+
END=$NODE_RANGE
51+
fi
52+
53+
# Validate we have enough nodes
54+
if [ ${#WORKERS[@]} -lt $((END + 1)) ]; then
55+
echo "ERROR: Need at least $((END + 1)) worker nodes for this operation"
56+
echo "Found: ${#WORKERS[@]} workers"
57+
exit 1
58+
fi
59+
60+
case "$OPERATION" in
61+
add)
62+
LABELS="$@"
63+
echo "Adding labels to nodes [$START-$END]: $LABELS"
64+
for i in $(seq $START $END); do
65+
if [ -n "${WORKERS[$i]}" ]; then
66+
kubectl label node ${WORKERS[$i]} $LABELS --overwrite
67+
fi
68+
done
69+
;;
70+
remove)
71+
LABELS_TO_REMOVE=""
72+
for label in "$@"; do
73+
LABELS_TO_REMOVE="$LABELS_TO_REMOVE ${label}-"
74+
done
75+
echo "Removing labels from nodes [$START-$END]: $@"
76+
for i in $(seq $START $END); do
77+
if [ -n "${WORKERS[$i]}" ]; then
78+
kubectl label node ${WORKERS[$i]} $LABELS_TO_REMOVE --overwrite 2>/dev/null || true
79+
fi
80+
done
81+
;;
82+
*)
83+
echo "ERROR: Unknown operation: $OPERATION"
84+
echo "Usage: $0 {add|remove|clean-all} ..."
85+
exit 1
86+
;;
87+
esac
88+
89+
echo "✓ Operation complete"
90+

k8s-tests/chainsaw/deployment-policy/legacy-compatibility/cleanup-nodes.sh renamed to k8s-tests/chainsaw/deployment-policy/legacy-compatibility/assert-default-compartment.yaml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/bin/bash
2-
31
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
42
# SPDX-License-Identifier: Apache-2.0
53
#
@@ -19,11 +17,12 @@
1917
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2018
# SPDX-License-Identifier: Apache-2.0
2119

22-
set -e
23-
24-
echo "Cleaning up node labels..."
25-
26-
# Remove test labels from all nodes
27-
kubectl label nodes --all skyhook.nvidia.com/test-node- --overwrite || true
28-
29-
echo "✓ Cleanup complete!"
20+
apiVersion: skyhook.nvidia.com/v1alpha1
21+
kind: Skyhook
22+
metadata:
23+
name: legacy-interruption-budget-test
24+
status:
25+
compartmentStatuses:
26+
__default__:
27+
matched: 6
28+
ceiling: 3

k8s-tests/chainsaw/deployment-policy/legacy-compatibility/chainsaw-test.yaml

Lines changed: 14 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -37,99 +37,28 @@ spec:
3737
try:
3838
- script:
3939
content: |
40-
chmod +x setup-nodes.sh cleanup-nodes.sh
41-
./setup-nodes.sh
40+
chmod +x ../label-nodes.sh
41+
# Clean up any existing labels from previous tests
42+
../label-nodes.sh clean-all skyhook.nvidia.com/test-node
43+
# Label first 6 worker nodes
44+
../label-nodes.sh add 0-5 skyhook.nvidia.com/test-node=skyhooke2e
45+
echo "✓ Node labeling complete"
46+
kubectl get nodes -L skyhook.nvidia.com/test-node --sort-by=.metadata.name | head -8
4247
4348
- name: apply-skyhook
4449
try:
4550
- apply:
4651
file: skyhook.yaml
47-
- script:
48-
content: |
49-
echo "Waiting for Skyhook to initialize..."
50-
sleep 10
51-
52-
- name: verify-default-compartment-created
53-
try:
54-
- script:
55-
content: |
56-
echo "=== Verifying synthetic __default__ compartment ==="
57-
58-
COMPARTMENTS=$(kubectl get skyhook legacy-interruption-budget-test -o jsonpath='{.status.compartmentStatuses}' | jq -r 'keys[]')
59-
echo "Compartments found: $COMPARTMENTS"
60-
61-
DEFAULT=$(echo "$COMPARTMENTS" | grep -c "__default__" || echo "0")
62-
63-
if [ "$DEFAULT" != "1" ]; then
64-
echo "ERROR: Expected __default__ compartment to be created"
65-
echo "Found compartments: $COMPARTMENTS"
66-
kubectl get skyhook legacy-interruption-budget-test -o yaml
67-
exit 1
68-
fi
69-
70-
echo "✓ Synthetic __default__ compartment created"
71-
72-
- name: verify-compartment-uses-fixed-strategy
73-
try:
74-
- script:
75-
content: |
76-
echo "=== Verifying FixedStrategy is used ==="
77-
78-
# Get the compartment details from status
79-
MATCHED=$(kubectl get skyhook legacy-interruption-budget-test \
80-
-o jsonpath='{.status.compartmentStatuses.__default__.matched}')
81-
82-
echo "Nodes matched: $MATCHED (expected: 6)"
83-
84-
if [ "$MATCHED" != "6" ]; then
85-
echo "ERROR: Expected 6 nodes in default compartment, got $MATCHED"
86-
kubectl get skyhook legacy-interruption-budget-test -o yaml
87-
exit 1
88-
fi
89-
90-
echo "✓ All nodes assigned to __default__ compartment"
52+
- sleep:
53+
duration: 10s
9154

92-
- name: verify-budget-ceiling-configured
55+
- name: verify-default-compartment
9356
try:
94-
- script:
95-
content: |
96-
echo "=== Verifying budget ceiling is configured ==="
97-
98-
CEILING=$(kubectl get skyhook legacy-interruption-budget-test \
99-
-o jsonpath='{.status.compartmentStatuses.__default__.ceiling}')
100-
101-
echo "Configured ceiling: $CEILING (expected: 3)"
102-
103-
if [ "$CEILING" != "3" ]; then
104-
echo "ERROR: Expected ceiling of 3 (from interruptionBudget count), got $CEILING"
105-
kubectl get skyhook legacy-interruption-budget-test -o yaml
106-
exit 1
107-
fi
108-
109-
echo "✓ Budget ceiling configured correctly from InterruptionBudget"
57+
- assert:
58+
file: assert-default-compartment.yaml
11059

111-
- name: verify-final-state
60+
- name: verify-metrics
11261
try:
113-
- script:
114-
content: |
115-
echo "=== Verifying legacy compatibility ==="
116-
117-
CEILING=$(kubectl get skyhook legacy-interruption-budget-test -o jsonpath='{.status.compartmentStatuses.__default__.ceiling}')
118-
MATCHED=$(kubectl get skyhook legacy-interruption-budget-test -o jsonpath='{.status.compartmentStatuses.__default__.matched}')
119-
120-
echo "Final verification:"
121-
echo " - Synthetic __default__ compartment: ✓"
122-
echo " - Budget ceiling from interruptionBudget: $CEILING"
123-
echo " - Matched nodes: $MATCHED"
124-
125-
if [ "$CEILING" != "3" ] || [ "$MATCHED" != "6" ]; then
126-
echo "ERROR: Legacy compatibility verification failed"
127-
exit 1
128-
fi
129-
130-
echo ""
131-
echo "✓✓✓ Legacy InterruptionBudget compatibility verified! ✓✓✓"
132-
echo "Existing customers can continue using interruptionBudget safely."
13362
- script:
13463
content: |
13564
echo "=== Verifying legacy compatibility metrics ==="
@@ -146,4 +75,4 @@ spec:
14675
try:
14776
- script:
14877
content: |
149-
./cleanup-nodes.sh || true
78+
../label-nodes.sh clean-all skyhook.nvidia.com/test-node

k8s-tests/chainsaw/deployment-policy/legacy-compatibility/setup-nodes.sh

Lines changed: 0 additions & 43 deletions
This file was deleted.

k8s-tests/chainsaw/deployment-policy/linear-strategy/cleanup-nodes.sh renamed to k8s-tests/chainsaw/deployment-policy/linear-strategy/assert-compartment.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/bin/bash
2-
31
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
42
# SPDX-License-Identifier: Apache-2.0
53
#
@@ -19,9 +17,12 @@
1917
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2018
# SPDX-License-Identifier: Apache-2.0
2119

22-
set -e
23-
24-
echo "Cleaning up node labels..."
25-
kubectl label nodes --all tier- 2>/dev/null || true
26-
kubectl label nodes --all skyhook.nvidia.com/test-node- 2>/dev/null || true
27-
echo "✓ Cleanup complete"
20+
apiVersion: skyhook.nvidia.com/v1alpha1
21+
kind: Skyhook
22+
metadata:
23+
name: linear-strategy-test
24+
status:
25+
compartmentStatuses:
26+
production:
27+
matched: 8
28+
ceiling: 4

k8s-tests/chainsaw/deployment-policy/multi-compartment/cleanup-nodes.sh renamed to k8s-tests/chainsaw/deployment-policy/linear-strategy/assert-complete.yaml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/bin/bash
2-
31
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
42
# SPDX-License-Identifier: Apache-2.0
53
#
@@ -19,9 +17,14 @@
1917
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2018
# SPDX-License-Identifier: Apache-2.0
2119

22-
set -e
23-
24-
echo "Cleaning up node labels..."
25-
kubectl label nodes --all priority- 2>/dev/null || true
26-
kubectl label nodes --all skyhook.nvidia.com/test-node- 2>/dev/null || true
27-
echo "✓ Cleanup complete"
20+
apiVersion: skyhook.nvidia.com/v1alpha1
21+
kind: Skyhook
22+
metadata:
23+
name: linear-strategy-test
24+
status:
25+
status: complete
26+
compartmentStatuses:
27+
production:
28+
completed: 8
29+
inProgress: 0
30+
progressPercent: 100

0 commit comments

Comments
 (0)