Skip to content

Commit

Permalink
pkg/yoke: add wait option to descent
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmdm committed Jun 15, 2024
1 parent 2721de8 commit e7580be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 4 additions & 7 deletions cmd/yoke/cmd_descent.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ func init() {

type DescentParams struct {
GlobalSettings
Release string
RevisionID int
yoke.DescentParams
}

func GetDescentfParams(settings GlobalSettings, args []string) (*DescentParams, error) {
Expand All @@ -39,6 +38,8 @@ func GetDescentfParams(settings GlobalSettings, args []string) (*DescentParams,

RegisterGlobalFlags(flagset, &params.GlobalSettings)

flagset.DurationVar(&params.Wait, "wait", 0, "time to wait for release to become ready")

flagset.Parse(args)

params.Release = flagset.Arg(0)
Expand All @@ -65,9 +66,5 @@ func Descent(ctx context.Context, params DescentParams) error {
if err != nil {
return fmt.Errorf("failed to instantiate k8 client: %w", err)
}

return commander.Descent(ctx, yoke.DescentParams{
Release: params.Release,
RevisionID: params.RevisionID,
})
return commander.Descent(ctx, params.DescentParams)
}
8 changes: 8 additions & 0 deletions pkg/yoke/yoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"reflect"
"time"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

Expand Down Expand Up @@ -32,6 +33,7 @@ func FromK8Client(client *k8s.Client) *Commander {
type DescentParams struct {
Release string
RevisionID int
Wait time.Duration
}

func (commander Commander) Descent(ctx context.Context, params DescentParams) error {
Expand Down Expand Up @@ -88,6 +90,12 @@ func (commander Commander) Descent(ctx context.Context, params DescentParams) er
return fmt.Errorf("failed to update resource release mapping: %w", err)
}

if params.Wait > 0 {
if err := commander.k8s.WaitForReadyMany(ctx, next.Resources, k8s.WaitOptions{Timeout: params.Wait}); err != nil {
return fmt.Errorf("release did not become ready within wait period: %w", err)
}
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/yoke/yoke_takeoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (commander Commander) Takeoff(ctx context.Context, params TakeoffParams) er

if params.Wait > 0 {
if err := commander.k8s.WaitForReadyMany(ctx, resources, k8s.WaitOptions{Timeout: params.Wait}); err != nil {
return fmt.Errorf("release did not become ready within %s timeout: to rollback use `yoke descent`: %w", params.Wait.String(), err)
return fmt.Errorf("release did not become ready within wait period: to rollback use `yoke descent`: %w", err)
}
}

Expand Down

0 comments on commit e7580be

Please sign in to comment.