refactor!: do not set default timeout
Some checks failed
continuous-integration/drone/push Build is failing

See #596

Quite some `i18n.G` additions along the way!
This commit is contained in:
2025-08-25 11:38:07 +02:00
parent 44a7d288af
commit 6a52575ae0
10 changed files with 99 additions and 79 deletions

View File

@ -9,6 +9,7 @@ import (
"strings"
"time"
"coopcloud.tech/abra/pkg/i18n"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network"
@ -21,6 +22,12 @@ import (
// RunRemove is the swarm implementation of docker stack remove
func RunRemove(ctx context.Context, client *apiclient.Client, opts Remove) error {
log.Info(i18n.G("initialising undeploy"))
if WaitTimeout != 0 {
log.Debug(i18n.G("timeout: set to %d second(s)", WaitTimeout))
}
sigIntCh := make(chan os.Signal, 1)
signal.Notify(sigIntCh, os.Interrupt)
defer signal.Stop(sigIntCh)
@ -62,7 +69,7 @@ func RunRemove(ctx context.Context, client *apiclient.Client, opts Remove) error
}
if len(services)+len(networks)+len(secrets)+len(configs) == 0 {
log.Warnf("nothing found in stack: %s", namespace)
log.Warn(i18n.G("nothing found in stack: %s", namespace))
continue
}
@ -72,17 +79,17 @@ func RunRemove(ctx context.Context, client *apiclient.Client, opts Remove) error
hasError = removeNetworks(ctx, client, networks) || hasError
if hasError {
errs = append(errs, fmt.Sprintf("failed to remove some resources from stack: %s", namespace))
errs = append(errs, fmt.Sprint(i18n.G("failed to remove some resources from stack: %s", namespace)))
continue
}
log.Info("polling undeploy status")
log.Info(i18n.G("polling undeploy status"))
timeout, err := waitOnTasks(ctx, client, namespace)
if timeout {
errs = append(errs, err.Error())
} else {
if err != nil {
errs = append(errs, fmt.Sprintf("failed to wait on tasks of stack: %s: %s", namespace, err))
errs = append(errs, fmt.Sprint(i18n.G("failed to wait on tasks of stack: %s: %s", namespace, err)))
}
}
}
@ -99,7 +106,7 @@ func RunRemove(ctx context.Context, client *apiclient.Client, opts Remove) error
case <-waitCh:
return nil
case <-sigIntCh:
return fmt.Errorf("skipping as requested, undeploy still in progress 🟠")
return errors.New(i18n.G("skipping as requested, undeploy still in progress 🟠"))
case err := <-errCh:
return err
}
@ -121,10 +128,10 @@ func removeServices(
var hasError bool
sort.Slice(services, sortServiceByName(services))
for _, service := range services {
log.Debugf("removing service %s", service.Spec.Name)
log.Debug(i18n.G("removing service %s", service.Spec.Name))
if err := client.ServiceRemove(ctx, service.ID); err != nil {
hasError = true
log.Fatalf("failed to remove service %s: %s", service.ID, err)
log.Fatal(i18n.G("failed to remove service %s: %s", service.ID, err))
}
}
return hasError
@ -137,10 +144,10 @@ func removeNetworks(
) bool {
var hasError bool
for _, network := range networks {
log.Debugf("removing network %s", network.Name)
log.Debug(i18n.G("removing network %s", network.Name))
if err := client.NetworkRemove(ctx, network.ID); err != nil {
hasError = true
log.Fatalf("failed to remove network %s: %s", network.ID, err)
log.Fatal(i18n.G("failed to remove network %s: %s", network.ID, err))
}
}
return hasError
@ -153,10 +160,10 @@ func removeSecrets(
) bool {
var hasError bool
for _, secret := range secrets {
log.Debugf("removing secret %s", secret.Spec.Name)
log.Debug(i18n.G("removing secret %s", secret.Spec.Name))
if err := client.SecretRemove(ctx, secret.ID); err != nil {
hasError = true
log.Fatalf("Failed to remove secret %s: %s", secret.ID, err)
log.Fatal(i18n.G("failed to remove secret %s: %s", secret.ID, err))
}
}
return hasError
@ -169,10 +176,10 @@ func removeConfigs(
) bool {
var hasError bool
for _, config := range configs {
log.Debugf("removing config %s", config.Spec.Name)
log.Debug(i18n.G("removing config %s", config.Spec.Name))
if err := client.ConfigRemove(ctx, config.ID); err != nil {
hasError = true
log.Fatalf("failed to remove config %s: %s", config.ID, err)
log.Fatal(i18n.G("failed to remove config %s: %s", config.ID, err))
}
}
return hasError
@ -206,12 +213,17 @@ func terminalState(state swarm.TaskState) bool {
func waitOnTasks(ctx context.Context, client apiclient.APIClient, namespace string) (bool, error) {
var timedOut bool
log.Debugf("waiting on undeploy tasks (timeout=%v secs)", WaitTimeout)
go func() {
t := time.Duration(WaitTimeout) * time.Second
<-time.After(t)
log.Debug("timed out on undeploy")
if WaitTimeout == 0 {
return
}
log.Debug(i18n.G("timeout: waiting on undeploy tasks (timeout=%v secs)", WaitTimeout))
timeout := time.Duration(WaitTimeout) * time.Second
<-time.After(timeout)
log.Debug(i18n.G("timed out on undeploy (timeout=%v sec)", WaitTimeout))
timedOut = true
}()
@ -219,7 +231,7 @@ func waitOnTasks(ctx context.Context, client apiclient.APIClient, namespace stri
for {
tasks, err := getStackTasks(ctx, client, namespace)
if err != nil {
return false, fmt.Errorf("failed to get tasks: %w", err)
return false, errors.New(i18n.G("failed to get tasks: %w", err))
}
for _, task := range tasks {
@ -234,7 +246,7 @@ func waitOnTasks(ctx context.Context, client apiclient.APIClient, namespace stri
}
if timedOut {
return true, fmt.Errorf("deployment timed out 🟠")
return true, errors.New(i18n.G("deployment timed out 🟠"))
}
}