Skip to content

Commit 8322072

Browse files
committed
fix(agent/k8s_test): fix the operator-agent tests and add cli building to agent ci for tests
1 parent f8a4b6a commit 8322072

File tree

10 files changed

+51
-33
lines changed

10 files changed

+51
-33
lines changed

.github/workflows/agent-ci.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,9 @@ jobs:
224224
225225
- name: Run operator-agent tests
226226
env:
227-
AGENT_IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/agent:${{ needs.compute-metadata.outputs.agent-image-tag }}
227+
AGENT_IMAGE: ${{ format('{0}/{1}/agent:{2}', toLower(env.REGISTRY), toLower(env.IMAGE_NAME), needs.compute-metadata.outputs.agent-image-tag) }}
228228
run: |
229229
cd operator
230230
echo "Testing with agent image: ${AGENT_IMAGE}"
231+
make build-cli
231232
make setup-kind-cluster operator-agent-tests

k8s-tests/operator-agent/check_node.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ node=$1
2323
cmd=$2
2424
check=$3
2525
timeout=${4:-10}
26+
invert=${5:-false}
2627

2728

2829
# loop until the command returns a non-zero exit code or the timeout is reached
2930
for i in $(seq 1 ${timeout}); do
3031
data=$(kubectl exec ${node}-debugger -- chroot /host bash -c "${cmd}")
31-
if echo "${data}" | grep -q "${check}"; then
32+
check_result=$(echo "${data}" | grep -c "${check}")
33+
if [ "$invert" == "true" ]; then
34+
check_result=$((! check_result))
35+
fi
36+
if [ $check_result -gt 0 ]; then
3237
echo "Check passed"
3338
exit 0
3439
else
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
#
44
#
@@ -14,38 +14,39 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
1817
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
1918
apiVersion: chainsaw.kyverno.io/v1alpha1
2019
kind: Test
2120
metadata:
2221
name: dont-write-logs-agent-operator
2322
spec:
2423
timeouts:
25-
assert: 10s
26-
exec: 10s
24+
assert: 240s
25+
exec: 90s
2726
steps:
2827
- try:
2928
- script:
3029
content: |
3130
## remove annotation from last run
32-
../../../../operator/bin/skyhook reset simple-agent-operator --confirm 2>/dev/null || true
31+
../../../operator/bin/skyhook reset dont-write-logs-agent-operator --confirm 2>/dev/null || true
3332
- script:
3433
content: |
3534
## reinstall the debug pod in case it was deleted
3635
../setup.sh kind-worker setup
3736
- script:
3837
content: |
3938
## clean up any logs from prior runs
40-
../check_node.sh kind-worker "rm -f /var/log/skyhook/dont-write-logs-agent-operator/shellscript/1.1.1/*.log" ".*" 2
39+
../check_node.sh kind-worker "rm -rf /var/log/skyhook/dont-write-logs-agent-operator || true" ".*" 2
40+
../check_node.sh kind-worker "rm -rf /var/lib/skyhook/dont-write-logs-agent-operator || true" ".*" 2
4141
- apply:
4242
file: skyhook.yaml
4343
- assert:
4444
file: assert.yaml
4545
- script:
4646
content: |
47-
../check_node.sh kind-worker "ls /var/lib/skyhook/dont-write-logs-agent-operator/flags/shellscript/1.1.1/" "shellscript_run.sh.*"
48-
../check_node.sh kind-worker "ls /var/log/skyhook/dont-write-logs-agent-operator/shellscript/1.1.1/*.log | wc -l" "0" 2
47+
set -e
48+
## Wont even create the log directory
49+
../check_node.sh kind-worker "ls /var/log/skyhook/" "dont-write-logs-agent-operator" 2 true
4950
- finally:
5051
- delete:
5152
file: skyhook.yaml

k8s-tests/operator-agent/dont_write_logs/skyhook.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
#
44
#
@@ -14,7 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
1817
apiVersion: skyhook.nvidia.com/v1alpha1
1918
kind: Skyhook
2019
metadata:
@@ -34,7 +33,7 @@ spec:
3433
- name: SKYHOOK_AGENT_WRITE_LOGS
3534
value: "false"
3635
configMap:
37-
config.sh: |
36+
apply.sh: |
3837
#!/bin/bash
3938
echo "Hello, world!"
4039

k8s-tests/operator-agent/interrupt/chainsaw-test.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,21 @@ spec:
2828
- script:
2929
content: |
3030
## remove annotation from last run
31-
../../../../operator/bin/skyhook reset simple-agent-operator --confirm 2>/dev/null || true
31+
../../../operator/bin/skyhook reset interrupt-agent-operator --confirm 2>/dev/null || true
3232
- script:
3333
content: |
3434
## reinstall the debug pod in case it was deleted
3535
../setup.sh kind-worker setup
36+
- script:
37+
content: |
38+
## clean up from prior runs
39+
../check_node.sh kind-worker "rm -rf /var/log/skyhook/interrupt-agent-operator || true" ".*" 2
40+
../check_node.sh kind-worker "rm -rf /var/lib/skyhook/interrupt-agent-operator || true" ".*" 2
3641
- apply:
3742
file: skyhook.yaml
3843
- script:
3944
content: |
45+
set -e
4046
../check_node.sh kind-worker "ls /var/lib/skyhook/interrupt-agent-operator/interrupts/flags/interrupt-agent-operator*/" "no_op.complete" 60
4147
- assert:
4248
file: assert.yaml

k8s-tests/operator-agent/interrupt/skyhook.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
#
44
#
@@ -14,7 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
1817
apiVersion: skyhook.nvidia.com/v1alpha1
1918
kind: Skyhook
2019
metadata:
@@ -33,6 +32,6 @@ spec:
3332
interrupt:
3433
type: noop
3534
configMap:
36-
config.sh: |
35+
apply.sh: |
3736
#!/bin/bash
3837
echo "Hello, world!"

k8s-tests/operator-agent/reap_old_logs/chainsaw-test.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
#
44
#
@@ -14,7 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
1817
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
1918
apiVersion: chainsaw.kyverno.io/v1alpha1
2019
kind: Test
@@ -29,11 +28,16 @@ spec:
2928
- script:
3029
content: |
3130
## remove annotation from last run
32-
../../../../operator/bin/skyhook reset reap-old-logs-agent-operator --confirm 2>/dev/null || true
31+
../../../operator/bin/skyhook reset reap-old-logs-agent-operator --confirm
3332
- script:
3433
content: |
3534
## reinstall the debug pod in case it was deleted
3635
../setup.sh kind-worker setup
36+
- script:
37+
content: |
38+
## clean up from prior runs
39+
../check_node.sh kind-worker "rm -rf /var/log/skyhook/reap-old-logs-agent-operator || true" ".*" 2
40+
../check_node.sh kind-worker "rm -rf /var/lib/skyhook/reap-old-logs-agent-operator || true" ".*" 2
3741
- apply:
3842
file: skyhook.yaml
3943
- assert:

k8s-tests/operator-agent/reap_old_logs/skyhook.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
#
44
#
@@ -14,7 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
1817
apiVersion: skyhook.nvidia.com/v1alpha1
1918
kind: Skyhook
2019
metadata:
@@ -31,12 +30,13 @@ spec:
3130
version: "1.1.1"
3231
image: ghcr.io/nvidia/skyhook-packages/shellscript
3332
configMap:
34-
config.sh: |
33+
apply.sh: |-
3534
#!/bin/bash
36-
if [ $(ls /var/lib/skyhook/reap-old-logs-agent-operator/flags/shellscript/1.1.1/*.log | wc -l) -eq 5 ]; then
35+
sleep 1
36+
if [ $(ls /var/log/skyhook/reap-old-logs-agent-operator/shellscript/1.1.1/*.log | wc -l) -eq 5 ]; then
3737
echo "5 logs found. After this should still be 5."
3838
exit 0
39-
else:
39+
else
4040
echo "Not enough logs yet. Erroring to produce more."
4141
exit 1
4242
fi

k8s-tests/operator-agent/simple/chainsaw-test.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
#
44
#
@@ -14,26 +14,30 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
1817
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
1918
apiVersion: chainsaw.kyverno.io/v1alpha1
2019
kind: Test
2120
metadata:
2221
name: simple-agent-operator
2322
spec:
2423
timeouts:
25-
assert: 10s
26-
exec: 10s
24+
assert: 240s
25+
exec: 90s
2726
steps:
2827
- try:
2928
- script:
3029
content: |
3130
## remove annotation from last run
32-
../../../../operator/bin/skyhook reset simple-agent-operator --confirm 2>/dev/null || true
31+
../../../operator/bin/skyhook reset simple-agent-operator --confirm 2>/dev/null || true
3332
- script:
3433
content: |
3534
## reinstall the debug pod in case it was deleted
3635
../setup.sh kind-worker setup
36+
- script:
37+
content: |
38+
## clean up from prior runs
39+
../check_node.sh kind-worker "rm -rf /var/log/skyhook/simple-agent-operator || true" ".*" 2
40+
../check_node.sh kind-worker "rm -rf /var/lib/skyhook/simple-agent-operator || true" ".*" 2
3741
- apply:
3842
file: skyhook.yaml
3943
- assert:

k8s-tests/operator-agent/simple/skyhook.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
#
44
#
@@ -14,7 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
1817
apiVersion: skyhook.nvidia.com/v1alpha1
1918
kind: Skyhook
2019
metadata:
@@ -31,7 +30,7 @@ spec:
3130
version: "1.1.1"
3231
image: ghcr.io/nvidia/skyhook-packages/shellscript
3332
configMap:
34-
config.sh: |
33+
apply.sh: |
3534
#!/bin/bash
3635
echo "Hello, world!"
3736

0 commit comments

Comments
 (0)