Skip to content

Commit

Permalink
feat: add retry for kpt commands (#1717)
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody committed Jul 20, 2023
1 parent eb5174a commit 55c9c8d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion infra/blueprint-test/pkg/kpt/kpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package kpt

import (
"fmt"
"time"

"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/utils"
kptfilev1 "github.com/GoogleContainerTools/kpt-functions-sdk/go/api/kptfile/v1"
kptutil "github.com/GoogleContainerTools/kpt-functions-sdk/go/api/util"
"github.com/gruntwork-io/terratest/modules/logger"
"github.com/gruntwork-io/terratest/modules/retry"
"github.com/gruntwork-io/terratest/modules/shell"
"github.com/mitchellh/go-testing-interface"
"sigs.k8s.io/kustomize/kyaml/kio/kioutil"
Expand All @@ -21,6 +23,7 @@ type CmdCfg struct {
dir string // dir to execute commands in
logger *logger.Logger // custom logger
t testing.TB // TestingT or TestingB
tries int // qty to try kpt command, default: 3
}

type cmdOption func(*CmdCfg)
Expand Down Expand Up @@ -48,6 +51,7 @@ func NewCmdConfig(t testing.TB, opts ...cmdOption) *CmdCfg {
kOpts := &CmdCfg{
logger: utils.GetLoggerFromT(),
t: t,
tries: 3,
}
// apply options
for _, opt := range opts {
Expand Down Expand Up @@ -75,7 +79,10 @@ func (k *CmdCfg) RunCmd(args ...string) string {
Logger: k.logger,
WorkingDir: k.dir,
}
op, err := shell.RunCommandAndGetStdOutE(k.t, kptCmd)
command := func() (string, error) {
return shell.RunCommandAndGetStdOutE(k.t, kptCmd)
}
op, err := retry.DoWithRetryE(k.t, "run kpt command", k.tries, 15*time.Second, command)
if err != nil {
k.t.Fatal(err)
}
Expand Down

0 comments on commit 55c9c8d

Please sign in to comment.