Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add namespace parameter for cluster-test #11824

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. Default is "openshift-compliance".', dest="namespace", default="openshift-compliance"
)
cluster_test_parser.set_defaults(func=clusterTestFunc)

test_parser = subparser.add_parser(
Expand Down
Loading