message_thread.start()
def _agent_down(self, host: str) -> bool:
+ # if host is draining or drained (has _no_schedule label) there should not
+ # be an agent deployed there and therefore we should return False
+ if host not in [h.hostname for h in self.mgr._non_draining_hosts()]:
+ return False
# if we don't have a timestamp, it's likely because of a mgr fail over.
# just set the timestamp to now. However, if host was offline before, we
# should not allow creating a new timestamp to cause it to be marked online
)
]
+ def _non_draining_hosts(self) -> List[HostSpec]:
+ """
+ Returns all hosts that do not have _no_schedule label.
+
+ Useful for the agent who needs this specific list rather than the
+ _schedulable_hosts since the agent needs to be deployed on hosts with
+ no daemon refresh
+ """
+ return [
+ h for h in self.inventory.all_specs() if '_no_schedule' not in h.labels
+ ]
+
def _unreachable_hosts(self) -> List[HostSpec]:
"""
Return all hosts that are offline or in maintenance mode.
if r is not None:
bad_hosts.append(r)
- if not self.mgr.use_agent:
+ if not self.mgr.use_agent or host not in [h.hostname for h in self.mgr._non_draining_hosts()]:
if self.mgr.cache.host_needs_daemon_refresh(host):
self.log.debug('refreshing %s daemons' % host)
r = self._refresh_host_daemons(host)
rank_map = self.mgr.spec_store[spec.service_name()].rank_map or {}
ha = HostAssignment(
spec=spec,
- hosts=self.mgr.inventory.all_specs() if spec.service_name() == 'agent' else self.mgr._schedulable_hosts(),
+ hosts=self.mgr._non_draining_hosts() if spec.service_name() == 'agent' else self.mgr._schedulable_hosts(),
unreachable_hosts=self.mgr._unreachable_hosts(),
daemons=daemons,
networks=self.mgr.cache.networks,
finally:
if self.mgr.use_agent:
# can only send ack to agents if we know for sure port they bound to
- hosts_altered = set([h for h in hosts_altered if h in self.mgr.cache.agent_ports])
+ hosts_altered = set([h for h in hosts_altered if (h in self.mgr.cache.agent_ports and h in [
+ h2.hostname for h2 in self.mgr._non_draining_hosts()])])
self.mgr.agent_helpers._request_agent_acks(hosts_altered, increment=True)
if r is None: