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

Improve rke2-uninstall.ps1 script #5779

Merged
merged 1 commit into from
May 23, 2024

Conversation

manuelbuil
Copy link
Contributor

@manuelbuil manuelbuil commented Apr 15, 2024

Proposed Changes

This PR tries to fix the current implementation of the rke2-uninstall.ps1 script. Often this script fails to remove everything from the node because by the time it tries to remove the containerd namespace, there are still resources in that namespace. As a consequence, we end up with files in /var/lib/rancher/agent/ which are impossible to remove because according to Windows, they are locked. To remove them, a restart normally works but not always.

This PR does two things:
1 - The rke2-uninstall.ps1 would create a lock file in the dataDir. Then it will kill kubelet. In the pebinary code, we won't restart kubelet if that lock file exists
2 - It retries removing the namespace for a few times, in case the previous trial failed. There might be situations where the script can't succeed (e.g. user forgot to drain). For those cases, it gives up after 30 seconds and continues deleting other stuff, as it does today

Types of Changes

Bugfix

Verification

Install rke2 on linux and windows. Deploy a pod in windows. Run the rke2-uninstall.ps1 script. Without this PR, half of the time the script will fail and it will be impossible to remove the directory /var/lib/rancher.

With this PR, the script works and /var/lib/rancher does not exist anymore

Testing

Linked Issues

#5778
rancher/rancher#45016

User-Facing Change


Further Comments

@manuelbuil manuelbuil requested a review from a team as a code owner April 15, 2024 15:43
Copy link
Contributor

@HarrisonWAffel HarrisonWAffel left a comment

Choose a reason for hiding this comment

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

lgtm, do you think we should add a blurb in the docs calling out the need to drain the node before running this script?

@manuelbuil manuelbuil requested a review from brandond April 17, 2024 05:37
@manuelbuil manuelbuil force-pushed the rke2uninstallwindows branch from 4f9b86b to 6622d4a Compare April 18, 2024 13:49
@manuelbuil manuelbuil force-pushed the rke2uninstallwindows branch from 6622d4a to 0075531 Compare April 19, 2024 05:50
@manuelbuil manuelbuil requested a review from brandond April 19, 2024 06:54
@codecov-commenter
Copy link

codecov-commenter commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 26.46%. Comparing base (7139680) to head (d58842e).
Report is 31 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5779   +/-   ##
=======================================
  Coverage   26.46%   26.46%           
=======================================
  Files          30       30           
  Lines        2649     2649           
=======================================
  Hits          701      701           
  Misses       1903     1903           
  Partials       45       45           
Flag Coverage Δ
inttests 10.00% <ø> (ø)
unittests 18.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

bundle/bin/rke2-uninstall.ps1 Outdated Show resolved Hide resolved
@manuelbuil manuelbuil force-pushed the rke2uninstallwindows branch 2 times, most recently from 0e6961a to 6324be7 Compare April 24, 2024 13:01
@manuelbuil manuelbuil requested a review from brandond April 25, 2024 15:09
New-Item -ItemType File -Path $lockFilePath -Force
} else {
# ctr should exist at this point but just in case we add this log
Write-Host "Command ctr not found. Aumatica uninstallation might fail"
Copy link
Member

@brandond brandond Apr 30, 2024

Choose a reason for hiding this comment

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

nit on spelling/grammar:

Suggested change
Write-Host "Command ctr not found. Aumatica uninstallation might fail"
Write-Host "ctr.exe not found, container cleanup and RKE2 uninstallation is unlikely to succeed."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh! Thanks, I missed that

Copy link
Member

@brandond brandond left a comment

Choose a reason for hiding this comment

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

lgtm with warning nit

@manuelbuil manuelbuil force-pushed the rke2uninstallwindows branch from 6324be7 to e04c655 Compare May 2, 2024 05:55
if ($command) {
$executablePath = $command.Source
$dataBinDirDirectory = Split-Path -Parent $executablePath
$lockFilePath = Join-Path -Path $directory -ChildPath "rke2-uninstall.lock"
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking back over this with the new changes, I don't see $directory being set anywhere, looks like it should be $dataBinDirDirectory

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch! Let me retest this carefully again

@manuelbuil manuelbuil force-pushed the rke2uninstallwindows branch from e04c655 to d58842e Compare May 13, 2024 06:03
@manuelbuil
Copy link
Contributor Author

restested and works :)

@brandond brandond requested a review from HarrisonWAffel May 13, 2024 20:29
@manuelbuil manuelbuil merged commit 969a162 into rancher:master May 23, 2024
6 checks passed
@manuelbuil manuelbuil deleted the rke2uninstallwindows branch May 23, 2024 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants