Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add retry for kpt commands #1717

Merged
merged 4 commits into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading