-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Waiting For a Plan to Finish (#1461)
Signed-off-by: Ken Sipe <kensipe@gmail.com>
- Loading branch information
Showing
9 changed files
with
282 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
type Options struct { | ||
Out io.Writer | ||
Instance string | ||
Wait bool | ||
} | ||
|
||
var ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package plan | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"time" | ||
|
||
pollwait "k8s.io/apimachinery/pkg/util/wait" | ||
|
||
"github.com/kudobuilder/kudo/pkg/kudoctl/env" | ||
"github.com/kudobuilder/kudo/pkg/kudoctl/util/kudo" | ||
) | ||
|
||
// Options are the configurable options for plans | ||
type WaitOptions struct { | ||
Out io.Writer | ||
Instance string | ||
WaitTime int64 | ||
} | ||
|
||
// Status runs the plan status command | ||
func Wait(options *WaitOptions, settings *env.Settings) error { | ||
kc, err := env.GetClient(settings) | ||
if err != nil { | ||
return err | ||
} | ||
//return status(kc, options, settings.Namespace) | ||
return wait(kc, options, settings.Namespace) | ||
} | ||
|
||
func wait(kc *kudo.Client, options *WaitOptions, ns string) error { | ||
instance, err := kc.GetInstance(options.Instance, ns) | ||
if err != nil { | ||
return err | ||
} | ||
if instance == nil { | ||
return fmt.Errorf("instance %s/%s does not exist", ns, options.Instance) | ||
} | ||
|
||
planStatus := instance.GetLastExecutedPlanStatus() | ||
if planStatus == nil { | ||
return fmt.Errorf("instance %s/%s does not have an active plan", ns, options.Instance) | ||
} | ||
|
||
fmt.Fprintf(options.Out, "waiting on instance %s/%s with plan %q\n", ns, options.Instance, planStatus.Name) | ||
err = kc.WaitForInstance(options.Instance, ns, nil, time.Duration(options.WaitTime)*time.Second) | ||
if errors.Is(err, pollwait.ErrWaitTimeout) { | ||
_, _ = fmt.Fprintf(options.Out, "timeout waiting for instance %s/%s on plan %q\n", ns, options.Instance, planStatus.Name) | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
_, _ = fmt.Fprintf(options.Out, "instance %s/%s plan %q finished\n", ns, options.Instance, planStatus.Name) | ||
return nil | ||
} |
Oops, something went wrong.