agent: refactor to comply with gocyclo check
agent: refactor to comply with gocyclo check

Normally, it would better to rebase changes based on automated checks
into existing commits. In this case, it seems interesting keep a history
of the changes made based on the check. Is the code clearer? Some may
say so, but it may have been more valuable to spend time on concerted
refactoring work or unit testing. Hopefully, this visibility can help us
make a decision on our tools.

Signed-off-by: Stephen J Day <63efd86fa22882ae89b6027b22a36e4db1f4214d@docker.com>

AliyunContainerService/swarmkit,vasil-yordanov/swarmkit,dperny/swarmkit-1,RenaudWasTaken/swarmkit,runshenzhu/swarmkit,allencloud/swarmkit,AliyunContainerService/swarmkit,deljuven/swarmkit,RenaudWasTaken/swarmkit,yp-engineering/swarmkit,jlhawn/swarmkit,vasil-yordanov/swarmkit,yp-engineering/swarmkit,cheyang/swarmkit,Noyan759/swarmkit,dperny/swarmkit-1,fate-grand-order/swarmkit,deljuven/swarmkit,aaronlehmann/swarmkit,diogomonica/swarmkit,allencloud/swarmkit,docker/swarmkit,yongtang/swarmkit,cezarsa/swarmkit,sungwonh/swarmkit,Noyan759/swarmkit,diogomonica/swarmkit,sungwonh/swarmkit,elifa/swarmkit,aaronlehmann/swarmkit,alyyousuf7/swarmkit,yongtang/swarmkit,docker/swarmkit,cheyang/swarmkit,runshenzhu/swarmkit,alyyousuf7/swarmkit,fate-grand-order/swarmkit,jlhawn/swarmkit,elifa/swarmkit,cezarsa/swarmkit