Skip to content

Commit

Permalink
Fix force_update action, remove buggy restart action
Browse files Browse the repository at this point in the history
Signed-off-by: Julien 'Lta' BALLET <[email protected]>
  • Loading branch information
elthariel committed Jun 7, 2019
1 parent f890594 commit e062a0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
13 changes: 6 additions & 7 deletions libraries/docker_swarm_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,16 @@ def whyrun_supported?

action :update do
ensure_swarm_available!
converge_by('Update service') { update_service }
if current_service_changed?
converge_by('Update service') { update_service }
end
end

action :force_update do
ensure_swarm_available!
converge_by('Update service [forced]') { update_service(true) }
end

action :restart do
ensure_swarm_available!
converge_by('Restart service') { restart_service }
converge_by('Update service [forced]') do
update_service(true)
end
end

action :destroy do
Expand Down
18 changes: 11 additions & 7 deletions libraries/helpers_swarm_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,29 @@ def current_service_changed?
current_spec != new_spec
end

def current_force_update_counter
current_spec = current_service.hash['Spec']
current_spec['TaskTemplate']['ForceUpdate'] || 0
end


def create_service
current_swarm.create_service(service_spec)
end

def update_service(force = false)
spec = service_spec
spec = service_spec.deep_dup

if force
spec = service_spec.deep_dup
spec['TaskTemplate']['ForceUpdate'] = 1
# For the update to be forced, you need to change the ForceUpdate
# counter. We're wrapping to avoid overflow, although unlikely
force_update = current_force_update_counter + 1 % 1000
spec['TaskTemplate']['ForceUpdate'] = force_update
end

current_service.update(spec)
end

def restart_service
current_service.restart
end

def service_spec
spec = {
'Name' => name,
Expand Down

0 comments on commit e062a0e

Please sign in to comment.