fixup! feat: backup revolution

This commit is contained in:
decentral1se 2024-01-12 17:10:17 +01:00
parent daeba70dac
commit c63e97385f
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
1 changed files with 9 additions and 9 deletions

View File

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