diff --git a/pkg/kubectl/resource/BUILD b/pkg/kubectl/resource/BUILD index a9cd926b5a..7b2560b5a5 100644 --- a/pkg/kubectl/resource/BUILD +++ b/pkg/kubectl/resource/BUILD @@ -23,7 +23,6 @@ go_library( "//build/visible_to:pkg_kubectl_resource_CONSUMERS", ], deps = [ - "//pkg/kubectl/validation:go_default_library", "//vendor/golang.org/x/text/encoding/unicode:go_default_library", "//vendor/golang.org/x/text/transform:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library", @@ -62,8 +61,6 @@ go_test( ], embed = [":go_default_library"], deps = [ - "//pkg/apis/core/install:go_default_library", - "//pkg/kubectl/scheme:go_default_library", "//vendor/github.com/davecgh/go-spew/spew:go_default_library", "//vendor/github.com/ghodss/yaml:go_default_library", "//vendor/github.com/stretchr/testify/assert:go_default_library", diff --git a/pkg/kubectl/resource/builder.go b/pkg/kubectl/resource/builder.go index 71bb3253e5..e92b2b4893 100644 --- a/pkg/kubectl/resource/builder.go +++ b/pkg/kubectl/resource/builder.go @@ -35,7 +35,6 @@ import ( utilerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/restmapper" - "k8s.io/kubernetes/pkg/kubectl/validation" ) var FileExtensions = []string{".json", ".yaml", ".yml"} @@ -105,7 +104,7 @@ type Builder struct { export bool - schema validation.Schema + schema ContentValidator // fakeClientFn is used for testing fakeClientFn FakeClientFunc @@ -177,7 +176,7 @@ func NewBuilder(restClientGetter RESTClientGetter) *Builder { ).AddError(mapperErr).AddError(discoveryErr) } -func (b *Builder) Schema(schema validation.Schema) *Builder { +func (b *Builder) Schema(schema ContentValidator) *Builder { b.schema = schema return b } diff --git a/pkg/kubectl/resource/builder_test.go b/pkg/kubectl/resource/builder_test.go index f13f280b65..c702fdf073 100644 --- a/pkg/kubectl/resource/builder_test.go +++ b/pkg/kubectl/resource/builder_test.go @@ -29,6 +29,7 @@ import ( "strings" "testing" + "github.com/davecgh/go-spew/spew" "github.com/ghodss/yaml" "k8s.io/api/core/v1" @@ -47,11 +48,9 @@ import ( "k8s.io/client-go/rest/fake" restclientwatch "k8s.io/client-go/rest/watch" utiltesting "k8s.io/client-go/util/testing" - "k8s.io/kubernetes/pkg/kubectl/scheme" - // install the pod scheme into the legacy scheme for test typer resolution - "github.com/davecgh/go-spew/spew" - _ "k8s.io/kubernetes/pkg/apis/core/install" + // TODO we need to remove this linkage and create our own scheme + "k8s.io/client-go/kubernetes/scheme" ) var ( diff --git a/pkg/kubectl/resource/interfaces.go b/pkg/kubectl/resource/interfaces.go index c776eb6bfe..1a26ec9cc8 100644 --- a/pkg/kubectl/resource/interfaces.go +++ b/pkg/kubectl/resource/interfaces.go @@ -78,3 +78,8 @@ func (c *clientOptions) Delete() *rest.Request { func (c *clientOptions) Put() *rest.Request { return c.modify(c.c.Put()) } + +// ContentValidator is an interface that knows how to validate an API object serialized to a byte array. +type ContentValidator interface { + ValidateBytes(data []byte) error +} diff --git a/pkg/kubectl/resource/visitor.go b/pkg/kubectl/resource/visitor.go index 20550940eb..55031a470b 100644 --- a/pkg/kubectl/resource/visitor.go +++ b/pkg/kubectl/resource/visitor.go @@ -38,7 +38,6 @@ import ( utilerrors "k8s.io/apimachinery/pkg/util/errors" "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/apimachinery/pkg/watch" - "k8s.io/kubernetes/pkg/kubectl/validation" ) const ( @@ -219,7 +218,7 @@ func (l EagerVisitorList) Visit(fn VisitorFunc) error { return utilerrors.NewAggregate(errs) } -func ValidateSchema(data []byte, schema validation.Schema) error { +func ValidateSchema(data []byte, schema ContentValidator) error { if schema == nil { return nil } @@ -433,7 +432,7 @@ func ignoreFile(path string, extensions []string) bool { } // FileVisitorForSTDIN return a special FileVisitor just for STDIN -func FileVisitorForSTDIN(mapper *mapper, schema validation.Schema) Visitor { +func FileVisitorForSTDIN(mapper *mapper, schema ContentValidator) Visitor { return &FileVisitor{ Path: constSTDINstr, StreamVisitor: NewStreamVisitor(nil, mapper, constSTDINstr, schema), @@ -443,7 +442,7 @@ func FileVisitorForSTDIN(mapper *mapper, schema validation.Schema) Visitor { // ExpandPathsToFileVisitors will return a slice of FileVisitors that will handle files from the provided path. // After FileVisitors open the files, they will pass an io.Reader to a StreamVisitor to do the reading. (stdin // is also taken care of). Paths argument also accepts a single file, and will return a single visitor -func ExpandPathsToFileVisitors(mapper *mapper, paths string, recursive bool, extensions []string, schema validation.Schema) ([]Visitor, error) { +func ExpandPathsToFileVisitors(mapper *mapper, paths string, recursive bool, extensions []string, schema ContentValidator) ([]Visitor, error) { var visitors []Visitor err := filepath.Walk(paths, func(path string, fi os.FileInfo, err error) error { if err != nil { @@ -513,11 +512,11 @@ type StreamVisitor struct { *mapper Source string - Schema validation.Schema + Schema ContentValidator } // NewStreamVisitor is a helper function that is useful when we want to change the fields of the struct but keep calls the same. -func NewStreamVisitor(r io.Reader, mapper *mapper, source string, schema validation.Schema) *StreamVisitor { +func NewStreamVisitor(r io.Reader, mapper *mapper, source string, schema ContentValidator) *StreamVisitor { return &StreamVisitor{ Reader: r, mapper: mapper,