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

Commit

Permalink
agent: squash loops into a single one in desiredAgentState
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Dongsu Park committed May 30, 2016
1 parent 2fc4f38 commit 3d876bf
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions agent/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,30 +141,20 @@ func desiredAgentState(a *Agent, reg registry.Registry) (*AgentState, error) {

for _, u := range units {
u := u
md := u.RequiredTargetMetadata()

if u.IsGlobal() {
continue
}

sUnit, ok := sUnitMap[u.Name]
if !ok || sUnit.TargetMachineID == "" || sUnit.TargetMachineID != ms.ID {
continue
if !machine.HasMetadata(&ms, md) {
log.Debugf("Agent unable to run global unit %s: missing required metadata", u.Name)
continue
}
}

as.Units[u.Name] = &u
}

for _, u := range units {
u := u
md := u.RequiredTargetMetadata()

if !u.IsGlobal() {
continue
}

if !machine.HasMetadata(&ms, md) {
log.Debugf("Agent unable to run global unit %s: missing required metadata", u.Name)
continue
sUnit, ok := sUnitMap[u.Name]
if !ok || sUnit.TargetMachineID == "" || sUnit.TargetMachineID != ms.ID {
continue
}
}

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

0 comments on commit 3d876bf

Please sign in to comment.