Skip to content

Commit

Permalink
chore: remove setupError
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Oct 18, 2024
1 parent 5eea1f5 commit 2ceab84
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 98 deletions.
10 changes: 1 addition & 9 deletions checks/database_backup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package checks

import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"

"github.com/flanksource/canary-checker/api/context"
Expand Down Expand Up @@ -52,13 +51,6 @@ func (c *DatabaseBackupChecker) Check(ctx *context.Context, extConfig external.C
case check.GCP != nil:
return GCPDatabaseBackupCheck(ctx, check)
default:
return FailDatabaseBackupParse(ctx, check)
return pkg.Invalid(check, ctx.Canary, "GCP details not provided in check")
}
}

func FailDatabaseBackupParse(ctx *context.Context, check v1.DatabaseBackupCheck) pkg.Results {
result := pkg.Fail(check, ctx.Canary)
var results pkg.Results
results = append(results, result)
return results.ErrorMessage(errors.New("Could not parse databaseBackup input"))
}
4 changes: 0 additions & 4 deletions checks/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@ func NewNamespaceChecker() *NamespaceChecker {
// Returns check result and metrics
func (c *NamespaceChecker) Run(ctx *context.Context) pkg.Results {
logger.Warnf("namespace check is deprecated. Please use the kubernetes resource check")
var err error
var results pkg.Results
for _, conf := range ctx.Canary.Spec.Namespace {
if c.k8s == nil {
c.k8s = ctx.Kubernetes()
c.ctx = ctx
if err != nil {
return pkg.SetupError(ctx.Canary, err)
}
}
results = append(results, c.Check(c.ctx, conf)...)
}
Expand Down
52 changes: 0 additions & 52 deletions checks/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@ package checks
import (
"fmt"
"sync"
"time"

"github.com/flanksource/canary-checker/api/external"
"github.com/flanksource/canary-checker/pkg"
)

func Error(check external.Check, err error) *pkg.CheckResult {
return &pkg.CheckResult{
Check: check,
Pass: false,
Invalid: true,
Error: err.Error(),
}
}

func Failf(check external.Check, msg string, args ...interface{}) *pkg.CheckResult {
return &pkg.CheckResult{
Check: check,
Expand All @@ -27,48 +17,6 @@ func Failf(check external.Check, msg string, args ...interface{}) *pkg.CheckResu
}
}

// TextFailf used for failure in case of text based results
func TextFailf(check external.Check, textResults bool, msg string, args ...interface{}) *pkg.CheckResult {
if textResults {
return &pkg.CheckResult{
Check: check,
Pass: false,
Invalid: false,
DisplayType: "Text",
Message: fmt.Sprintf(msg, args...),
}
}
return Failf(check, msg, args...)
}
func Success(check external.Check, start time.Time) *pkg.CheckResult {
return &pkg.CheckResult{
Check: check,
Pass: true,
Invalid: false,
Duration: time.Since(start).Milliseconds(),
}
}

func Successf(check external.Check, start time.Time, textResults bool, msg string, args ...interface{}) *pkg.CheckResult {
if textResults {
return &pkg.CheckResult{
Check: check,
Pass: true,
DisplayType: "Text",
Invalid: false,
Message: fmt.Sprintf(msg, args...),
Duration: time.Since(start).Milliseconds(),
}
}
return &pkg.CheckResult{
Check: check,
Pass: true,
Invalid: false,
Message: fmt.Sprintf(msg, args...),
Duration: time.Since(start).Milliseconds(),
}
}

func Passf(check external.Check, msg string, args ...interface{}) *pkg.CheckResult {
return &pkg.CheckResult{
Check: check,
Expand Down
41 changes: 8 additions & 33 deletions pkg/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,20 @@ import (

type Results []*CheckResult

func Fail(check external.Check, canary v1.Canary) *CheckResult {
return &CheckResult{
Check: check,
Data: map[string]interface{}{
"results": make(map[string]interface{}),
},
Start: time.Now(),
Pass: false,
Canary: canary,
}
}

func SetupError(canary v1.Canary, err error) Results {
var results Results
for _, check := range canary.Spec.GetAllChecks() {
results = append(results, &CheckResult{
Start: time.Now(),
Pass: false,
Invalid: true,
Error: err.Error(),
Check: check,
Data: map[string]interface{}{
"results": make(map[string]interface{}),
},
})
}
return results
}

func Invalid(check external.Check, canary v1.Canary, reason string) Results {
return Results{&CheckResult{
Start: time.Now(),
Pass: false,
Error: reason,
Check: check,
Start: time.Now(),
Pass: false,
Invalid: true,
Error: reason,
Check: check,
Data: map[string]interface{}{
"results": make(map[string]interface{}),
},
Canary: canary,
}}
}

func Success(check external.Check, canary v1.Canary) *CheckResult {
result := New(check, canary)
result.Pass = true
Expand Down Expand Up @@ -162,10 +135,12 @@ func (r Results) Failf(msg string, args ...interface{}) Results {
r[0].Failf(msg, args...)
return r
}

func (r Results) Invalidf(msg string, args ...interface{}) Results {
r[0].Invalidf(msg, args...)
return r
}

func (r Results) WithError(err error) Results {
r[0].ErrorObject = err
return r
Expand Down

0 comments on commit 2ceab84

Please sign in to comment.