Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

fleetctl: Remove unit content from etcd #1291

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 17 additions & 1 deletion registry/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ func (r *EtcdRegistry) DestroyUnit(name string) error {
opts := &etcd.DeleteOptions{
Recursive: true,
}
_, err := r.kAPI.Delete(r.ctx(), key, opts)
u, err := r.Unit(name)
if err != nil {
log.Warningf("r.Unit error, name=%s\n", name)
u = nil
}
_, err = r.kAPI.Delete(r.ctx(), key, opts)
if err != nil {
if isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
err = errors.New("job does not exist")
Expand All @@ -300,6 +305,17 @@ func (r *EtcdRegistry) DestroyUnit(name string) error {
}

// TODO(jonboulle): add unit reference counting and actually destroying Units
if u != nil { //delete unit
path := u.Unit.Hash().String()
key = r.prefixed(unitPrefix, path)
_, err = r.kAPI.Delete(r.ctx(), key, opts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't safe as there may be two units that hash to the same key in etcd.

if err != nil {
if isEtcdError(err, etcd.ErrorCodeKeyNotFound) {
err = errors.New("unit does not exist")
}
return err
}
}
return nil
}

Expand Down