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

Commit 3d876bf

Browse files
author
Dongsu Park
committed
agent: squash loops into a single one in desiredAgentState
Commit "fleetd: support conflict in global unit" split out the loop in desiredAgentState() into 2 loops, one for non-global units and the other for global units. To follow the maintainer's suggestion, squash the loops again into a single one.
1 parent 2fc4f38 commit 3d876bf

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

agent/reconcile.go

+9-19
Original file line numberDiff line numberDiff line change
@@ -141,30 +141,20 @@ func desiredAgentState(a *Agent, reg registry.Registry) (*AgentState, error) {
141141

142142
for _, u := range units {
143143
u := u
144+
md := u.RequiredTargetMetadata()
144145

145146
if u.IsGlobal() {
146-
continue
147-
}
148-
149-
sUnit, ok := sUnitMap[u.Name]
150-
if !ok || sUnit.TargetMachineID == "" || sUnit.TargetMachineID != ms.ID {
151-
continue
147+
if !machine.HasMetadata(&ms, md) {
148+
log.Debugf("Agent unable to run global unit %s: missing required metadata", u.Name)
149+
continue
150+
}
152151
}
153152

154-
as.Units[u.Name] = &u
155-
}
156-
157-
for _, u := range units {
158-
u := u
159-
md := u.RequiredTargetMetadata()
160-
161153
if !u.IsGlobal() {
162-
continue
163-
}
164-
165-
if !machine.HasMetadata(&ms, md) {
166-
log.Debugf("Agent unable to run global unit %s: missing required metadata", u.Name)
167-
continue
154+
sUnit, ok := sUnitMap[u.Name]
155+
if !ok || sUnit.TargetMachineID == "" || sUnit.TargetMachineID != ms.ID {
156+
continue
157+
}
168158
}
169159

170160
if cExists, _ := as.HasConflict(u.Name, u.Conflicts()); cExists {

0 commit comments

Comments
 (0)