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

fix(crank): error out on timeout installing package #5207

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmd/crank/xpkg/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type installCmd struct {
ManualActivation bool `short:"m" help:"Require the new package's first revision to be manually activated."`
PackagePullSecrets []string `placeholder:"NAME" help:"A comma-separated list of secrets the package manager should use to pull the package from the registry."`
RevisionHistoryLimit int64 `short:"r" placeholder:"LIMIT" help:"How many package revisions may exist before the oldest revisions are deleted."`
Wait time.Duration `short:"w" default:"0s" help:"How long to wait for the package to install before returning. The command does not wait by default."`
Wait time.Duration `short:"w" default:"0s" help:"How long to wait for the package to install before returning. The command does not wait by default. Errors out if the timeout is exceeded."`
phisco marked this conversation as resolved.
Show resolved Hide resolved
}

func (c *installCmd) Help() string {
Expand Down Expand Up @@ -179,7 +179,7 @@ func (c *installCmd) Run(k *kong.Context, logger logging.Logger) error { //nolin
if c.Wait > 0 {
// Poll every 2 seconds to see whether the package is ready.
logger.Debug("Waiting for package to be ready", "timeout", timeout)
wait.UntilWithContext(ctx, func(ctx context.Context) {
go wait.UntilWithContext(ctx, func(ctx context.Context) {
if err := kube.Get(ctx, client.ObjectKeyFromObject(pkg), pkg); err != nil {
logger.Debug("Cannot get package", "error", err)
return
Expand All @@ -194,6 +194,13 @@ func (c *installCmd) Run(k *kong.Context, logger logging.Logger) error { //nolin

logger.Debug("Package is not yet ready")
}, 2*time.Second)

<-ctx.Done()

if err := ctx.Err(); errors.Is(err, context.DeadlineExceeded) {
return errors.Wrap(err, "Package did not become ready")
}

}

_, err = fmt.Fprintf(k.Stdout, "%s/%s created\n", c.Kind, pkg.GetName())
Expand Down