basic design up and balling

Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
pull/30616/head
Austin Abro 2 years ago committed by Andrea Tartaglia
parent ef0c6c3841
commit fb8c977b4e
No known key found for this signature in database

@ -168,11 +168,21 @@ func (c *Client) SetWaiter(ws WaitStrategy) error {
} }
// New creates a new Client. // New creates a new Client.
func New(getter genericclioptions.RESTClientGetter) *Client { func New(getter genericclioptions.RESTClientGetter, waiter Waiter) *Client {
if getter == nil { if getter == nil {
getter = genericclioptions.NewConfigFlags(true) getter = genericclioptions.NewConfigFlags(true)
} }
factory := cmdutil.NewFactory(getter) factory := cmdutil.NewFactory(getter)
if waiter == nil {
sw, err := getStatusWatcher(factory)
if err != nil {
// TODO, likely will move how the stats watcher is created so it doesn't need to be created
// unless it's going to be used
panic(err)
}
waiter = &kstatusWaiter{sw, nopLogger}
}
factory := cmdutil.NewFactory(getter)
c := &Client{ c := &Client{
Factory: factory, Factory: factory,
} }

@ -836,7 +836,7 @@ func TestWaitDelete(t *testing.T) {
func TestReal(t *testing.T) { func TestReal(t *testing.T) {
t.Skip("This is a live test, comment this line to run") t.Skip("This is a live test, comment this line to run")
c := New(nil) c := New(nil, nil)
resources, err := c.Build(strings.NewReader(guestbookManifest), false) resources, err := c.Build(strings.NewReader(guestbookManifest), false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -846,7 +846,7 @@ func TestReal(t *testing.T) {
} }
testSvcEndpointManifest := testServiceManifest + "\n---\n" + testEndpointManifest testSvcEndpointManifest := testServiceManifest + "\n---\n" + testEndpointManifest
c = New(nil) c = New(nil, nil)
resources, err = c.Build(strings.NewReader(testSvcEndpointManifest), false) resources, err = c.Build(strings.NewReader(testSvcEndpointManifest), false)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

@ -64,6 +64,10 @@ type Waiter interface {
// WaitForDelete wait up to the given timeout for the specified resources to be deleted. // WaitForDelete wait up to the given timeout for the specified resources to be deleted.
WaitForDelete(resources ResourceList, timeout time.Duration) error WaitForDelete(resources ResourceList, timeout time.Duration) error
// Update updates one or more resources or creates the resource
// if it doesn't exist.
Update(original, target ResourceList, force bool) (*Result, error)
// WatchUntilReady watches the resources given and waits until it is ready. // WatchUntilReady watches the resources given and waits until it is ready.
// //
// This method is mainly for hook implementations. It watches for a resource to // This method is mainly for hook implementations. It watches for a resource to
@ -73,6 +77,7 @@ type Waiter interface {
// For Pods, "ready" means the Pod phase is marked "succeeded". // For Pods, "ready" means the Pod phase is marked "succeeded".
// For all other kinds, it means the kind was created or modified without // For all other kinds, it means the kind was created or modified without
// error. // error.
// TODO: Is watch until ready really behavior we want over the resources actually being ready?
WatchUntilReady(resources ResourceList, timeout time.Duration) error WatchUntilReady(resources ResourceList, timeout time.Duration) error
} }

@ -61,6 +61,19 @@ func (hw *legacyWaiter) WaitWithJobs(resources ResourceList, timeout time.Durati
return hw.waitForResources(resources, timeout) return hw.waitForResources(resources, timeout)
} }
func (w *waiter) Wait(resources ResourceList, timeout time.Duration) error {
w.timeout = timeout
return w.waitForResources(resources)
}
func (w *waiter) WaitWithJobs(resources ResourceList, timeout time.Duration) error {
// Implementation
// TODO this function doesn't make sense unless you pass a readyChecker to it
// TODO pass context instead
w.timeout = timeout
return w.waitForResources(resources)
}
// waitForResources polls to get the current status of all pods, PVCs, Services and // waitForResources polls to get the current status of all pods, PVCs, Services and
// Jobs(optional) until all are ready or a timeout is reached // Jobs(optional) until all are ready or a timeout is reached
func (hw *legacyWaiter) waitForResources(created ResourceList, timeout time.Duration) error { func (hw *legacyWaiter) waitForResources(created ResourceList, timeout time.Duration) error {

Loading…
Cancel
Save