Skip to content

Commit

Permalink
chore: argo status updater tests (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
bozerkins authored Jul 26, 2023
1 parent e10f327 commit d02f132
Show file tree
Hide file tree
Showing 7 changed files with 456 additions and 17 deletions.
13 changes: 9 additions & 4 deletions cmd/argo-watcher/argo_status_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strings"
"time"

"github.com/avast/retry-go/v4"
"github.com/rs/zerolog/log"
Expand All @@ -16,12 +17,14 @@ const defaultErrorMessage string = "could not retrieve details"
type ArgoStatusUpdater struct {
argo Argo
retryAttempts uint
retryDelay time.Duration
registryProxyUrl string
}

func (updater *ArgoStatusUpdater) Init(argo Argo, retryAttempts uint, registryProxyUrl string) {
func (updater *ArgoStatusUpdater) Init(argo Argo, retryAttempts uint, retryDelay time.Duration, registryProxyUrl string) {
updater.argo = argo
updater.retryAttempts = retryAttempts
updater.retryDelay = retryDelay
updater.registryProxyUrl = registryProxyUrl
}

Expand Down Expand Up @@ -130,6 +133,8 @@ func (updater *ArgoStatusUpdater) checkWithRetry(task models.Task) (int, error)
log.Debug().Str("app", task.App).Str("id", task.Id).Msgf("%s is not available yet", expected)
lastStatus = ArgoAppNotAvailable
return errorArgoPlannedRetry
} else {
log.Debug().Str("app", task.App).Str("id", task.Id).Msgf("Expected image is in the app summary")
}
}

Expand All @@ -149,7 +154,7 @@ func (updater *ArgoStatusUpdater) checkWithRetry(task models.Task) (int, error)
return nil
},
retry.DelayType(retry.FixedDelay),
retry.Delay(argoSyncRetryDelay),
retry.Delay(updater.retryDelay),
retry.Attempts(updater.retryAttempts),
retry.RetryIf(func(err error) bool {
return errors.Is(err, errorArgoPlannedRetry)
Expand Down Expand Up @@ -186,7 +191,7 @@ func (updater *ArgoStatusUpdater) handleAppNotFound(task models.Task, err error)
func (updater *ArgoStatusUpdater) handleArgoUnavailable(task models.Task, err error) {
log.Error().Str("id", task.Id).Msg("ArgoCD is not available. Aborting.")
reason := fmt.Sprintf(ArgoAPIErrorTemplate, err.Error())
updater.argo.state.SetTaskStatus(task.Id, "aborted", reason)
updater.argo.state.SetTaskStatus(task.Id, models.StatusAborted, reason)
}

func (updater *ArgoStatusUpdater) handleDeploymentFailed(task models.Task, err error) {
Expand All @@ -199,7 +204,7 @@ func (updater *ArgoStatusUpdater) handleDeploymentFailed(task models.Task, err e
func (updater *ArgoStatusUpdater) handleDeploymentSuccess(task models.Task) {
log.Info().Str("id", task.Id).Msg("App is running on the excepted version.")
updater.argo.metrics.ResetFailedDeployment(task.App)
updater.argo.state.SetTaskStatus(task.Id, "deployed", "")
updater.argo.state.SetTaskStatus(task.Id, models.StatusDeployedMessage, "")
}

func (updater *ArgoStatusUpdater) handleAppNotAvailable(task models.Task, err error) {
Expand Down
Loading

0 comments on commit d02f132

Please sign in to comment.