Skip to content

Commit

Permalink
Merge pull request #5207 from phisco/error-on-timeout
Browse files Browse the repository at this point in the history
fix(crank): error out on timeout installing package
  • Loading branch information
phisco committed Jan 10, 2024
2 parents 6112ccb + 9964fab commit d67f1ea
Showing 1 changed file with 9 additions and 2 deletions.
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. Returns an error if the timeout is exceeded."`
}

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

0 comments on commit d67f1ea

Please sign in to comment.