Skip to content

Commit

Permalink
Result of query for services is used before handling possible error (#…
Browse files Browse the repository at this point in the history
…405)

* Result of query for services is used before handling possible error

* Return early when a non-replicated service is matched
  • Loading branch information
m90 authored Apr 15, 2024
1 parent bf79c91 commit 8b69566
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/backup/stop_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,21 @@ func (s *script) stopContainersAndServices() (func() error, error) {
}),
Status: true,
})
if err != nil {
return noop, errwrap.Wrap(err, "error querying for services to scale down")
}
for _, s := range matchingServices {
if s.Spec.Mode.Replicated == nil {
return noop, errwrap.Wrap(
nil,
fmt.Sprintf("only replicated services can be restarted, but found a label on service %s", s.Spec.Name),
)
}
servicesToScaleDown = append(servicesToScaleDown, handledSwarmService{
serviceID: s.ID,
initialReplicaCount: *s.Spec.Mode.Replicated.Replicas,
})
}
if err != nil {
return noop, errwrap.Wrap(err, "error querying for services to scale down")
}
}

if len(containersToStop) == 0 && len(servicesToScaleDown) == 0 {
Expand Down

0 comments on commit 8b69566

Please sign in to comment.