Move group_limit & group_wait under boot

Also make formatting the group strategy the responsibility of the
commander.
This commit is contained in:
Kevin McConnell
2023-04-14 11:01:25 +01:00
parent 100b72e4b4
commit a8726be20e
6 changed files with 29 additions and 23 deletions

View File

@@ -835,13 +835,14 @@ mrsk lock release
When deploying to large numbers of hosts, you might prefer not to restart your services on every host at the same time.
MRSK's default is to boot new containers on all hosts in parallel. But you can control this by configuring `group_limit` and `group_wait`.
MRSK's default is to boot new containers on all hosts in parallel. But you can control this by configuring `group_limit` and `group_wait` as boot options:
```yaml
service: myservice
group_limit: 10
group_wait: 30
boot:
group_limit: 10
group_wait: 2
```
When `group_limit` is specified, containers will be booted on, at most, `group_limit` hosts at once. MRSK will pause for `group_wait` seconds between batches.

View File

@@ -13,7 +13,7 @@ class Mrsk::Cli::App < Mrsk::Cli::Base
execute *MRSK.app.tag_current_as_latest
end
on(MRSK.hosts, **MRSK.config.group_strategy) do |host|
on(MRSK.hosts, **MRSK.group_strategy) do |host|
roles = MRSK.roles_on(host)
roles.each do |role|

View File

@@ -51,6 +51,14 @@ class Mrsk::Commander
end
end
def group_strategy
if config.boot.group_limit.present?
{ in: :groups, limit: config.boot.group_limit, wait: config.boot.group_wait }
else
{}
end
end
def roles_on(host)
roles.select { |role| role.hosts.include?(host.to_s) }.map(&:name)
end

View File

@@ -87,6 +87,10 @@ class Mrsk::Configuration
roles.select(&:running_traefik?).flat_map(&:hosts).uniq
end
def boot
Mrsk::Configuration::Boot.new(section: raw_config.boot)
end
def repository
[ raw_config.registry["server"], image ].compact.join("/")
@@ -153,15 +157,6 @@ class Mrsk::Configuration
end
def group_strategy
if group_limit.present?
{ in: :groups, limit: group_limit, wait: group_wait }
else
{}
end
end
def audit_broadcast_cmd
raw_config.audit_broadcast_cmd
end
@@ -246,12 +241,4 @@ class Mrsk::Configuration
raise "Can't use commit hash as version, no git repository found in #{Dir.pwd}"
end
end
def group_limit
raw_config.group_limit&.to_i
end
def group_wait
raw_config.group_wait&.to_i
end
end

View File

@@ -0,0 +1,9 @@
class Mrsk::Configuration::Boot
attr_reader :group_wait, :group_limit
def initialize(section:)
section = section || {}
@group_limit = section["group_limit"]
@group_wait = section["group_wait"]
end
end

View File

@@ -12,5 +12,6 @@ registry:
username: user
password: pw
group_limit: 3
group_wait: 30
boot:
group_limit: 3
group_wait: 30