Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix kvm remove when domain is not defined #4355

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion pkg/drivers/kvm/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,11 @@ func (d *Driver) Remove() error {
return errors.Wrap(err, "destroying running domain")
}

return dom.Undefine()
if err := d.undefineDomain(conn, dom); err != nil {
return errors.Wrap(err, "undefine domain")
}

return nil
}

func (d *Driver) destroyRunningDomain(dom *libvirt.Domain) error {
Expand All @@ -467,3 +471,25 @@ func (d *Driver) destroyRunningDomain(dom *libvirt.Domain) error {

return dom.Destroy()
}

func (d *Driver) undefineDomain(conn *libvirt.Connect, dom *libvirt.Domain) error {
definedDomains, err := conn.ListDefinedDomains()
if err != nil {
return errors.Wrap(err, "list defined domains")
}

var found bool
for _, domain := range definedDomains {
if domain == d.MachineName {
found = true
break
}
}

if !found {
log.Warnf("Domain %s not defined, skipping undefine...", d.MachineName)
return nil
}

return dom.Undefine()
}