diff --git a/vendor.conf b/vendor.conf index 12a15108..5fcf457d 100644 --- a/vendor.conf +++ b/vendor.conf @@ -2,4 +2,4 @@ github.com/rancher/types github.com/pkg/errors v0.8.0 -github.com/rancher/norman 92a6f9ebeeff00dc5b5c981aaaf71a30bd3f2ea7 transitive=true +github.com/rancher/norman 5bafd7b137333cb19834c530bd85e6ce05afc63c transitive=true diff --git a/vendor/github.com/rancher/norman/README.md b/vendor/github.com/rancher/norman/README.md index 2b6e8733..3ab28f91 100644 --- a/vendor/github.com/rancher/norman/README.md +++ b/vendor/github.com/rancher/norman/README.md @@ -1,66 +1,11 @@ Norman ======== -An API framework for Building [Rancher Style APIs](https://github.com/rancher/api-spec/) backed by K8s CustomResources. - -## Building - -`make` +An API framework for Building [Rancher Style APIs](https://github.com/rancher/api-spec/) backed by K8s CustomResources and their controllers. ## Example -Refer to `examples/` - -```go -package main - -import ( - "context" - "fmt" - "net/http" - "os" - - "github.com/rancher/norman/generator" - "github.com/rancher/norman/server" - "github.com/rancher/norman/types" -) - -type Foo struct { - types.Resource - Name string `json:"name"` - Foo string `json:"foo"` - SubThing Baz `json:"subThing"` -} - -type Baz struct { - Name string `json:"name"` -} - -var ( - version = types.APIVersion{ - Version: "v1", - Group: "io.cattle.core.example", - Path: "/example/v1", - } - - Schemas = types.NewSchemas() -) - -func main() { - if _, err := Schemas.Import(&version, Foo{}); err != nil { - panic(err) - } - - server, err := server.NewAPIServer(context.Background(), os.Getenv("KUBECONFIG"), Schemas) - if err != nil { - panic(err) - } - - fmt.Println("Listening on 0.0.0.0:1234") - http.ListenAndServe("0.0.0.0:1234", server) -} -``` - +Refer to https://github.com/rancher/go-skel for skeleton norman controller projects ## License Copyright (c) 2014-2017 [Rancher Labs, Inc.](http://rancher.com) diff --git a/vendor/github.com/rancher/norman/generator/controller_template.go b/vendor/github.com/rancher/norman/generator/controller_template.go index 26d52f49..c913dfec 100644 --- a/vendor/github.com/rancher/norman/generator/controller_template.go +++ b/vendor/github.com/rancher/norman/generator/controller_template.go @@ -41,7 +41,7 @@ type {{.schema.CodeName}}List struct { Items []{{.prefix}}{{.schema.CodeName}} } -type {{.schema.CodeName}}HandlerFunc func(key string, obj *{{.prefix}}{{.schema.CodeName}}) (*{{.prefix}}{{.schema.CodeName}}, error) +type {{.schema.CodeName}}HandlerFunc func(key string, obj *{{.prefix}}{{.schema.CodeName}}) (runtime.Object, error) type {{.schema.CodeName}}Lister interface { List(namespace string, selector labels.Selector) (ret []*{{.prefix}}{{.schema.CodeName}}, err error) diff --git a/vendor/github.com/rancher/norman/generator/default.go b/vendor/github.com/rancher/norman/generator/default.go new file mode 100644 index 00000000..6da459a2 --- /dev/null +++ b/vendor/github.com/rancher/norman/generator/default.go @@ -0,0 +1,66 @@ +package generator + +import ( + "fmt" + "path" + "strings" + + "github.com/rancher/norman/types" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +var ( + baseCattle = "client" + baseK8s = "apis" +) + +func DefaultGenerate(schemas *types.Schemas, pkgPath string, publicAPI bool, foreignTypes map[string]bool) error { + version := getVersion(schemas) + group := strings.Split(version.Group, ".")[0] + + cattleOutputPackage := path.Join(pkgPath, baseCattle, group, version.Version) + if !publicAPI { + cattleOutputPackage = "" + } + k8sOutputPackage := path.Join(pkgPath, baseK8s, version.Group, version.Version) + + if err := Generate(schemas, foreignTypes, cattleOutputPackage, k8sOutputPackage); err != nil { + return err + } + + return nil +} + +func ControllersForForeignTypes(baseOutputPackage string, gv schema.GroupVersion, nsObjs []interface{}, objs []interface{}) error { + version := gv.Version + group := gv.Group + groupPath := group + + if groupPath == "" { + groupPath = "core" + } + + k8sOutputPackage := path.Join(baseOutputPackage, baseK8s, groupPath, version) + + return GenerateControllerForTypes(&types.APIVersion{ + Version: version, + Group: group, + Path: fmt.Sprintf("/k8s/%s-%s", groupPath, version), + }, k8sOutputPackage, nsObjs, objs) +} + +func getVersion(schemas *types.Schemas) *types.APIVersion { + var version types.APIVersion + for _, schema := range schemas.Schemas() { + if version.Group == "" { + version = schema.Version + continue + } + if version.Group != schema.Version.Group || + version.Version != schema.Version.Version { + panic("schema set contains two APIVersions") + } + } + + return &version +} diff --git a/vendor/github.com/rancher/norman/generator/generator.go b/vendor/github.com/rancher/norman/generator/generator.go index 9e510f71..8d5c3f1c 100644 --- a/vendor/github.com/rancher/norman/generator/generator.go +++ b/vendor/github.com/rancher/norman/generator/generator.go @@ -361,27 +361,33 @@ func GenerateControllerForTypes(version *types.APIVersion, k8sOutputPackage stri return gofmt(baseDir, k8sOutputPackage) } -func Generate(schemas *types.Schemas, backendTypes map[string]bool, cattleOutputPackage, k8sOutputPackage string) error { +func Generate(schemas *types.Schemas, foreignTypes map[string]bool, cattleOutputPackage, k8sOutputPackage string) error { baseDir := args.DefaultSourceTree() cattleDir := path.Join(baseDir, cattleOutputPackage) k8sDir := path.Join(baseDir, k8sOutputPackage) + if cattleOutputPackage == "" { + cattleDir = "" + } + if err := prepareDirs(cattleDir, k8sDir); err != nil { return err } - controllers := []*types.Schema{} + var controllers []*types.Schema - cattleClientTypes := []*types.Schema{} + var cattleClientTypes []*types.Schema for _, schema := range schemas.Schemas() { if blackListTypes[schema.ID] { continue } - _, backendType := backendTypes[schema.ID] + _, backendType := foreignTypes[schema.ID] - if err := generateType(cattleDir, schema, schemas); err != nil { - return err + if cattleDir != "" { + if err := generateType(cattleDir, schema, schemas); err != nil { + return err + } } if backendType || @@ -402,8 +408,10 @@ func Generate(schemas *types.Schemas, backendTypes map[string]bool, cattleOutput } } - if err := generateClient(cattleDir, cattleClientTypes); err != nil { - return err + if cattleDir != "" { + if err := generateClient(cattleDir, cattleClientTypes); err != nil { + return err + } } if len(controllers) > 0 { @@ -424,11 +432,19 @@ func Generate(schemas *types.Schemas, backendTypes map[string]bool, cattleOutput return err } - return gofmt(baseDir, cattleOutputPackage) + if cattleOutputPackage != "" { + return gofmt(baseDir, cattleOutputPackage) + } + + return nil } func prepareDirs(dirs ...string) error { for _, dir := range dirs { + if dir == "" { + continue + } + if err := os.MkdirAll(dir, 0755); err != nil { return err } diff --git a/vendor/github.com/rancher/norman/generator/lifecycle_template.go b/vendor/github.com/rancher/norman/generator/lifecycle_template.go index a9f14abd..5594e446 100644 --- a/vendor/github.com/rancher/norman/generator/lifecycle_template.go +++ b/vendor/github.com/rancher/norman/generator/lifecycle_template.go @@ -10,9 +10,9 @@ import ( ) type {{.schema.CodeName}}Lifecycle interface { - Create(obj *{{.prefix}}{{.schema.CodeName}}) (*{{.prefix}}{{.schema.CodeName}}, error) - Remove(obj *{{.prefix}}{{.schema.CodeName}}) (*{{.prefix}}{{.schema.CodeName}}, error) - Updated(obj *{{.prefix}}{{.schema.CodeName}}) (*{{.prefix}}{{.schema.CodeName}}, error) + Create(obj *{{.prefix}}{{.schema.CodeName}}) (runtime.Object, error) + Remove(obj *{{.prefix}}{{.schema.CodeName}}) (runtime.Object, error) + Updated(obj *{{.prefix}}{{.schema.CodeName}}) (runtime.Object, error) } type {{.schema.ID}}LifecycleAdapter struct { @@ -46,9 +46,9 @@ func (w *{{.schema.ID}}LifecycleAdapter) Updated(obj runtime.Object) (runtime.Ob func New{{.schema.CodeName}}LifecycleAdapter(name string, clusterScoped bool, client {{.schema.CodeName}}Interface, l {{.schema.CodeName}}Lifecycle) {{.schema.CodeName}}HandlerFunc { adapter := &{{.schema.ID}}LifecycleAdapter{lifecycle: l} syncFn := lifecycle.NewObjectLifecycleAdapter(name, clusterScoped, adapter, client.ObjectClient()) - return func(key string, obj *{{.prefix}}{{.schema.CodeName}}) (*{{.prefix}}{{.schema.CodeName}}, error) { + return func(key string, obj *{{.prefix}}{{.schema.CodeName}}) (runtime.Object, error) { newObj, err := syncFn(key, obj) - if o, ok := newObj.(*{{.prefix}}{{.schema.CodeName}}); ok { + if o, ok := newObj.(runtime.Object); ok { return o, err } return nil, err diff --git a/vendor/github.com/rancher/norman/vendor.conf b/vendor/github.com/rancher/norman/vendor.conf index bb7d6b63..afb270b4 100644 --- a/vendor/github.com/rancher/norman/vendor.conf +++ b/vendor/github.com/rancher/norman/vendor.conf @@ -1,8 +1,8 @@ # package github.com/rancher/norman -k8s.io/kubernetes v1.12.1-lite7 https://github.com/ibuildthecloud/k3s.git transitive=true,staging=true -github.com/maruel/panicparse c0182c169410cfa80c7e8f046dad208eaef91338 -bitbucket.org/ww/goautoneg a547fc61f48d567d5b4ec6f8aee5573d8efce11d https://github.com/rancher/goautoneg.git -golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5 -github.com/gorilla/mux v1.6.1 +k8s.io/kubernetes v1.12.2-lite1 https://github.com/ibuildthecloud/k3s.git transitive=true,staging=true +github.com/maruel/panicparse c0182c169410cfa80c7e8f046dad208eaef91338 +bitbucket.org/ww/goautoneg a547fc61f48d567d5b4ec6f8aee5573d8efce11d https://github.com/rancher/goautoneg.git +golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5 +github.com/gorilla/mux v1.6.1 diff --git a/vendor/k8s.io/api/core/v1/types.go b/vendor/k8s.io/api/core/v1/types.go index f3f35d0e..02028919 100644 --- a/vendor/k8s.io/api/core/v1/types.go +++ b/vendor/k8s.io/api/core/v1/types.go @@ -5208,7 +5208,7 @@ type SecurityContext struct { // readonly paths and masked paths. // This requires the ProcMountType feature flag to be enabled. // +optional - ProcMount *ProcMountType `json:"procMount,omitEmpty" protobuf:"bytes,9,opt,name=procMount"` + ProcMount *ProcMountType `json:"procMount,omitempty" protobuf:"bytes,9,opt,name=procMount"` } type ProcMountType string diff --git a/vendor/k8s.io/apimachinery/pkg/util/net/BUILD b/vendor/k8s.io/apimachinery/pkg/util/net/BUILD index 00fba56b..d38670a8 100644 --- a/vendor/k8s.io/apimachinery/pkg/util/net/BUILD +++ b/vendor/k8s.io/apimachinery/pkg/util/net/BUILD @@ -16,7 +16,12 @@ go_test( "util_test.go", ], embed = [":go_default_library"], - deps = ["//vendor/github.com/spf13/pflag:go_default_library"], + deps = [ + "//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library", + "//vendor/github.com/spf13/pflag:go_default_library", + "//vendor/github.com/stretchr/testify/assert:go_default_library", + "//vendor/github.com/stretchr/testify/require:go_default_library", + ], ) go_library( diff --git a/vendor/k8s.io/apimachinery/pkg/util/net/http.go b/vendor/k8s.io/apimachinery/pkg/util/net/http.go index 8abbdea8..7c2a5e62 100644 --- a/vendor/k8s.io/apimachinery/pkg/util/net/http.go +++ b/vendor/k8s.io/apimachinery/pkg/util/net/http.go @@ -321,9 +321,10 @@ type Dialer interface { // ConnectWithRedirects uses dialer to send req, following up to 10 redirects (relative to // originalLocation). It returns the opened net.Conn and the raw response bytes. -func ConnectWithRedirects(originalMethod string, originalLocation *url.URL, header http.Header, originalBody io.Reader, dialer Dialer) (net.Conn, []byte, error) { +// If requireSameHostRedirects is true, only redirects to the same host are permitted. +func ConnectWithRedirects(originalMethod string, originalLocation *url.URL, header http.Header, originalBody io.Reader, dialer Dialer, requireSameHostRedirects bool) (net.Conn, []byte, error) { const ( - maxRedirects = 10 + maxRedirects = 9 // Fail on the 10th redirect maxResponseSize = 16384 // play it safe to allow the potential for lots of / large headers ) @@ -387,10 +388,6 @@ redirectLoop: resp.Body.Close() // not used - // Reset the connection. - intermediateConn.Close() - intermediateConn = nil - // Prepare to follow the redirect. redirectStr := resp.Header.Get("Location") if redirectStr == "" { @@ -404,6 +401,15 @@ redirectLoop: if err != nil { return nil, nil, fmt.Errorf("malformed Location header: %v", err) } + + // Only follow redirects to the same host. Otherwise, propagate the redirect response back. + if requireSameHostRedirects && location.Hostname() != originalLocation.Hostname() { + break redirectLoop + } + + // Reset the connection. + intermediateConn.Close() + intermediateConn = nil } connToReturn := intermediateConn diff --git a/vendor/k8s.io/client-go/pkg/version/base.go b/vendor/k8s.io/client-go/pkg/version/base.go index c9dae68b..2e358d2f 100644 --- a/vendor/k8s.io/client-go/pkg/version/base.go +++ b/vendor/k8s.io/client-go/pkg/version/base.go @@ -3,8 +3,8 @@ package version var ( gitMajor = "1" gitMinor = "12" - gitVersion = "v1.12.1-lite7" - gitCommit = "b5d55f02488df0daa1399df41777aeeeaa36eabb" + gitVersion = "v1.12.2-lite1" + gitCommit = "44905551dd08ce1e656c9e07c4a5d90627f01774" gitTreeState = "clean" - buildDate = "2018-10-24T23:26+00:00Z" + buildDate = "2018-10-30T18:28+00:00Z" )