diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 2e64f38ae..83fc81de9 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -168,9 +168,19 @@ func (c *Client) SetWaiter(ws WaitStrategy) error { } // New creates a new Client. -func New(getter genericclioptions.RESTClientGetter) *Client { +func New(getter genericclioptions.RESTClientGetter, waiter Waiter) *Client { if getter == nil { getter = genericclioptions.NewConfigFlags(true) + } + 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{ diff --git a/pkg/kube/client_test.go b/pkg/kube/client_test.go index 82dc4f0a8..fbf8fce18 100644 --- a/pkg/kube/client_test.go +++ b/pkg/kube/client_test.go @@ -616,10 +616,10 @@ func TestPerform(t *testing.T) { } } -// Likely it is not possible to get this test to work with kstatus given that it seems +// Likely it is not possible to get this test to work with kstatus given that it seems // kstatus is not making constant get checks on the resources and is instead waiting for events // Potentially the test could be reworked to make the pods after five seconds -// would need this -> +// would need this -> func TestWait(t *testing.T) { podList := newPodList("starfish", "otter", "squid") @@ -836,7 +836,7 @@ func TestWaitDelete(t *testing.T) { func TestReal(t *testing.T) { 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) if err != nil { t.Fatal(err) @@ -846,7 +846,7 @@ func TestReal(t *testing.T) { } testSvcEndpointManifest := testServiceManifest + "\n---\n" + testEndpointManifest - c = New(nil) + c = New(nil, nil) resources, err = c.Build(strings.NewReader(testSvcEndpointManifest), false) if err != nil { t.Fatal(err) diff --git a/pkg/kube/interface.go b/pkg/kube/interface.go index 7339ae0ff..1301bf463 100644 --- a/pkg/kube/interface.go +++ b/pkg/kube/interface.go @@ -64,6 +64,10 @@ type Waiter interface { // WaitForDelete wait up to the given timeout for the specified resources to be deleted. 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. // // 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 all other kinds, it means the kind was created or modified without // error. + // TODO: Is watch until ready really behavior we want over the resources actually being ready? WatchUntilReady(resources ResourceList, timeout time.Duration) error } diff --git a/pkg/kube/wait.go b/pkg/kube/wait.go index 9bfa1ef6d..60dd55590 100644 --- a/pkg/kube/wait.go +++ b/pkg/kube/wait.go @@ -61,6 +61,19 @@ func (hw *legacyWaiter) WaitWithJobs(resources ResourceList, timeout time.Durati 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 // Jobs(optional) until all are ready or a timeout is reached func (hw *legacyWaiter) waitForResources(created ResourceList, timeout time.Duration) error {