Hello guys,
We are running Bitbucket autoscaler version 3.11.7 and we noticed that in dynamic Kubernetes environments with high node churn, the cleaner leaves job and secret definitions when sudenly interrupted during the deletion.
Cleaner.delete_runners (autoscaler/cleaner/pct_runner_idle_cleaner.py) deletes the Bitbucket runner first, then its Kubernetes Job and the runner-oauth-credentials-<uuid> Secret. The cleaner finds runners only by listing them in Bitbucket. If it stops between the two steps (pod restart, rollout, or an error from the Kubernetes API), the next run can't see that runner any more. Its Job and Secret then stay in the cluster for good, including the runner's OAuth credentials.
Steps to reproduce
- Let the cleaner select an offline or disabled autoscaler runner for deletion.
- Kill the cleaner pod right after the Bitbucket
DELETE .../pipelines-config/runners/{uuid} call succeeds. - After the pod restarts, the runner is gone from Bitbucket, and
runner-<uuid> and runner-oauth-credentials-<uuid> still exist in the runner namespace.
The fix is to delete the Kubernetes resources before the Bitbucket runner. KubernetesService.delete_job already treats a missing Job or Secret as a warning, so the next run retries safely after an interruption at any point.
This:
self.kubernetes_service.delete_job(runner_uuid.strip('{}'), self.runner_data.namespace)
Should be above this:
self.runner_service.delete_bitbucket_runner(
workspace=self.runner_data.workspace,
runner_uuid=runner_uuid,
repository=self.runner_data.repository
)
Thanks
Stefan