diff --git a/controllers/openstack_ansibleee_controller.go b/controllers/openstack_ansibleee_controller.go index 4dd48d5b..37a5b068 100644 --- a/controllers/openstack_ansibleee_controller.go +++ b/controllers/openstack_ansibleee_controller.go @@ -299,6 +299,7 @@ func (r *OpenStackAnsibleEEReconciler) jobForOpenStackAnsibleEE( // Override args list if we are in a debug mode if instance.Spec.Debug { args = []string{"sleep", "1d"} + r.Log.Info(fmt.Sprintf("Instance %s will be running in debug mode.", instance.Name)) } podSpec := corev1.PodSpec{ RestartPolicy: corev1.RestartPolicy(instance.Spec.RestartPolicy), @@ -354,7 +355,9 @@ func (r *OpenStackAnsibleEEReconciler) jobForOpenStackAnsibleEE( // we need to ensure that Play and Role are empty before addPlaybook addPlaybook(instance, h, job, hashes) } - if len(instance.Spec.CmdLine) > 0 { + if len(instance.Spec.CmdLine) > 0 && !instance.Spec.Debug { + // RUNNER_CMDLINE environment variable should only be set + // if the operator isn't running in a debug mode. addCmdLine(instance, h, job, hashes) } if len(labels["deployIdentifier"]) > 0 { diff --git a/tests/kuttl/tests/run_simple_playbook/01-assert.yaml b/tests/kuttl/tests/run_simple_playbook/01-assert.yaml index ca6d8f4e..2b2f61d2 100644 --- a/tests/kuttl/tests/run_simple_playbook/01-assert.yaml +++ b/tests/kuttl/tests/run_simple_playbook/01-assert.yaml @@ -52,8 +52,10 @@ namespaced: true commands: - script: | pod=$(oc get pods -n openstack -l app=openstackansibleee,job-name=ansibleee-play -o name) - logs=$(oc logs -n openstack "$pod" | grep 'Hello, world this is ansibleee-play.yaml') - + description=$(oc describe -n openstack "$pod") + logs=$(echo "$description" | grep 'Hello, world this is ansibleee-play.yaml') + echo Pod name: $pod + echo Description: $description if [ -n "$logs" ]; then exit 0 else diff --git a/tests/kuttl/tests/run_simple_playbook_debug/01-assert.yaml b/tests/kuttl/tests/run_simple_playbook_debug/01-assert.yaml index dfa71a80..41e73dab 100644 --- a/tests/kuttl/tests/run_simple_playbook_debug/01-assert.yaml +++ b/tests/kuttl/tests/run_simple_playbook_debug/01-assert.yaml @@ -50,10 +50,11 @@ namespaced: true commands: - script: | pod=$(oc get pods -n openstack -l app=openstackansibleee,job-name=ansibleee-play-debug -o name) - description=$(oc describe -n openstack "$pod" | grep 'Hello, world this is ansibleee-play-debug.yaml') + description=$(oc describe -n openstack "$pod") + playbook_present=$(echo "$description" | grep 'Hello, world this is ansibleee-play-debug.yaml') echo Pod name: $pod echo Description: $description - if [ -n "$description" ]; then + if [ -n "$playbook_present" ]; then exit 0 else exit 1 diff --git a/tests/kuttl/tests/run_simple_playbook_debug_cmdline/01-assert.yaml b/tests/kuttl/tests/run_simple_playbook_debug_cmdline/01-assert.yaml new file mode 100644 index 00000000..d4165ac5 --- /dev/null +++ b/tests/kuttl/tests/run_simple_playbook_debug_cmdline/01-assert.yaml @@ -0,0 +1,67 @@ +# +# Check for: +# +# - 1 OpenStackAnsibleEE CR +# - 1 Ansibleee-play pod +# - 1 Ansibleee-play job +# - Correct output from ansible play +# +apiVersion: ansibleee.openstack.org/v1alpha1 +kind: OpenStackAnsibleEE +metadata: + name: ansibleee-play-debug + namespace: openstack +spec: + image: quay.io/openstack-k8s-operators/openstack-ansibleee-runner:latest + name: openstackansibleee + play: | + - name: Print hello world + hosts: localhost + tasks: + - name: Using debug statement + ansible.builtin.debug: + msg: "Hello, world this is ansibleee-play-debug.yaml" + debug: true +status: + JobStatus: Running +--- +apiVersion: v1 +kind: Pod +metadata: + generateName: ansibleee-play-debug- + namespace: openstack + labels: + job-name: ansibleee-play-debug +status: + phase: Running +--- +apiVersion: batch/v1 +kind: Job +metadata: + labels: + app: openstackansibleee + job-name: ansibleee-play-debug + name: ansibleee-play-debug + namespace: openstack +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +namespaced: true +commands: + - script: | + pod=$(oc get pods -n openstack -l app=openstackansibleee,job-name=ansibleee-play-debug -o name) + description=$(oc describe -n openstack "$pod") + playbook_present=$(echo "$description" | grep 'Hello, world this is ansibleee-play-debug.yaml') + cmdline_present=$(echo "$description" | grep 'Hello, world this is ansibleee-play-debug.yaml') + echo Pod name: $pod + echo Description: $description + if [ -n "$playbook_present" ]; then + exit 0 + else + exit 1 + fi + if [ -z "$cmdline_present" ]; then + exit 1 + else + exit 0 + fi diff --git a/tests/kuttl/tests/run_simple_playbook_debug_cmdline/01-run-debug.yaml b/tests/kuttl/tests/run_simple_playbook_debug_cmdline/01-run-debug.yaml new file mode 100644 index 00000000..030aae30 --- /dev/null +++ b/tests/kuttl/tests/run_simple_playbook_debug_cmdline/01-run-debug.yaml @@ -0,0 +1,16 @@ +apiVersion: ansibleee.openstack.org/v1alpha1 +kind: OpenStackAnsibleEE +metadata: + name: ansibleee-play-debug + namespace: openstack +spec: + image: quay.io/openstack-k8s-operators/openstack-ansibleee-runner:latest + play: | + - name: Print hello world + hosts: localhost + tasks: + - name: Using debug statement + ansible.builtin.debug: + msg: "Hello, world this is ansibleee-play-debug.yaml" + debug: true + cmdLine: "echo This shouldn't be printed." diff --git a/tests/kuttl/tests/run_simple_playbook_debug_cmdline/02-cleanup.yaml b/tests/kuttl/tests/run_simple_playbook_debug_cmdline/02-cleanup.yaml new file mode 100644 index 00000000..4ee4e76a --- /dev/null +++ b/tests/kuttl/tests/run_simple_playbook_debug_cmdline/02-cleanup.yaml @@ -0,0 +1,6 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +delete: +- apiVersion: ansibleee.openstack.org/v1alpha1 + kind: OpenStackAnsibleEE + name: ansibleee-play-debug diff --git a/tests/kuttl/tests/run_simple_playbook_debug_cmdline/02-errors.yaml b/tests/kuttl/tests/run_simple_playbook_debug_cmdline/02-errors.yaml new file mode 100644 index 00000000..8d7392a2 --- /dev/null +++ b/tests/kuttl/tests/run_simple_playbook_debug_cmdline/02-errors.yaml @@ -0,0 +1,23 @@ +# +# Check for: +# +# - No Ansibleee-play pod +# - No Ansibleee-play job +# +apiVersion: v1 +kind: Pod +metadata: + generateName: ansible-play- + labels: + app: openstackansibleee-debug + job-name: ansibleee-play-debug + namespace: openstack +--- +apiVersion: batch/v1 +kind: Job +metadata: + labels: + app: openstackansibleee-debug + job-name: ansibleee-play-debug + name: ansibleee-play-debug + namespace: openstack