Added cleanupDataDir function to remove any folders within the data d… #5139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
This PR adds the ability for the RKE2 executable to clean up unused data directory folders. As RKE2 clusters are upgraded, the data directory keeps old artifacts of its previous versions. As described within the issue discussion, when a cluster is upgraded, containers running within the cluster may still reference the old artifacts from previous versions. This will happen until the rke2 service is restart or the machine is rebooted. I implemented it in a way even if the service fails to clean up the data directory the RKE2 cluster will continue with its startup process.
Types of Changes
New Feature
Verification
Testing
Linked Issues
#3902
User-Facing Change
NONE
Further Comments
For this feature, I tried to use https://github.com/mitchellh/go-ps/tree/master to identify what folders need to be deleted in the data directory; however, referencing the executables did not show the same output as traversing proc directory and retrieving the symlinks for the exe file for each process folder. Additionally, I did not implement how this would work on the windows version of RKE2.