Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit fa89def

Browse files
authored
Use go template for hostPort check (#474)
* Use go template for hostPort check * Address comments 1
1 parent 2879355 commit fa89def

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

pkg/tnf/testcases/data/cnf/privilegedpod.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package cnf
1818

1919
// PrivilegedPodJSON test templates for privileged pods
20+
//nolint:lll
2021
var PrivilegedPodJSON = string(`{
2122
"testcase": [
2223
{
@@ -33,7 +34,7 @@ var PrivilegedPodJSON = string(`{
3334
"name": "HOST_PORT_CHECK",
3435
"skiptest": true,
3536
"loop": 1,
36-
"command": "oc get pod %s -n %s -o json | jq -r '.spec.containers[%d] | select(.ports) | .ports[].hostPort'",
37+
"command": "oc get pod %s -n %s -o go-template='{{$putName := .metadata.name}}{{$cut := (index .spec.containers %d)}}{{range $cut.ports }}{{if .hostPort}}PUT {{$putName}} - CUT {{$cut.name}} has declared hostPort {{.hostPort}}{{\"\\n\"}}{{end}}{{end}}'",
3738
"action": "allow",
3839
"expectedstatus": [
3940
"^(<no value>)*$"

pkg/tnf/testcases/files/cnf/privilegedpod.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ testcase:
1010
- name: HOST_PORT_CHECK
1111
skiptest: true
1212
loop: 0
13-
command: "oc get pod %s -n %s -o json | jq -r '.spec.containers[%d] | select(.ports) | .ports[].hostPort'"
13+
command: "oc get pod %s -n %s -o go-template='{{$putName := .metadata.name}}{{$cut := (index .spec.containers %d)}}{{range $cut.ports }}{{if .hostPort}}PUT {{$putName}} - CUT {{$cut.name}} has declared hostPort {{.hostPort}}{{\"\\n\"}}{{end}}{{end}}'"
1414
action: allow
1515
expectedType: "regex"
1616
expectedstatus:

0 commit comments

Comments
 (0)