Don't clear current stemcell on VM delete - #737
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (6)
💤 Files with no reviewable changes (5)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. WalkthroughThe VM and manager constructors no longer accept or store Priority: ⬆️ High Severity of issue fixed: High Merge Risk: ⚪ Minimal · up to The change preserves the current stemcell across failed VM recreation attempts and is ready to merge after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks 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 |
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.