Add annotated reader interface for parser
An annotated reader supplies the package parser with additional context about data that was read. The parser does not require a backend reader to supply annotation information, but will check to see if the reader implements the interface and will invoke it if an error is encountered. Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
This commit is contained in:
parent
57ef784bfe
commit
28b5c76222
|
|
@ -19,10 +19,12 @@ package parser
|
|||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/afero"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
|
@ -31,6 +33,13 @@ import (
|
|||
"k8s.io/client-go/kubernetes"
|
||||
)
|
||||
|
||||
// AnnotatedReadCloser is a wrapper around io.ReadCloser that allows
|
||||
// implementations to supply additional information about data that is read.
|
||||
type AnnotatedReadCloser interface {
|
||||
io.ReadCloser
|
||||
Annotate() interface{}
|
||||
}
|
||||
|
||||
// ObjectCreaterTyper know how to create and determine the type of objects.
|
||||
type ObjectCreaterTyper interface {
|
||||
runtime.ObjectCreater
|
||||
|
|
@ -105,6 +114,9 @@ func (p *PackageParser) Parse(ctx context.Context, reader io.ReadCloser) (*Packa
|
|||
if err != nil {
|
||||
o, _, err := do.Decode(bytes, nil, nil)
|
||||
if err != nil {
|
||||
if anno, ok := reader.(AnnotatedReadCloser); ok {
|
||||
return pkg, errors.Wrap(err, fmt.Sprintf("%+v", anno.Annotate()))
|
||||
}
|
||||
return pkg, err
|
||||
}
|
||||
pkg.objects = append(pkg.objects, o)
|
||||
|
|
|
|||
Loading…
Reference in New Issue