Remove unused TimeoutError code

This commit is contained in:
Morten Torkildsen 2021-12-07 12:58:32 +01:00
parent 9e462c333d
commit 602301ecfa
3 changed files with 0 additions and 94 deletions

View File

@ -6,7 +6,6 @@ package taskrunner
import (
"context"
"fmt"
"sort"
"time"
"sigs.k8s.io/cli-utils/pkg/apply/cache"
@ -14,7 +13,6 @@ import (
"sigs.k8s.io/cli-utils/pkg/apply/poller"
"sigs.k8s.io/cli-utils/pkg/kstatus/polling"
pollevent "sigs.k8s.io/cli-utils/pkg/kstatus/polling/event"
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
"sigs.k8s.io/cli-utils/pkg/object"
)
@ -292,46 +290,3 @@ func (b *baseRunner) nextTask(taskQueue chan Task,
type TaskResult struct {
Err error
}
// TimeoutError is a special error used by tasks when they have
// timed out.
type TimeoutError struct {
// Identifiers contains the identifiers of all resources that the
// WaitTask was waiting for.
Identifiers object.ObjMetadataSet
// Timeout is the amount of time it took before it timed out.
Timeout time.Duration
// Condition defines the criteria for which the task was waiting.
Condition Condition
TimedOutResources []TimedOutResource
}
type TimedOutResource struct {
Identifier object.ObjMetadata
Status status.Status
Message string
}
func (te TimeoutError) Error() string {
ids := []string{}
for _, id := range te.Identifiers {
ids = append(ids, id.String())
}
sort.Strings(ids)
return fmt.Sprintf("timeout after %.0f seconds waiting for %d resources (%v) to reach condition %s",
te.Timeout.Seconds(), len(te.Identifiers), ids, te.Condition)
}
// IsTimeoutError checks whether a given error is
// a TimeoutError.
func IsTimeoutError(err error) (*TimeoutError, bool) {
if e, ok := err.(*TimeoutError); ok {
return e, true
}
return &TimeoutError{}, false
}

View File

@ -13,14 +13,12 @@ import (
"text/template"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"sigs.k8s.io/cli-utils/pkg/apply/taskrunner"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/manifestreader"
)
const (
DefaultErrorExitCode = 1
TimeoutErrorExitCode = 3
)
var errorMsgForType map[reflect.Type]string
@ -42,14 +40,6 @@ package or automatically deleting omitted resources (pruning).
Package has multiple inventory object templates.
The package should have one and only one inventory object template.
`
//nolint:lll
errorMsgForType[reflect.TypeOf(taskrunner.TimeoutError{})] = `
Timeout after {{printf "%.0f" .err.Timeout.Seconds}} seconds waiting for {{printf "%d" (len .err.TimedOutResources)}} out of {{printf "%d" (len .err.Identifiers)}} resources to reach condition {{ .err.Condition}}:
{{- range .err.TimedOutResources}}
{{printf "%s/%s %s %s" .Identifier.GroupKind.Kind .Identifier.Name .Status .Message }}
{{- end}}
`
errorMsgForType[reflect.TypeOf(manifestreader.UnknownTypesError{})] = `
@ -61,7 +51,6 @@ Unknown type(s) encountered. Every type must either be already installed in the
`
statusCodeForType = make(map[reflect.Type]int)
statusCodeForType[reflect.TypeOf(taskrunner.TimeoutError{})] = TimeoutErrorExitCode
}
// CheckErr looks up the appropriate error message and exit status for known

View File

@ -7,14 +7,9 @@ import (
"fmt"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/cli-utils/pkg/apply/taskrunner"
"sigs.k8s.io/cli-utils/pkg/inventory"
"sigs.k8s.io/cli-utils/pkg/kstatus/status"
"sigs.k8s.io/cli-utils/pkg/object"
)
func TestTextForError(t *testing.T) {
@ -52,39 +47,6 @@ func TestTextForError(t *testing.T) {
cmdNameBase: "kapply",
expectFound: false,
},
"timeout error": {
err: &taskrunner.TimeoutError{
Timeout: 2 * time.Second,
Identifiers: object.ObjMetadataSet{
{
GroupKind: schema.GroupKind{
Kind: "Deployment",
Group: "apps",
},
Name: "foo",
},
},
Condition: taskrunner.AllCurrent,
TimedOutResources: []taskrunner.TimedOutResource{
{
Identifier: object.ObjMetadata{
GroupKind: schema.GroupKind{
Kind: "Deployment",
Group: "apps",
},
Name: "foo",
},
Status: status.InProgressStatus,
},
},
},
cmdNameBase: "kapply",
expectFound: true,
expectedErrText: `
Timeout after 2 seconds waiting for 1 out of 1 resources to reach condition AllCurrent:
Deployment/foo InProgress
`,
},
}
for tn, tc := range testCases {