|
| 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-lifecycle |
| 22 | +spec: |
| 23 | + description: | |
| 24 | + Test all CLI lifecycle commands: |
| 25 | + - pause: pauses a Skyhook from processing |
| 26 | + - resume: resumes a paused Skyhook |
| 27 | + - disable: disables a Skyhook completely |
| 28 | + - enable: enables a disabled Skyhook |
| 29 | + timeouts: |
| 30 | + assert: 60s |
| 31 | + exec: 30s |
| 32 | + steps: |
| 33 | + # Step 1: Create a Skyhook |
| 34 | + - name: setup-skyhook |
| 35 | + try: |
| 36 | + - apply: |
| 37 | + file: skyhook.yaml |
| 38 | + - script: |
| 39 | + timeout: 30s |
| 40 | + content: | |
| 41 | + echo "Waiting for Skyhook to be created..." |
| 42 | + for i in $(seq 1 15); do |
| 43 | + if kubectl get skyhook cli-lifecycle-test 2>/dev/null; then |
| 44 | + echo "Skyhook created" |
| 45 | + exit 0 |
| 46 | + fi |
| 47 | + sleep 2 |
| 48 | + done |
| 49 | + echo "Timeout waiting for Skyhook" |
| 50 | + exit 1 |
| 51 | +
|
| 52 | + # Step 2: Test pause command |
| 53 | + - name: test-pause |
| 54 | + try: |
| 55 | + - script: |
| 56 | + timeout: 30s |
| 57 | + content: | |
| 58 | + ../../../../operator/bin/skyhook pause cli-lifecycle-test --confirm |
| 59 | + - assert: |
| 60 | + file: assert-paused.yaml |
| 61 | + |
| 62 | + # Step 3: Test resume command |
| 63 | + - name: test-resume |
| 64 | + try: |
| 65 | + - script: |
| 66 | + timeout: 30s |
| 67 | + content: | |
| 68 | + ../../../../operator/bin/skyhook resume cli-lifecycle-test |
| 69 | + - assert: |
| 70 | + file: assert-resumed.yaml |
| 71 | + |
| 72 | + # Step 4: Test disable command |
| 73 | + - name: test-disable |
| 74 | + try: |
| 75 | + - script: |
| 76 | + timeout: 30s |
| 77 | + content: | |
| 78 | + ../../../../operator/bin/skyhook disable cli-lifecycle-test --confirm |
| 79 | + - assert: |
| 80 | + file: assert-disabled.yaml |
| 81 | + |
| 82 | + # Step 5: Test enable command |
| 83 | + - name: test-enable |
| 84 | + try: |
| 85 | + - script: |
| 86 | + timeout: 30s |
| 87 | + content: | |
| 88 | + ../../../../operator/bin/skyhook enable cli-lifecycle-test |
| 89 | + - assert: |
| 90 | + file: assert-enabled.yaml |
| 91 | + |
| 92 | + # Step 6: Test pause and disable together |
| 93 | + - name: test-pause-and-disable |
| 94 | + try: |
| 95 | + - script: |
| 96 | + timeout: 30s |
| 97 | + content: | |
| 98 | + ../../../../operator/bin/skyhook pause cli-lifecycle-test --confirm |
| 99 | + ../../../../operator/bin/skyhook disable cli-lifecycle-test --confirm |
| 100 | + - assert: |
| 101 | + file: assert-paused-and-disabled.yaml |
| 102 | + - script: |
| 103 | + timeout: 30s |
| 104 | + content: | |
| 105 | + # Resume should only remove pause, not disable |
| 106 | + ../../../../operator/bin/skyhook resume cli-lifecycle-test |
| 107 | + - assert: |
| 108 | + file: assert-still-disabled.yaml |
| 109 | + - script: |
| 110 | + timeout: 30s |
| 111 | + content: | |
| 112 | + # Enable should remove disable |
| 113 | + ../../../../operator/bin/skyhook enable cli-lifecycle-test |
| 114 | +
|
| 115 | + # Cleanup |
| 116 | + - name: cleanup |
| 117 | + try: |
| 118 | + - script: |
| 119 | + content: | |
| 120 | + kubectl delete skyhook cli-lifecycle-test 2>/dev/null || true |
| 121 | +
|
0 commit comments