kubernetes: clean up temporary provisioning scripts on the management server#13592
Open
nikolauseppinger wants to merge 1 commit into
Open
Conversation
… server The CKS action workers copy provisioning scripts (deploy-cloudstack-secret, deploy-provider, deploy-csi-driver, delete-pv-reclaimpolicy-delete, autoscale-kube-cluster and upgrade-kubernetes.sh) to the cluster nodes via retrieveScriptFiles() + copyScripts()/copyScriptFile(). Each script is written to a local temp file via File.createTempFile(), but that local copy is never deleted after it has been SCP'd to the node. As a result every cluster deploy, provider/CSI deploy, autoscale enable, PV cleanup and Kubernetes upgrade leaks one *.sh file per script into the management server's temp directory, growing without bound over the cluster lifetime. On a long-running management server this accumulates to hundreds of stale scripts in /tmp. This adds cleanupScriptFiles()/deleteScriptFileQuietly() to the base action worker and invokes it in a finally block around every copy site (deployProvider, deployCsiDriver, autoscaleCluster, deletePVsWithReclaimPolicyDelete and the upgrade worker), so the local temp copies are removed once they have been transferred to the node. The upgrade worker additionally removes its upgrade-kubernetes.sh temp file after the node loop completes. No functional change to the provisioning itself: the scripts are still written, copied and executed exactly as before; only the leftover local copies are deleted. Covered by new unit tests for cleanupScriptFiles()/deleteScriptFileQuietly() (temp files deleted, null/missing files handled without throwing).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The CKS action workers copy provisioning scripts to the cluster nodes via
retrieveScriptFiles()+copyScripts()/copyScriptFile(). Each script iswritten to a local temp file with
File.createTempFile(filename, ".sh")inretrieveScriptFile(), but that local copy on the management server is neverdeleted after it has been SCP'd to the node.
As a result, every cluster deploy, provider/CSI deploy, autoscale enable, PV
cleanup and Kubernetes upgrade leaks one
*.shfile per script into themanagement server's temp directory, growing without bound over the cluster
lifetime:
This PR adds
cleanupScriptFiles()/deleteScriptFileQuietly()to the baseKubernetesClusterActionWorkerand invokes it in afinallyblock aroundevery copy site:
KubernetesClusterActionWorker.deployProvider()KubernetesClusterActionWorker.deployCsiDriver()KubernetesClusterResourceModifierActionWorker.autoscaleCluster()KubernetesClusterResourceModifierActionWorker.deletePVsWithReclaimPolicyDelete()KubernetesClusterUpgradeWorker(overridescleanupScriptFiles()to also removeits
upgrade-kubernetes.shtemp file, cleaned up after the per-node upgrade loopcompletes since the same file is reused across nodes)
There is no functional change to the provisioning itself: the scripts are still
written, copied and executed exactly as before; only the leftover local copies
on the management server are removed once they have been transferred.
Types of changes
Bug Severity
Observed on a CloudStack 4.22.1 management server running CKS clusters; the code
path is unchanged on
main.