Skip to content

Commit

Permalink
add retry for kpt commands
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody committed Jul 18, 2023
1 parent 9b5aed3 commit 72acd8e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions 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 All @@ -46,8 +49,9 @@ func WithLogger(logger *logger.Logger) cmdOption {
// NewCmdConfig sets defaults and validates values for kpt Options.
func NewCmdConfig(t testing.TB, opts ...cmdOption) *CmdCfg {
kOpts := &CmdCfg{
logger: utils.GetLoggerFromT(),
t: t,
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 72acd8e

Please sign in to comment.