Skip to content

kubernetes: clean up temporary provisioning scripts on the management server#13592

Open
nikolauseppinger wants to merge 1 commit into
apache:mainfrom
nikolauseppinger:kubernetes/cleanup-temp-provisioning-scripts
Open

kubernetes: clean up temporary provisioning scripts on the management server#13592
nikolauseppinger wants to merge 1 commit into
apache:mainfrom
nikolauseppinger:kubernetes/cleanup-temp-provisioning-scripts

Conversation

@nikolauseppinger

@nikolauseppinger nikolauseppinger commented Jul 10, 2026

Copy link
Copy Markdown

Description

The CKS action workers copy provisioning scripts to the cluster nodes via
retrieveScriptFiles() + copyScripts() / copyScriptFile(). Each script is
written to a local temp file with File.createTempFile(filename, ".sh") in
retrieveScriptFile(), but that local copy on the management server 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:

-rw-r--r--. 1 cloud cloud 3230 ... autoscale-kube-cluster10402639792822688389.sh
-rw-r--r--. 1 cloud cloud 7197 ... delete-pv-reclaimpolicy-delete10664788910304997694.sh
-rw-r--r--. 1 cloud cloud 2303 ... deploy-cloudstack-secret10522058804386657778.sh
-rw-r--r--. 1 cloud cloud 1811 ... deploy-csi-driver1118819744193036791.sh
-rw-r--r--. 1 cloud cloud 1472 ... deploy-provider10072339396849174814.sh
-rw-r--r--. 1 cloud cloud 4971 ... upgrade-kubernetes.sh10982436999748062804.sh
... (dozens more, one set per CKS action)

This PR adds cleanupScriptFiles() / deleteScriptFileQuietly() to the base
KubernetesClusterActionWorker and invokes it in a finally block around
every copy site:

  • KubernetesClusterActionWorker.deployProvider()
  • KubernetesClusterActionWorker.deployCsiDriver()
  • KubernetesClusterResourceModifierActionWorker.autoscaleCluster()
  • KubernetesClusterResourceModifierActionWorker.deletePVsWithReclaimPolicyDelete()
  • KubernetesClusterUpgradeWorker (overrides cleanupScriptFiles() to also remove
    its upgrade-kubernetes.sh temp file, cleaned up after the per-node upgrade loop
    completes 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 fix (non-breaking change which fixes an issue)

Bug Severity

  • Minor

Observed on a CloudStack 4.22.1 management server running CKS clusters; the code
path is unchanged on main.

… 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant