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

reset_confirmation in reset.yml #10288

Merged
merged 4 commits into from
Jul 18, 2023
Merged

reset_confirmation in reset.yml #10288

merged 4 commits into from
Jul 18, 2023

Conversation

somewho
Copy link
Contributor

@somewho somewho commented Jul 12, 2023

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change

/kind bug

/kind cleanup
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

What this PR does / why we need it:
reset confirmation user input fix

Which issue(s) this PR fixes:

Fixes #10287

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Fix reset_confirmation not working when inputing correct value

reset confirmation user input fix
@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jul 12, 2023
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jul 12, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jul 12, 2023
@k8s-ci-robot
Copy link
Contributor

Welcome @somewho!

It looks like this is your first PR to kubernetes-sigs/kubespray 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kubespray has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 12, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @somewho. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 12, 2023
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 12, 2023
Copy link
Member

@MrFreezeex MrFreezeex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I am guessing this happened since we updated Ansible :(

/lgtm
/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 12, 2023
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 12, 2023
Copy link
Member

@Pradumnasaraf Pradumnasaraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

Looks good

@MrFreezeex
Copy link
Member

Actually this does fail in CI:

TASK [Check confirmation] ******************************************************
task path: /builds/kargo-ci/kubernetes-sigs-kubespray/playbooks/reset.yml:28
Wednesday 12 July 2023  15:54:24 +0000 (0:00:00.221)       0:00:20.172 ******** 
fatal: [instance-1]: FAILED! => {"msg": "The conditional check 'reset_confirmation.user_input != \"yes\"' failed. The error was: error while evaluating conditional (reset_confirmation.user_input != \"yes\"): 'str object' has no attribute 'user_input'. 'str object' has no attribute 'user_input'\n\nThe error appears to be in '/builds/kargo-ci/kubernetes-sigs-kubespray/playbooks/reset.yml': line 28, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n        - not (skip_confirmation | default(false) | bool)\n    - name: Check confirmation\n      ^ here\n"}

@Pradumnasaraf
Copy link
Member

Actually this does fail in CI:

TASK [Check confirmation] ******************************************************
task path: /builds/kargo-ci/kubernetes-sigs-kubespray/playbooks/reset.yml:28
Wednesday 12 July 2023  15:54:24 +0000 (0:00:00.221)       0:00:20.172 ******** 
fatal: [instance-1]: FAILED! => {"msg": "The conditional check 'reset_confirmation.user_input != \"yes\"' failed. The error was: error while evaluating conditional (reset_confirmation.user_input != \"yes\"): 'str object' has no attribute 'user_input'. 'str object' has no attribute 'user_input'\n\nThe error appears to be in '/builds/kargo-ci/kubernetes-sigs-kubespray/playbooks/reset.yml': line 28, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n        - not (skip_confirmation | default(false) | bool)\n    - name: Check confirmation\n      ^ here\n"}

Ah, yes. It is unable to evaluate the conditional.

added default for non-interactive run in ci/cd
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 15, 2023
@somewho somewho changed the title Update reset.yml reset_confirmation in reset.yml Jul 15, 2023
* skip reset_confirmation promtp when reset_confirmation is defined via extra-vars option (for tests)
* check both string type and object type with user_input for reset_confirmation var
@somewho
Copy link
Contributor Author

somewho commented Jul 15, 2023

Actually this does fail in CI:

TASK [Check confirmation] ******************************************************
task path: /builds/kargo-ci/kubernetes-sigs-kubespray/playbooks/reset.yml:28
Wednesday 12 July 2023  15:54:24 +0000 (0:00:00.221)       0:00:20.172 ******** 
fatal: [instance-1]: FAILED! => {"msg": "The conditional check 'reset_confirmation.user_input != \"yes\"' failed. The error was: error while evaluating conditional (reset_confirmation.user_input != \"yes\"): 'str object' has no attribute 'user_input'. 'str object' has no attribute 'user_input'\n\nThe error appears to be in '/builds/kargo-ci/kubernetes-sigs-kubespray/playbooks/reset.yml': line 28, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n        - not (skip_confirmation | default(false) | bool)\n    - name: Check confirmation\n      ^ here\n"}

'Cause of
ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} -e @${CI_TEST_VARS} -e local_release_dir=${PWD}/downloads --limit "${RECOVER_CONTROL_PLANE_TEST_GROUPS}:!fake_hosts" -e reset_confirmation=yes reset.yml
in tests/scripts/testcases_run.sh

I've made some changes to deal with both string via extra-vars command line option and with object type when registered by ansible.builtin.pause module prompt

Also I've found another workaround in playbooks/remove_node.yml

  tasks:
    - name: Confirm Execution
      pause:
        prompt: "Are you sure you want to delete nodes state? Type 'yes' to delete nodes."
      register: pause_result
      run_once: True
      when:
        - not (skip_confirmation | default(false) | bool)

    - name: Fail if user does not confirm deletion
      fail:
        msg: "Delete nodes confirmation failed"
      when: pause_result.user_input | default('yes') != 'yes'

but is "default('yes')" behavior acceptable?

Copy link
Member

@MrFreezeex MrFreezeex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh indeed nice catch! I would prefer though that you change the register to something else for backward compatibility with the variable on the ansible cli (reset_confirmation_prompt maybe?) and have an or instead of defining the same variable twice at two places. This would be less confusing/more readable IMO

@somewho
Copy link
Contributor Author

somewho commented Jul 16, 2023

Oh indeed nice catch! I would prefer though that you change the register to something else for backward compatibility with the variable on the ansible cli (reset_confirmation_prompt maybe?) and have an or instead of defining the same variable twice at two places. This would be less confusing/more readable IMO

With reset_confirmation_prompt:
a (with or).

when: (reset_confirmation_prompt.user_input | default('') or reset_confirmation | default('')) != "yes"

b.

when: (reset_confirmation_prompt.user_input | default(reset_confirmation)) | default('')) != "yes"

In both cases have to use a default for each of the variables
Which option is preferable?

@MrFreezeex
Copy link
Member

MrFreezeex commented Jul 16, 2023

Both looks fine I am not sure if a works though maybe this would work better (but b is also fine 🤷‍♂️)
(reset_confirmation_prompt.user_input | default("") != "yes") or (reset_confirmation | default("") != "yes")

@somewho
Copy link
Contributor Author

somewho commented Jul 16, 2023

Both looks fine I am not sure if a works though maybe this would work better (but b is also fine 🤷‍♂️)
(reset_confirmation_prompt.user_input | default("") != "yes") or (reset_confirmation | default("") != "yes")

I think I found a good and fairly clear solution:

      when:
        - not reset_confirmation | default(false) | bool
        - not reset_confirmation_prompt.user_input | default("") == "yes"

Copy link
Member

@MrFreezeex MrFreezeex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and indeed very clean thanks!
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 16, 2023
Copy link
Member

@floryut floryut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@somewho Thank you for the fix 🙇

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: floryut, MrFreezeex, Pradumnasaraf, somewho

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 18, 2023
@k8s-ci-robot k8s-ci-robot merged commit 788190b into kubernetes-sigs:master Jul 18, 2023
@yankay yankay mentioned this pull request Aug 24, 2023
pedro-peter pushed a commit to pedro-peter/kubespray that referenced this pull request May 8, 2024
* Update reset.yml

reset confirmation user input fix

* Update reset.yml

added default for non-interactive run in ci/cd

* fix reset_confirmation in reset.yml

* skip reset_confirmation promtp when reset_confirmation is defined via extra-vars option (for tests)
* check both string type and object type with user_input for reset_confirmation var

* reset_confirmation_prompt in conjunction with reset_confirmation

improvement inspired by:
kubernetes-sigs#10288 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reset the cluster is failed
5 participants