Skip to content

Commit

Permalink
add namespace parameter for cluster-test
Browse files Browse the repository at this point in the history
  • Loading branch information
sluetze committed Apr 16, 2024
1 parent 61b02e4 commit bc391ce
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions utils/add_kubernetes_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def set_template_vars(value, template_vars):
kind: ComplianceScan
metadata:
name: test
namespace: {NAMESPACE}
spec:
scanType: {TYPE}
profile: {PROFILE}
Expand Down Expand Up @@ -352,7 +353,7 @@ def clusterTestFunc(args):
return 1

ret_code, _ = subprocess.getstatusoutput(
'oc delete compliancescans/test')
'oc delete -n {NAMESPACE} compliancescans/test'.format(NAMESPACE=args.namespace))
if ret_code == 0:
# if previous compliancescans were actually deleted, wait a bit to allow resources to clean up.
print('* Waiting for cleanup from a previous test run')
Expand All @@ -364,7 +365,7 @@ def clusterTestFunc(args):
apply_cmd = ['oc', 'apply', '-f', '-']
with subprocess.Popen(apply_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) as proc:
_, err = proc.communicate(
input=TEST_SCAN_TEMPLATE.format(PROFILE=profile, TYPE=args.scantype).encode())
input=TEST_SCAN_TEMPLATE.format(PROFILE=profile, TYPE=args.scantype, NAMESPACE=args.namespace).encode())
if proc.returncode != 0:
print('Error applying scan object: %s' % err)
try:
Expand All @@ -378,7 +379,7 @@ def clusterTestFunc(args):
scan_result = None
while True:
ret_code, output = subprocess.getstatusoutput(
'oc get compliancescans/test -o template="{{.status.phase}} {{.status.result}}"')
'oc get -n {NAMESPACE} compliancescans/test -o template="{{{{.status.phase}}}} {{{{.status.result}}}}"'.format(NAMESPACE=args.namespace))
if output is not None:
print('> Output from last phase check: %s' % output)
if output.startswith('DONE'):
Expand Down Expand Up @@ -499,6 +500,9 @@ def main():
'--scan-type', help='Type of scan to execute.', dest="scantype",
default="Platform",
choices=["Node", "Platform"])
cluster_test_parser.add_argument(
'--namespace', help='Namespace where compliance operator is installed', dest="namespace", default="openshift-compliance"
)
cluster_test_parser.set_defaults(func=clusterTestFunc)

test_parser = subparser.add_parser(
Expand Down

0 comments on commit bc391ce

Please sign in to comment.