|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json |
| 18 | +apiVersion: chainsaw.kyverno.io/v1alpha1 |
| 19 | +kind: Test |
| 20 | +metadata: |
| 21 | + name: cli-node |
| 22 | +spec: |
| 23 | + description: | |
| 24 | + Test all CLI node commands: |
| 25 | + - node list: shows nodes targeted by a Skyhook |
| 26 | + - node status: shows Skyhook activity on nodes |
| 27 | + - node ignore/unignore: excludes/includes nodes from processing |
| 28 | + - node reset: resets package state on a node |
| 29 | + timeouts: |
| 30 | + assert: 120s |
| 31 | + exec: 90s |
| 32 | + steps: |
| 33 | + # Step 1: Create a Skyhook and wait for activity |
| 34 | + - name: setup-skyhook |
| 35 | + try: |
| 36 | + - apply: |
| 37 | + file: skyhook.yaml |
| 38 | + - script: |
| 39 | + timeout: 60s |
| 40 | + content: | |
| 41 | + NODE=$(kubectl get nodes -l skyhook.nvidia.com/test-node=skyhooke2e -o jsonpath='{.items[0].metadata.name}') |
| 42 | + echo "Waiting for Skyhook activity on node $NODE..." |
| 43 | + for i in $(seq 1 30); do |
| 44 | + ANNOTATION=$(kubectl get node "$NODE" -o jsonpath='{.metadata.annotations.skyhook\.nvidia\.com/nodeState_cli-node-test}' 2>/dev/null) |
| 45 | + if [ -n "$ANNOTATION" ]; then |
| 46 | + echo "Skyhook activity detected" |
| 47 | + exit 0 |
| 48 | + fi |
| 49 | + sleep 2 |
| 50 | + done |
| 51 | + echo "Timeout waiting for activity" |
| 52 | + exit 1 |
| 53 | +
|
| 54 | + # Step 2: Test node list (table format) |
| 55 | + - name: test-node-list |
| 56 | + try: |
| 57 | + - script: |
| 58 | + timeout: 30s |
| 59 | + content: | |
| 60 | + ../../../../operator/bin/skyhook node list --skyhook cli-node-test |
| 61 | + - script: |
| 62 | + timeout: 30s |
| 63 | + content: | |
| 64 | + ../../../../operator/bin/skyhook node list --skyhook cli-node-test -o json |
| 65 | +
|
| 66 | + # Step 3: Test node status |
| 67 | + - name: test-node-status |
| 68 | + try: |
| 69 | + - script: |
| 70 | + timeout: 30s |
| 71 | + content: | |
| 72 | + NODE=$(kubectl get nodes -l skyhook.nvidia.com/test-node=skyhooke2e -o jsonpath='{.items[0].metadata.name}') |
| 73 | + ../../../../operator/bin/skyhook node status "$NODE" |
| 74 | + - script: |
| 75 | + timeout: 30s |
| 76 | + content: | |
| 77 | + NODE=$(kubectl get nodes -l skyhook.nvidia.com/test-node=skyhooke2e -o jsonpath='{.items[0].metadata.name}') |
| 78 | + ../../../../operator/bin/skyhook node status "$NODE" --skyhook cli-node-test |
| 79 | + - script: |
| 80 | + timeout: 30s |
| 81 | + content: | |
| 82 | + NODE=$(kubectl get nodes -l skyhook.nvidia.com/test-node=skyhooke2e -o jsonpath='{.items[0].metadata.name}') |
| 83 | + ../../../../operator/bin/skyhook node status "$NODE" -o json |
| 84 | +
|
| 85 | + # Step 4: Test node ignore/unignore |
| 86 | + - name: test-node-ignore |
| 87 | + try: |
| 88 | + - script: |
| 89 | + timeout: 30s |
| 90 | + content: | |
| 91 | + NODE=$(kubectl get nodes -l skyhook.nvidia.com/test-node=skyhooke2e -o jsonpath='{.items[0].metadata.name}') |
| 92 | + ../../../../operator/bin/skyhook node ignore "$NODE" |
| 93 | + - assert: |
| 94 | + file: assert-node-ignored.yaml |
| 95 | + - name: test-node-unignore |
| 96 | + try: |
| 97 | + - script: |
| 98 | + timeout: 30s |
| 99 | + content: | |
| 100 | + NODE=$(kubectl get nodes -l skyhook.nvidia.com/test-node=skyhooke2e -o jsonpath='{.items[0].metadata.name}') |
| 101 | + ../../../../operator/bin/skyhook node unignore "$NODE" |
| 102 | + - assert: |
| 103 | + file: assert-node-unignored.yaml |
| 104 | + |
| 105 | + # Step 5: Test node reset |
| 106 | + - name: test-node-reset |
| 107 | + try: |
| 108 | + - script: |
| 109 | + timeout: 30s |
| 110 | + content: | |
| 111 | + NODE=$(kubectl get nodes -l skyhook.nvidia.com/test-node=skyhooke2e -o jsonpath='{.items[0].metadata.name}') |
| 112 | + ../../../../operator/bin/skyhook node reset "$NODE" --skyhook cli-node-test --confirm |
| 113 | + - assert: |
| 114 | + file: assert-node-reset.yaml |
| 115 | + |
| 116 | + # Cleanup |
| 117 | + - name: cleanup |
| 118 | + try: |
| 119 | + - script: |
| 120 | + content: | |
| 121 | + kubectl delete skyhook cli-node-test 2>/dev/null || true |
| 122 | + for NODE in $(kubectl get nodes -l skyhook.nvidia.com/test-node=skyhooke2e -o jsonpath='{.items[*].metadata.name}'); do |
| 123 | + kubectl annotate node "$NODE" skyhook.nvidia.com/nodeState_cli-node-test- 2>/dev/null || true |
| 124 | + kubectl label node "$NODE" skyhook.nvidia.com/ignore- 2>/dev/null || true |
| 125 | + done |
| 126 | +
|
0 commit comments