fixup! feat: backup revolution
This commit is contained in:
parent
daeba70dac
commit
c63e97385f
|
@ -28,27 +28,27 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
|
|||
return swarm.Service{}, fmt.Errorf("no services deployed?")
|
||||
}
|
||||
|
||||
var backupServices []swarm.Service
|
||||
var matchingServices []swarm.Service
|
||||
for _, service := range services {
|
||||
if enabled, exists := service.Spec.Labels[label]; exists && enabled == "true" {
|
||||
backupServices = append(backupServices, service)
|
||||
matchingServices = append(matchingServices, service)
|
||||
}
|
||||
}
|
||||
|
||||
if len(backupServices) == 0 {
|
||||
return swarm.Service{}, fmt.Errorf("no backup services deployed?")
|
||||
if len(matchingServices) == 0 {
|
||||
return swarm.Service{}, fmt.Errorf("no services deployed matching label '%s'?", label)
|
||||
}
|
||||
|
||||
if len(backupServices) > 1 {
|
||||
if len(matchingServices) > 1 {
|
||||
var servicesRaw []string
|
||||
for _, service := range backupServices {
|
||||
for _, service := range matchingServices {
|
||||
serviceName := service.Spec.Name
|
||||
created := formatter.HumanDuration(service.CreatedAt.Unix())
|
||||
servicesRaw = append(servicesRaw, fmt.Sprintf("%s (created %v)", serviceName, created))
|
||||
}
|
||||
|
||||
if !prompt {
|
||||
err := fmt.Errorf("expected 1 service but found %v: %s", len(backupServices), strings.Join(servicesRaw, " "))
|
||||
err := fmt.Errorf("expected 1 service but found %v: %s", len(matchingServices), strings.Join(servicesRaw, " "))
|
||||
return swarm.Service{}, err
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
|
|||
}
|
||||
|
||||
chosenService := strings.TrimSpace(strings.Split(response, " ")[0])
|
||||
for _, service := range backupServices {
|
||||
for _, service := range matchingServices {
|
||||
serviceName := strings.ToLower(service.Spec.Name)
|
||||
if serviceName == chosenService {
|
||||
return service, nil
|
||||
|
@ -75,7 +75,7 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
|
|||
logrus.Panic("failed to match chosen service")
|
||||
}
|
||||
|
||||
return backupServices[0], nil
|
||||
return matchingServices[0], nil
|
||||
}
|
||||
|
||||
// GetService retrieves a service container. If prompt is true and the retrievd
|
||||
|
|
Loading…
Reference in New Issue