The meaning of the (*Controller).isDistributedControl() method is not
immediately clear from the name, and it does not have any doc comment.
It returns true if and only if the controller is neither a manager node
nor an agent node -- that is, if the daemon is _not_ participating in a
Swarm cluster. The method name likely comes from the old abandoned
datastore-as-IPC control plane architecture for libnetwork. Refactor
c.isDistributedControl() -> !c.isSwarmNode()
to make it easier to understand code which consumes the method.
Signed-off-by: Cory Snider <csnider@mirantis.com>
| ... | ... |
@@ -241,7 +241,7 @@ func (c *Controller) clusterAgentInit() {
|
| 241 | 241 |
c.mu.Unlock() |
| 242 | 242 |
fallthrough |
| 243 | 243 |
case cluster.EventSocketChange, cluster.EventNodeReady: |
| 244 |
- if keysAvailable && !c.isDistributedControl() {
|
|
| 244 |
+ if keysAvailable && c.isSwarmNode() {
|
|
| 245 | 245 |
c.agentOperationStart() |
| 246 | 246 |
if err := c.agentSetup(clusterProvider); err != nil {
|
| 247 | 247 |
c.agentStopComplete() |
| ... | ... |
@@ -451,8 +451,8 @@ func (c *Controller) isAgent() bool {
|
| 451 | 451 |
return c.cfg.ClusterProvider.IsAgent() |
| 452 | 452 |
} |
| 453 | 453 |
|
| 454 |
-func (c *Controller) isDistributedControl() bool {
|
|
| 455 |
- return !c.isManager() && !c.isAgent() |
|
| 454 |
+func (c *Controller) isSwarmNode() bool {
|
|
| 455 |
+ return c.isManager() || c.isAgent() |
|
| 456 | 456 |
} |
| 457 | 457 |
|
| 458 | 458 |
func (c *Controller) GetPluginGetter() plugingetter.PluginGetter {
|
| ... | ... |
@@ -553,7 +553,7 @@ func (c *Controller) NewNetwork(networkType, name string, id string, options ... |
| 553 | 553 |
|
| 554 | 554 |
// At this point the network scope is still unknown if not set by user |
| 555 | 555 |
if (caps.DataScope == scope.Global || nw.scope == scope.Swarm) && |
| 556 |
- !c.isDistributedControl() && !nw.dynamic {
|
|
| 556 |
+ c.isSwarmNode() && !nw.dynamic {
|
|
| 557 | 557 |
if c.isManager() {
|
| 558 | 558 |
// For non-distributed controlled environment, globalscoped non-dynamic networks are redirected to Manager |
| 559 | 559 |
return nil, ManagerRedirectError(name) |
| ... | ... |
@@ -561,7 +561,7 @@ func (c *Controller) NewNetwork(networkType, name string, id string, options ... |
| 561 | 561 |
return nil, types.ForbiddenErrorf("Cannot create a multi-host network from a worker node. Please create the network from a manager node.")
|
| 562 | 562 |
} |
| 563 | 563 |
|
| 564 |
- if nw.scope == scope.Swarm && c.isDistributedControl() {
|
|
| 564 |
+ if nw.scope == scope.Swarm && !c.isSwarmNode() {
|
|
| 565 | 565 |
return nil, types.ForbiddenErrorf("cannot create a swarm scoped network when swarm is not active")
|
| 566 | 566 |
} |
| 567 | 567 |
|
| ... | ... |
@@ -704,7 +704,7 @@ addToStore: |
| 704 | 704 |
} |
| 705 | 705 |
} |
| 706 | 706 |
|
| 707 |
- if !c.isDistributedControl() {
|
|
| 707 |
+ if c.isSwarmNode() {
|
|
| 708 | 708 |
c.mu.Lock() |
| 709 | 709 |
arrangeIngressFilterRule() |
| 710 | 710 |
c.mu.Unlock() |
| ... | ... |
@@ -162,7 +162,7 @@ func (sb *Sandbox) delete(force bool) error {
|
| 162 | 162 |
} |
| 163 | 163 |
// Retain the sanbdox if we can't obtain the network from store. |
| 164 | 164 |
if _, err := c.getNetworkFromStore(ep.getNetwork().ID()); err != nil {
|
| 165 |
- if c.isDistributedControl() {
|
|
| 165 |
+ if !c.isSwarmNode() {
|
|
| 166 | 166 |
retain = true |
| 167 | 167 |
} |
| 168 | 168 |
log.G(context.TODO()).Warnf("Failed getting network for ep %s during sandbox %s delete: %v", ep.ID(), sb.ID(), err)
|
| ... | ... |
@@ -459,7 +459,7 @@ func (sb *Sandbox) ResolveName(ctx context.Context, name string, ipType int) ([] |
| 459 | 459 |
// network, ingress network and docker_gwbridge network. Name resolution |
| 460 | 460 |
// should prioritize returning the VIP/IPs on user overlay network. |
| 461 | 461 |
newList := []*Endpoint{}
|
| 462 |
- if !sb.controller.isDistributedControl() {
|
|
| 462 |
+ if sb.controller.isSwarmNode() {
|
|
| 463 | 463 |
newList = append(newList, getDynamicNwEndpoints(epList)...) |
| 464 | 464 |
ingressEP := getIngressNwEndpoint(epList) |
| 465 | 465 |
if ingressEP != nil {
|
| ... | ... |
@@ -198,7 +198,7 @@ func (c *Controller) unWatchSvcRecord(ep *Endpoint) {
|
| 198 | 198 |
|
| 199 | 199 |
func (c *Controller) processEndpointCreate(ep *Endpoint) {
|
| 200 | 200 |
n := ep.getNetwork() |
| 201 |
- if !c.isDistributedControl() && n.Scope() == scope.Swarm && n.driverIsMultihost() {
|
|
| 201 |
+ if c.isSwarmNode() && n.Scope() == scope.Swarm && n.driverIsMultihost() {
|
|
| 202 | 202 |
return |
| 203 | 203 |
} |
| 204 | 204 |
|
| ... | ... |
@@ -220,7 +220,7 @@ func (c *Controller) processEndpointCreate(ep *Endpoint) {
|
| 220 | 220 |
|
| 221 | 221 |
func (c *Controller) processEndpointDelete(ep *Endpoint) {
|
| 222 | 222 |
n := ep.getNetwork() |
| 223 |
- if !c.isDistributedControl() && n.Scope() == scope.Swarm && n.driverIsMultihost() {
|
|
| 223 |
+ if c.isSwarmNode() && n.Scope() == scope.Swarm && n.driverIsMultihost() {
|
|
| 224 | 224 |
return |
| 225 | 225 |
} |
| 226 | 226 |
|