mirror of https://github.com/helm/helm.git
option to wait for jobs
Signed-off-by: Austin Abro <AustinAbro321@gmail.com>
This commit is contained in:
parent
a6e5466942
commit
7b896df4d1
|
|
@ -22,6 +22,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/aggregator"
|
||||
"sigs.k8s.io/cli-utils/pkg/kstatus/polling/collector"
|
||||
|
|
@ -39,6 +40,15 @@ type kstatusWaiter struct {
|
|||
}
|
||||
|
||||
func (w *kstatusWaiter) Wait(resourceList ResourceList, timeout time.Duration) error {
|
||||
return w.wait(resourceList, timeout, false)
|
||||
}
|
||||
|
||||
func (w *kstatusWaiter) WaitWithJobs(resourceList ResourceList, timeout time.Duration) error {
|
||||
// Implementation
|
||||
return w.wait(resourceList, timeout, true)
|
||||
}
|
||||
|
||||
func (w *kstatusWaiter) wait(resourceList ResourceList, timeout time.Duration, waitWithJobs bool) error {
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), timeout)
|
||||
defer cancel()
|
||||
cancelCtx, cancel := context.WithCancel(ctx)
|
||||
|
|
@ -46,6 +56,12 @@ func (w *kstatusWaiter) Wait(resourceList ResourceList, timeout time.Duration) e
|
|||
// TODO maybe a simpler way to transfer the objects
|
||||
runtimeObjs := []runtime.Object{}
|
||||
for _, resource := range resourceList {
|
||||
switch AsVersioned(resource).(type) {
|
||||
case *batchv1.Job:
|
||||
if !waitWithJobs {
|
||||
continue
|
||||
}
|
||||
}
|
||||
runtimeObjs = append(runtimeObjs, resource.Object)
|
||||
}
|
||||
resources := []object.ObjMetadata{}
|
||||
|
|
@ -65,7 +81,6 @@ func (w *kstatusWaiter) Wait(resourceList ResourceList, timeout time.Duration) e
|
|||
if rs == nil {
|
||||
continue
|
||||
}
|
||||
fmt.Println("this is the status of object", rs.Status)
|
||||
rss = append(rss, rs)
|
||||
}
|
||||
desired := status.CurrentStatus
|
||||
|
|
@ -89,15 +104,10 @@ func (w *kstatusWaiter) Wait(resourceList ResourceList, timeout time.Duration) e
|
|||
if rs.Status == status.CurrentStatus {
|
||||
continue
|
||||
}
|
||||
errs = append(errs, fmt.Errorf("%s: %s not ready, status: %s", rs.Identifier.Name, rs.Identifier.GroupKind.Kind, rs.Status))
|
||||
errs = append(errs, fmt.Errorf("%s: %s not ready, status: %s", rs.Identifier.Name, rs.Identifier.GroupKind.Kind, rs.Status))
|
||||
}
|
||||
errs = append(errs, ctx.Err())
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *kstatusWaiter) WaitWithJobs(resources ResourceList, timeout time.Duration) error {
|
||||
// Implementation
|
||||
panic("not implemented")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,9 +90,10 @@ func getGVR(t *testing.T, mapper meta.RESTMapper, obj *unstructured.Unstructured
|
|||
func TestKWaitJob(t *testing.T) {
|
||||
t.Parallel()
|
||||
tests := []struct {
|
||||
name string
|
||||
objYamls []string
|
||||
expectErrs []error
|
||||
name string
|
||||
objYamls []string
|
||||
expectErrs []error
|
||||
waitForJobs bool
|
||||
}{
|
||||
{
|
||||
name: "Job is complete",
|
||||
|
|
@ -100,9 +101,16 @@ func TestKWaitJob(t *testing.T) {
|
|||
expectErrs: nil,
|
||||
},
|
||||
{
|
||||
name: "Job is not complete",
|
||||
objYamls: []string{jobNoStatus},
|
||||
expectErrs: []error{errors.New("test: Job not ready, status: InProgress"), errors.New("context deadline exceeded")},
|
||||
name: "Job is not complete",
|
||||
objYamls: []string{jobNoStatus},
|
||||
expectErrs: []error{errors.New("test: Job not ready, status: InProgress"), errors.New("context deadline exceeded")},
|
||||
waitForJobs: true,
|
||||
},
|
||||
{
|
||||
name: "Job is not ready, but we pass wait anyway",
|
||||
objYamls: []string{jobNoStatus},
|
||||
expectErrs: nil,
|
||||
waitForJobs: false,
|
||||
},
|
||||
{
|
||||
name: "Pod is ready",
|
||||
|
|
@ -141,7 +149,7 @@ func TestKWaitJob(t *testing.T) {
|
|||
err = fakeClient.Tracker().Create(gvr, resource, resource.GetNamespace())
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
c.Waiter = &kstatusWaiter{
|
||||
kwaiter := kstatusWaiter{
|
||||
sw: statusWatcher,
|
||||
log: c.Log,
|
||||
}
|
||||
|
|
@ -153,7 +161,7 @@ func TestKWaitJob(t *testing.T) {
|
|||
resourceList = append(resourceList, list...)
|
||||
}
|
||||
|
||||
err := c.Wait(resourceList, time.Second*3)
|
||||
err := kwaiter.wait(resourceList, time.Second*3, tt.waitForJobs)
|
||||
if tt.expectErrs != nil {
|
||||
assert.EqualError(t, err, errors.Join(tt.expectErrs...).Error())
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue