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

Commit fdf1dd9

Browse files
author
Dongsu Park
authored
Merge pull request #1564 from endocode/kayrus/list_filtered_units
fleetd: get filtered list of units instead of all units
2 parents e4f2123 + 4edc9ba commit fdf1dd9

File tree

6 files changed

+369
-71
lines changed

6 files changed

+369
-71
lines changed

systemd/manager.go

+26-16
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,25 @@ func (m *systemdUnitManager) GetUnitStates(filter pkg.Set) (map[string]*unit.Uni
196196
// operations could mutate the hashes before we've retrieved the state
197197
// for every unit in the filter, since they won't necessarily all be
198198
// present in the initial ListUnits() call.
199+
fallback := false
200+
199201
m.mutex.Lock()
200202
defer m.mutex.Unlock()
201-
dbusStatuses, err := m.systemd.ListUnits()
203+
dbusStatuses, err := m.systemd.ListUnitsByNames(filter.Values())
202204

203205
if err != nil {
204-
return nil, err
206+
fallback = true
207+
log.Debugf("ListUnitsByNames is not implemented in your systemd version (requires at least systemd 230), fallback to ListUnits: %v", err)
208+
dbusStatuses, err = m.systemd.ListUnits()
209+
if err != nil {
210+
return nil, err
211+
}
205212
}
206213

207214
states := make(map[string]*unit.UnitState)
208215
for _, dus := range dbusStatuses {
209-
if !filter.Contains(dus.Name) {
216+
if fallback && !filter.Contains(dus.Name) {
217+
// If filter could not be applied on DBus side, we will filter unit files here
210218
continue
211219
}
212220

@@ -221,21 +229,23 @@ func (m *systemdUnitManager) GetUnitStates(filter pkg.Set) (map[string]*unit.Uni
221229
states[dus.Name] = us
222230
}
223231

224-
// grab data on subscribed units that didn't show up in ListUnits, most
232+
// grab data on subscribed units that didn't show up in ListUnits in fallback mode, most
225233
// likely due to being inactive
226-
for _, name := range filter.Values() {
227-
if _, ok := states[name]; ok {
228-
continue
229-
}
230-
231-
us, err := m.getUnitState(name)
232-
if err != nil {
233-
return nil, err
234-
}
235-
if h, ok := m.hashes[name]; ok {
236-
us.UnitHash = h.String()
234+
if fallback {
235+
for _, name := range filter.Values() {
236+
if _, ok := states[name]; ok {
237+
continue
238+
}
239+
240+
us, err := m.getUnitState(name)
241+
if err != nil {
242+
return nil, err
243+
}
244+
if h, ok := m.hashes[name]; ok {
245+
us.UnitHash = h.String()
246+
}
247+
states[name] = us
237248
}
238-
states[name] = us
239249
}
240250

241251
return states, nil

vendor.manifest

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ github.com/coreos/etcd/client b2d33e6dcb24cddc0395f1bbe2213a27aef0fb46
33
github.com/coreos/etcd/pkg/pathutil b2d33e6dcb24cddc0395f1bbe2213a27aef0fb46
44
github.com/coreos/etcd/pkg/types b2d33e6dcb24cddc0395f1bbe2213a27aef0fb46
55
github.com/coreos/go-semver/semver a9a0c39c7e4a2929f73d4b757d1860fbb8e66d06
6-
github.com/coreos/go-systemd/activation 1f2251651d199b698a0be8c8bf2283178a2a97ed
7-
github.com/coreos/go-systemd/dbus 1f2251651d199b698a0be8c8bf2283178a2a97ed
8-
github.com/coreos/go-systemd/unit 1f2251651d199b698a0be8c8bf2283178a2a97ed
6+
github.com/coreos/go-systemd/activation 6dc8b843c670f2027cc26b164935635840a40526
7+
github.com/coreos/go-systemd/dbus 6dc8b843c670f2027cc26b164935635840a40526
8+
github.com/coreos/go-systemd/unit 6dc8b843c670f2027cc26b164935635840a40526
99
github.com/godbus/dbus 9bb9dbf0e53309fa81d26e7230cbb6cff9373cad
1010
github.com/golang/protobuf/proto dda510ac0fd43b39770f22ac6260eb91d377bce3
1111
github.com/jonboulle/clockwork b473f398c464f1988327f67c9e6aa7fba62f80d2

vendor/github.com/coreos/go-systemd/activation/listeners.go

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/coreos/go-systemd/dbus/dbus.go

+22-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/coreos/go-systemd/dbus/methods.go

+90-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)