change structure of client

Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
pull/13604/head
Austin Abro 9 months ago
parent ad1f1c02ef
commit 859ff9b548
No known key found for this signature in database
GPG Key ID: 92EB5159E403F9D6

@ -87,13 +87,8 @@ type Client struct {
Namespace string
kubeClient *kubernetes.Clientset
// I see a couple different options for how waiter could be handled here
// - The waiter could be instantiated in New or at the start of each wait function //
// - The waiter could be completely separate from the client interface,
// I don't like that this causes consumers to need another interface on top of kube
// - The waiter could be bundled with the resource manager into a client object. The waiter doesn't need factory /
// Another option still would be to
waiter Waiter
ResourceManager
Waiter
}
func init() {
@ -153,7 +148,7 @@ func New(getter genericclioptions.RESTClientGetter, waiter Waiter) *Client {
return &Client{
Factory: factory,
Log: nopLogger,
waiter: waiter,
Waiter: waiter,
}
}
@ -330,16 +325,6 @@ func getResource(info *resource.Info) (runtime.Object, error) {
return obj, nil
}
// Wait waits up to the given timeout for the specified resources to be ready.
func (c *Client) Wait(resources ResourceList, timeout time.Duration) error {
return c.waiter.Wait(resources, timeout)
}
// WaitWithJobs wait up to the given timeout for the specified resources to be ready, including jobs.
func (c *Client) WaitWithJobs(resources ResourceList, timeout time.Duration) error {
return c.waiter.WaitWithJobs(resources, timeout)
}
// WaitForDelete wait up to the given timeout for the specified resources to be deleted.
func (c *Client) WaitForDelete(resources ResourceList, timeout time.Duration) error {
w := waiter{

@ -522,12 +522,11 @@ func TestWait(t *testing.T) {
t.Fatal(err)
}
checker := NewReadyChecker(cs, c.Log, PausedAsReady(true))
w := &waiter{
c.Waiter = &waiter{
c: checker,
log: c.Log,
timeout: time.Second * 30,
}
c.waiter = w
resources, err := c.Build(objBody(&podList), false)
if err != nil {
t.Fatal(err)
@ -585,12 +584,11 @@ func TestWaitJob(t *testing.T) {
t.Fatal(err)
}
checker := NewReadyChecker(cs, c.Log, PausedAsReady(true), CheckJobs(true))
w := &waiter{
c.Waiter = &waiter{
c: checker,
log: c.Log,
timeout: time.Second * 30,
}
c.waiter = w
resources, err := c.Build(objBody(job), false)
if err != nil {
t.Fatal(err)
@ -650,12 +648,11 @@ func TestWaitDelete(t *testing.T) {
t.Fatal(err)
}
checker := NewReadyChecker(cs, c.Log, PausedAsReady(true))
w := &waiter{
c.Waiter = &waiter{
c: checker,
log: c.Log,
timeout: time.Second * 30,
}
c.waiter = w
resources, err := c.Build(objBody(&pod), false)
if err != nil {
t.Fatal(err)

@ -29,6 +29,11 @@ import (
//
// A KubernetesClient must be concurrency safe.
type Interface interface {
ResourceManager
Waiter
}
type ResourceManager interface {
// Create creates one or more resources.
Create(resources ResourceList) (*Result, error)
@ -38,7 +43,6 @@ type Interface interface {
// 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
@ -50,11 +54,9 @@ type Interface interface {
// error.
// TODO: Is watch until ready really behavior we want over the resources actually being ready?
WatchUntilReady(resources ResourceList, timeout time.Duration) error
// WaitAndGetCompletedPodPhase waits up to a timeout until a pod enters a completed phase
// and returns said phase (PodSucceeded or PodFailed qualify).
WaitAndGetCompletedPodPhase(name string, timeout time.Duration) (v1.PodPhase, error)
// Build creates a resource list from a Reader.
//
// Reader must contain a YAML stream (one or more YAML documents separated
@ -62,10 +64,8 @@ type Interface interface {
//
// Validates against OpenAPI schema if validate is true.
Build(reader io.Reader, validate bool) (ResourceList, error)
// IsReachable checks whether the client is able to connect to the cluster.
IsReachable() error
Waiter
}
// Waiter defines methods related to waiting for resource states.

@ -96,7 +96,7 @@ func TestRunHealthChecks(t *testing.T) {
err = fakeClient.Tracker().Create(podGVR, pod, pod.GetNamespace())
require.NoError(t, err)
}
c.waiter = &kstatusWaiter{
c.Waiter = &kstatusWaiter{
sw: statusWatcher,
log: c.Log,
}

Loading…
Cancel
Save