Result of query for services is used before handling possible error (#405)

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

* Return early when a non-replicated service is matched
This commit is contained in:
Frederik Ring 2024-04-15 15:08:37 +02:00 committed by GitHub
parent bf79c913e0
commit 8b69566291
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {