Skip to content

fix(reset): add etcd backup directory cleanup to prevent redeployment failures#13221

Open
Irshu786 wants to merge 2 commits into
kubernetes-sigs:masterfrom
Irshu786:patch-1
Open

fix(reset): add etcd backup directory cleanup to prevent redeployment failures#13221
Irshu786 wants to merge 2 commits into
kubernetes-sigs:masterfrom
Irshu786:patch-1

Conversation

@Irshu786
Copy link
Copy Markdown

@Irshu786 Irshu786 commented Apr 29, 2026

What type of PR is this?
/kind fix

What this PR does / why we need it:

This PR removes the etcd backup directory in the reset role.

The reset playbook did not remove the etcd backup directory (/var/backups/etcd by default). As a result, stale backup data from the previous deployment remained on the node, causing subsequent cluster deployments to fail or hang during the etcd backup job.

This can lead to increased operational toil, with users spending additional time troubleshooting failed or stuck deployments.

Special notes for your reviewer:
The etcd_backup_prefix variable already exists in Kubespray and points to the etcd backup directory (e.g., /var/backups/etcd)

Fixed reset playbook to clean up etcd backup directory, preventing cluster redeployment failures

Does this PR introduce a user-facing change?:
NONE

Add tasks to the reset role to find and remove etcd backup directories.
Copilot AI review requested due to automatic review settings April 29, 2026 07:14
@k8s-ci-robot k8s-ci-robot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Apr 29, 2026
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 29, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Irshu786 / name: Ali Irshad (277ddb7)
  • ✅ login: Irshu786 / name: Irshu786 (c58831a)

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @Irshu786!

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 size/S Denotes a PR that changes 10-29 lines, ignoring generated files. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 29, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @Irshu786. 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.

Details

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-sigs/prow repository.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Irshu786
Once this PR has been reviewed and has the lgtm label, please assign ant31 for approval. For more information see the Code Review Process.

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

Details 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

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds cleanup logic to the reset role so that etcd backup directories created under /var/backups (e.g. /var/backups/etcd-*) are removed during a cluster reset, aligning reset behavior with “remove all etcd-related data”.

Changes:

  • Find directories matching etcd-* under /var/backups.
  • Remove any matched etcd backup directories during playbooks/reset.yml runs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread roles/reset/tasks/main.yml Outdated
Comment thread roles/reset/tasks/main.yml Outdated
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 29, 2026
Comment thread roles/reset/tasks/main.yml Outdated
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 30, 2026
@Irshu786 Irshu786 changed the title Add tasks to find and remove etcd backup directories Add etcd_backup_prefix path to remove etcd backup directories Apr 30, 2026
@Irshu786 Irshu786 changed the title Add etcd_backup_prefix path to remove etcd backup directories Add etcd_backup_prefix path to remove etcd backup directory Apr 30, 2026
@Irshu786 Irshu786 changed the title Add etcd_backup_prefix path to remove etcd backup directory fix: add etcd_backup_prefix path to remove etcd backup directory Apr 30, 2026
@guoard
Copy link
Copy Markdown
Contributor

guoard commented Apr 30, 2026

Thank you for your contribution.
please sign the CLA and follow pull request template.

@Irshu786
Copy link
Copy Markdown
Author

/easycla

@guoard
Copy link
Copy Markdown
Contributor

guoard commented Apr 30, 2026

I think the CLA error is because of copilot commit!
Can you sqush all commits so you be the only author?

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 30, 2026
@Irshu786 Irshu786 requested a review from guoard April 30, 2026 12:26
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 30, 2026
@guoard
Copy link
Copy Markdown
Contributor

guoard commented Apr 30, 2026

Please follow pull request template.

kind and release-note.

@Irshu786 Irshu786 changed the title fix: add etcd_backup_prefix path to remove etcd backup directory fix(reset): add etcd backup directory cleanup to prevent redeployment failures Apr 30, 2026
@guoard
Copy link
Copy Markdown
Contributor

guoard commented May 1, 2026

I think kind should be fix and release note should be in block like this that Prow can undrestand it:

image

@guoard
Copy link
Copy Markdown
Contributor

guoard commented May 1, 2026

/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. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels May 1, 2026
@Irshu786
Copy link
Copy Markdown
Author

Irshu786 commented May 1, 2026

I think kind should be fix and release note should be in block like this that Prow can undrestand it:

image

can you please have a look at failed CI checks?

@guoard
Copy link
Copy Markdown
Contributor

guoard commented May 1, 2026

/retest-failed

1 similar comment
@guoard
Copy link
Copy Markdown
Contributor

guoard commented May 4, 2026

/retest-failed

@guoard
Copy link
Copy Markdown
Contributor

guoard commented May 4, 2026

/retest

- /etc/origin/ovn
- "{{ sysctl_file_path }}"
- /etc/crictl.yaml
- "{{ etcd_backup_prefix }}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I tested it, this will fail because that variable is undefined when reset playbook is running.

and this is not a good idea to delete everything in /var/backups dir, we need to delete {{ etcd_backup_prefix }}/etcd-* files. but i don't know how to access that variable.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

can we add a task rather than env approach?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@yankay WDYT?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@yankay can u have a look 👁️

@yankay
Copy link
Copy Markdown
Member

yankay commented May 11, 2026

Thanks for the fix @Irshu786!

One small concern: reset wiping the etcd backup directory feels a bit risky — backups are often the last recovery option if something goes wrong, including after an accidental reset.

Also, the current diff removes the whole {{ etcd_backup_prefix }} (defaults to /var/backups), not just the etcd-* subdirectories.

If the underlying issue is that stale backup dirs break redeployment, would it make sense to harden roles/etcd/handlers/backup_cleanup.yml instead, so it tolerates leftover dirs gracefully? Something like:

- name: Remove old etcd backups
  ansible.builtin.file:
    state: absent
    path: "{{ item }}"
  loop: "{{ (_etcd_backups.files | sort(attribute='ctime', reverse=True))[etcd_backup_retention_count:] | map(attribute='path') }}"
  when: etcd_backup_retention_count >= 0
  ignore_errors: true  # noqa ignore-errors - don't block etcd restart on stale backup cleanup

Just a thought — curious what others think.

@Irshu786
Copy link
Copy Markdown
Author

Irshu786 commented May 13, 2026

Thanks for the fix @Irshu786!

One small concern: reset wiping the etcd backup directory feels a bit risky — backups are often the last recovery option if something goes wrong, including after an accidental reset.

Also, the current diff removes the whole {{ etcd_backup_prefix }} (defaults to /var/backups), not just the etcd-* subdirectories.

If the underlying issue is that stale backup dirs break redeployment, would it make sense to harden roles/etcd/handlers/backup_cleanup.yml instead, so it tolerates leftover dirs gracefully? Something like:

- name: Remove old etcd backups
  ansible.builtin.file:
    state: absent
    path: "{{ item }}"
  loop: "{{ (_etcd_backups.files | sort(attribute='ctime', reverse=True))[etcd_backup_retention_count:] | map(attribute='path') }}"
  when: etcd_backup_retention_count >= 0
  ignore_errors: true  # noqa ignore-errors - don't block etcd restart on stale backup cleanup

Just a thought — curious what others think.

Thanks, That makes sense !!
I think reset should ideally leave the cluster in a fully clean state, But agreed that hardening the backup cleanup handler would prevent redeploys from getting stuck on stale backup dirs even if cleanup was missed earlier.

can i update the PR with suggested changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

5 participants