Don't clear current stemcell on VM delete - #737
Draft
Ivaylogi98 wants to merge 1 commit into
Draft
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
What
Removes the
stemcellRepo.ClearCurrent()call fromvm.Delete()(deployment/vm/vm.go), along with the now-unusedstemcellRepodependency it pulled onto thevmstruct,NewVM/NewVMWithMetadata,NewManager, andNewManagerFactory.Fixes #731.
Why
vm.Delete()unconditionally clearedcurrent_stemcell_id(set it to"") whenever the old VM was torn down. Insidecreate-env's delete-then-recreate cycle, the intended sequence is:vm.Delete()clearscurrent_stemcell_idcloudStemcell.PromoteAsCurrent()sets it to the new stemcell recordstemcellManager.DeleteUnused()reaps every record whose ID ≠ currentOn the happy path, step 2 overwrites the clear from step 1, so it has no observable effect. But when the replacement VM never comes up (agent timeout, network issue, or a failure inside
vmManager.Createbefore promote), step 2 is never reached andbosh-state.jsonis persisted withcurrent_stemcell_id: ""while the stemcell record and its IaaS image remain.On the next
create-envrun,FindUnused(stemcell/manager.go) treats every record as unused when the current pointer is empty (found == false), andDeleteUnusedderegisters the still-in-use image (e.g. an AWS AMI). Every subsequentcreate_vmthat references it then fails:This is more likely to surface on unattended pipelines that auto-retry a failed
create-env.The clear was always redundant
PromoteAsCurrent(stemcell/cloud_stemcell.go) callsrepo.UpdateCurrent(id)unconditionally — it never reads the prior value — so the clear invm.Delete()contributed nothing on the success path. It was introduced inbd573fe8(Nov 2014) as defensive symmetry (clear on teardown, set on build), but even in that original codePromoteAsCurrentran beforeDeleteUnused, so the clear only ever had an effect in the failure window, where it is purely destructive.With it removed, a failed deploy leaves
current_stemcell_idpointing at the stemcell the deployment is configured to use, soDeleteUnusedleaves it alone. A genuinely superseded stemcell is still reaped — but only after a successful deploy wherePromoteAsCurrentmoves the pointer to a newer record.Scope / not affected
delete-env(deployment.Delete()) deletes stemcells through an explicitcloudStemcell.Delete()step, independent ofvm.Delete()— unchanged.bosh delete-vmis a director API command (director.Deployment.DeleteVM) and never touches the local stemcell repo — unchanged.stemcell/manager.goandconfig/stemcell_repo.go(ClearCurrentis still used bycloudStemcell.Delete()) are left as-is. TheVM.Delete()interface signature is unchanged.Testing
clears current stemcell in the stemcell repocases indeployment/vm/vm_test.go(they asserted the removed behavior).go build ./...andgo test ./deployment/vm/... ./stemcell/... ./config/...pass.