From d3650b274ecd2d76d00eb40e9f35c6a855d0e4a1 Mon Sep 17 00:00:00 2001 From: Moritz Date: Fri, 14 Apr 2023 15:23:06 +0200 Subject: [PATCH] resolve review --- cli/app/upgrade.go | 12 ++++-------- cli/internal/deploy.go | 12 ++++-------- pkg/config/app.go | 13 ++++++++++++- pkg/upstream/stack/stack.go | 1 + 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index 86c1c0ab..197a9ab6 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -3,7 +3,6 @@ package app import ( "context" "fmt" - "strconv" "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/autocomplete" @@ -202,14 +201,11 @@ recipes. logrus.Fatal(err) } - timeoutLabel := config.GetLabel(compose, stackName, "timeout") - if timeoutLabel != "" { - stack.WaitTimeout, err = strconv.Atoi(timeoutLabel) - if err != nil { - logrus.Fatal(err) - } - logrus.Debugf("Set waiting timeout to %s s", timeoutLabel) + stack.WaitTimeout, err = config.GetTimeoutFromLabel(compose, stackName) + if err != nil { + logrus.Fatal(err) } + logrus.Debugf("set waiting timeout to %d s", stack.WaitTimeout) if err := stack.RunDeploy(cl, deployOpts, compose, stackName, internal.DontWaitConverge); err != nil { logrus.Fatal(err) diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index 25050759..dd9340d2 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -6,7 +6,6 @@ import ( "io/ioutil" "os" "path" - "strconv" "strings" "coopcloud.tech/abra/pkg/client" @@ -162,14 +161,11 @@ func DeployAction(c *cli.Context) error { logrus.Warn("skipping domain checks as requested") } - timeoutLabel := config.GetLabel(compose, stackName, "timeout") - if timeoutLabel != "" { - stack.WaitTimeout, err = strconv.Atoi(timeoutLabel) - if err != nil { - logrus.Fatal(err) - } - logrus.Debugf("Set waiting timeout to %s s", timeoutLabel) + stack.WaitTimeout, err = config.GetTimeoutFromLabel(compose, stackName) + if err != nil { + logrus.Fatal(err) } + logrus.Debugf("set waiting timeout to %d s", stack.WaitTimeout) if err := stack.RunDeploy(cl, deployOpts, compose, app.Name, DontWaitConverge); err != nil { logrus.Fatal(err) diff --git a/pkg/config/app.go b/pkg/config/app.go index 06ed722c..d86ba4f1 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -545,7 +545,7 @@ func SetUpdateLabel(compose *composetypes.Config, stackName string, appEnv AppEn } } -// getLabel reads docker labels in the format of "coop-cloud.${STACK_NAME}.${LABEL}" from the local compose files +// GetLabel reads docker labels in the format of "coop-cloud.${STACK_NAME}.${LABEL}" from the local compose files func GetLabel(compose *composetypes.Config, stackName string, label string) string { for _, service := range compose.Services { if service.Name == "app" { @@ -559,3 +559,14 @@ func GetLabel(compose *composetypes.Config, stackName string, label string) stri logrus.Debugf("no %s label found for %s", label, stackName) return "" } + +// GetTimeoutFromLabel reads the timeout value from docker label "coop-cloud.${STACK_NAME}.TIMEOUT" and returns 50 as default value +func GetTimeoutFromLabel(compose *composetypes.Config, stackName string) (int, error) { + var timeout = 50 // Default Timeout + var err error = nil + if timeoutLabel := GetLabel(compose, stackName, "timeout"); timeoutLabel != "" { + logrus.Debugf("timeout label: %s", timeoutLabel) + timeout, err = strconv.Atoi(timeoutLabel) + } + return timeout, err +} diff --git a/pkg/upstream/stack/stack.go b/pkg/upstream/stack/stack.go index 89a5649e..61ee93cf 100644 --- a/pkg/upstream/stack/stack.go +++ b/pkg/upstream/stack/stack.go @@ -31,6 +31,7 @@ const ( ResolveImageNever = "never" ) +// Timeout to wait until docker services converge, default is 50s (random choice) var WaitTimeout int = 50 type StackStatus struct {