Skip to content

Commit

Permalink
Fixes prune timeout value
Browse files Browse the repository at this point in the history
  • Loading branch information
seans3 committed Sep 27, 2021
1 parent 73a24dc commit bbd7cf1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
8 changes: 4 additions & 4 deletions pkg/apply/solver/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (t *TaskQueueBuilder) AppendPruneWaitTasks(pruneObjs []*unstructured.Unstru
t.err = err
}
addWaitTask, waitTimeout := waitTaskTimeout(o.DryRunStrategy.ClientOrServerDryRun(),
len(pruneSets), o.ReconcileTimeout)
len(pruneSets), o.PruneTimeout)
for _, pruneSet := range pruneSets {
t.AppendPruneTask(pruneSet, pruneFilters, o)
if addWaitTask {
Expand All @@ -261,13 +261,13 @@ func (t *TaskQueueBuilder) AppendPruneWaitTasks(pruneObjs []*unstructured.Unstru

// waitTaskTimeout returns true if the wait task should be added to the task queue;
// false otherwise. If true, also returns the duration within wait task before timeout.
func waitTaskTimeout(dryRun bool, numObjSets int, reconcileTimeout time.Duration) (bool, time.Duration) {
func waitTaskTimeout(dryRun bool, numObjSets int, waitTimeout time.Duration) (bool, time.Duration) {
var zeroTimeout = time.Duration(0)
if dryRun {
return false, zeroTimeout
}
if reconcileTimeout != zeroTimeout {
return true, reconcileTimeout
if waitTimeout != zeroTimeout {
return true, waitTimeout
}
if numObjSets > 1 {
return true, defaultWaitTimeout
Expand Down
38 changes: 35 additions & 3 deletions pkg/apply/solver/solver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,41 @@ func TestTaskQueueBuilder_AppendPruneWaitTasks(t *testing.T) {
},
isError: false,
},
"single resource with prune timeout has wait task": {
pruneObjs: []*unstructured.Unstructured{
testutil.Unstructured(t, resources["pod"]),
},
options: Options{
Prune: true,
PruneTimeout: 3 * time.Minute,
},
expectedTasks: []taskrunner.Task{
&task.PruneTask{
TaskName: "prune-0",
Objects: []*unstructured.Unstructured{
testutil.Unstructured(t, resources["pod"]),
},
},
taskrunner.NewWaitTask(
"wait-0",
[]object.ObjMetadata{
testutil.ToIdentifier(t, resources["pod"]),
},
taskrunner.AllCurrent,
3*time.Minute,
testutil.NewFakeRESTMapper()),
},
isError: false,
},
"multiple resources with prune timeout and server-dryrun": {
pruneObjs: []*unstructured.Unstructured{
testutil.Unstructured(t, resources["pod"]),
testutil.Unstructured(t, resources["default-pod"]),
},
options: Options{
ReconcileTimeout: time.Minute,
DryRunStrategy: common.DryRunServer,
Prune: true,
PruneTimeout: time.Minute,
DryRunStrategy: common.DryRunServer,
Prune: true,
},
// No wait task, since it is dry run
expectedTasks: []taskrunner.Task{
Expand Down Expand Up @@ -655,6 +681,12 @@ func TestTaskQueueBuilder_AppendPruneWaitTasks(t *testing.T) {
expTsk.Ids, actWaitTask.Ids)
}
assert.Equal(t, taskrunner.AllNotFound, actWaitTask.Condition)
// Validate the prune wait timeout.
expectedTimeout := defaultWaitTimeout
if tc.options.PruneTimeout != time.Duration(0) {
expectedTimeout = tc.options.PruneTimeout
}
assert.Equal(t, expectedTimeout, actualTask.(*taskrunner.WaitTask).Timeout)
}
}
})
Expand Down

0 comments on commit bbd7cf1

Please sign in to comment.