remove kube/kube deps from resourcebuilder

pull/8/head
David Eads 2018-05-09 15:02:06 -04:00
parent 7e75a09db6
commit 76d744efe9
5 changed files with 15 additions and 16 deletions

View File

@ -23,7 +23,6 @@ go_library(
"//build/visible_to:pkg_kubectl_resource_CONSUMERS", "//build/visible_to:pkg_kubectl_resource_CONSUMERS",
], ],
deps = [ deps = [
"//pkg/kubectl/validation:go_default_library",
"//vendor/golang.org/x/text/encoding/unicode:go_default_library", "//vendor/golang.org/x/text/encoding/unicode:go_default_library",
"//vendor/golang.org/x/text/transform:go_default_library", "//vendor/golang.org/x/text/transform:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library", "//vendor/k8s.io/api/core/v1:go_default_library",
@ -62,8 +61,6 @@ go_test(
], ],
embed = [":go_default_library"], embed = [":go_default_library"],
deps = [ 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/davecgh/go-spew/spew:go_default_library",
"//vendor/github.com/ghodss/yaml:go_default_library", "//vendor/github.com/ghodss/yaml:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library", "//vendor/github.com/stretchr/testify/assert:go_default_library",

View File

@ -35,7 +35,6 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/restmapper" "k8s.io/client-go/restmapper"
"k8s.io/kubernetes/pkg/kubectl/validation"
) )
var FileExtensions = []string{".json", ".yaml", ".yml"} var FileExtensions = []string{".json", ".yaml", ".yml"}
@ -105,7 +104,7 @@ type Builder struct {
export bool export bool
schema validation.Schema schema ContentValidator
// fakeClientFn is used for testing // fakeClientFn is used for testing
fakeClientFn FakeClientFunc fakeClientFn FakeClientFunc
@ -177,7 +176,7 @@ func NewBuilder(restClientGetter RESTClientGetter) *Builder {
).AddError(mapperErr).AddError(discoveryErr) ).AddError(mapperErr).AddError(discoveryErr)
} }
func (b *Builder) Schema(schema validation.Schema) *Builder { func (b *Builder) Schema(schema ContentValidator) *Builder {
b.schema = schema b.schema = schema
return b return b
} }

View File

@ -29,6 +29,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/davecgh/go-spew/spew"
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
@ -47,11 +48,9 @@ import (
"k8s.io/client-go/rest/fake" "k8s.io/client-go/rest/fake"
restclientwatch "k8s.io/client-go/rest/watch" restclientwatch "k8s.io/client-go/rest/watch"
utiltesting "k8s.io/client-go/util/testing" 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 // TODO we need to remove this linkage and create our own scheme
"github.com/davecgh/go-spew/spew" "k8s.io/client-go/kubernetes/scheme"
_ "k8s.io/kubernetes/pkg/apis/core/install"
) )
var ( var (

View File

@ -78,3 +78,8 @@ func (c *clientOptions) Delete() *rest.Request {
func (c *clientOptions) Put() *rest.Request { func (c *clientOptions) Put() *rest.Request {
return c.modify(c.c.Put()) 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
}

View File

@ -38,7 +38,6 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors" utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/yaml" "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/apimachinery/pkg/watch" "k8s.io/apimachinery/pkg/watch"
"k8s.io/kubernetes/pkg/kubectl/validation"
) )
const ( const (
@ -219,7 +218,7 @@ func (l EagerVisitorList) Visit(fn VisitorFunc) error {
return utilerrors.NewAggregate(errs) return utilerrors.NewAggregate(errs)
} }
func ValidateSchema(data []byte, schema validation.Schema) error { func ValidateSchema(data []byte, schema ContentValidator) error {
if schema == nil { if schema == nil {
return nil return nil
} }
@ -433,7 +432,7 @@ func ignoreFile(path string, extensions []string) bool {
} }
// FileVisitorForSTDIN return a special FileVisitor just for STDIN // 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{ return &FileVisitor{
Path: constSTDINstr, Path: constSTDINstr,
StreamVisitor: NewStreamVisitor(nil, mapper, constSTDINstr, schema), 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. // 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 // 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 // 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 var visitors []Visitor
err := filepath.Walk(paths, func(path string, fi os.FileInfo, err error) error { err := filepath.Walk(paths, func(path string, fi os.FileInfo, err error) error {
if err != nil { if err != nil {
@ -513,11 +512,11 @@ type StreamVisitor struct {
*mapper *mapper
Source string 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. // 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{ return &StreamVisitor{
Reader: r, Reader: r,
mapper: mapper, mapper: mapper,