diff --git a/vendor.conf b/vendor.conf index 96961e5a..0250c890 100644 --- a/vendor.conf +++ b/vendor.conf @@ -3,5 +3,5 @@ github.com/rancher/types k8s.io/kubernetes v1.8.3 transitive=true,staging=true bitbucket.org/ww/goautoneg a547fc61f48d567d5b4ec6f8aee5573d8efce11d https://github.com/rancher/goautoneg.git -github.com/rancher/norman ee148b4d18535ee26bce4b90380d91a1d9e4ac15 +github.com/rancher/norman 5ec6a8d719917fcca3cab8e8e9036384385ced40 golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5 diff --git a/vendor/github.com/rancher/norman/generator/controller_template.go b/vendor/github.com/rancher/norman/generator/controller_template.go index bd84f973..77126f66 100644 --- a/vendor/github.com/rancher/norman/generator/controller_template.go +++ b/vendor/github.com/rancher/norman/generator/controller_template.go @@ -63,7 +63,7 @@ type {{.schema.CodeName}}Interface interface { Get(name string, opts metav1.GetOptions) (*{{.prefix}}{{.schema.CodeName}}, error) Update(*{{.prefix}}{{.schema.CodeName}}) (*{{.prefix}}{{.schema.CodeName}}, error) Delete(name string, options *metav1.DeleteOptions) error - List(opts metav1.ListOptions) (*{{.prefix}}{{.schema.CodeName}}List, error) + List(opts metav1.ListOptions) (*{{.schema.CodeName}}List, error) Watch(opts metav1.ListOptions) (watch.Interface, error) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error Controller() {{.schema.CodeName}}Controller @@ -181,9 +181,9 @@ func (s *{{.schema.ID}}Client) Delete(name string, options *metav1.DeleteOptions return s.objectClient.Delete(name, options) } -func (s *{{.schema.ID}}Client) List(opts metav1.ListOptions) (*{{.prefix}}{{.schema.CodeName}}List, error) { +func (s *{{.schema.ID}}Client) List(opts metav1.ListOptions) (*{{.schema.CodeName}}List, error) { obj, err := s.objectClient.List(opts) - return obj.(*{{.prefix}}{{.schema.CodeName}}List), err + return obj.(*{{.schema.CodeName}}List), err } func (s *{{.schema.ID}}Client) Watch(opts metav1.ListOptions) (watch.Interface, error) { diff --git a/vendor/github.com/rancher/norman/types/definition/definition.go b/vendor/github.com/rancher/norman/types/definition/definition.go index ce07d0df..1e32b12f 100644 --- a/vendor/github.com/rancher/norman/types/definition/definition.go +++ b/vendor/github.com/rancher/norman/types/definition/definition.go @@ -1,6 +1,10 @@ package definition -import "strings" +import ( + "strings" + + "github.com/rancher/norman/types/convert" +) func IsMapType(fieldType string) bool { return strings.HasPrefix(fieldType, "map[") && strings.HasSuffix(fieldType, "]") @@ -26,3 +30,12 @@ func SubType(fieldType string) string { return fieldType[i+1 : len(fieldType)-1] } + +func GetType(data map[string]interface{}) string { + parts := strings.Split(GetFullType(data), "/") + return parts[len(parts)-1] +} + +func GetFullType(data map[string]interface{}) string { + return convert.ToString(data["type"]) +} diff --git a/vendor/github.com/rancher/norman/types/factory/schemas.go b/vendor/github.com/rancher/norman/types/factory/schemas.go index 055daee0..d4a2555f 100644 --- a/vendor/github.com/rancher/norman/types/factory/schemas.go +++ b/vendor/github.com/rancher/norman/types/factory/schemas.go @@ -8,11 +8,15 @@ import ( func Schemas(version *types.APIVersion) *types.Schemas { s := types.NewSchemas() - s.DefaultMappers = []types.Mapper{ - mapper.NewObject(), + s.DefaultMappers = func() []types.Mapper { + return []types.Mapper{ + mapper.NewObject(), + } } - s.DefaultPostMappers = []types.Mapper{ - &mapper.RenameReference{}, + s.DefaultPostMappers = func() []types.Mapper { + return []types.Mapper{ + &mapper.RenameReference{}, + } } s.AddMapperForType(version, v1.ObjectMeta{}, mapper.NewMetadataMapper()) return s diff --git a/vendor/github.com/rancher/norman/types/mapper/label_field.go b/vendor/github.com/rancher/norman/types/mapper/label_field.go index 6a05d57a..f5c3b8b1 100644 --- a/vendor/github.com/rancher/norman/types/mapper/label_field.go +++ b/vendor/github.com/rancher/norman/types/mapper/label_field.go @@ -1,13 +1,16 @@ package mapper -import "github.com/rancher/norman/types" +import ( + "github.com/rancher/norman/types" + "github.com/rancher/norman/types/values" +) type LabelField struct { Field string } func (e LabelField) FromInternal(data map[string]interface{}) { - v, ok := RemoveValue(data, "labels", "io.cattle.field."+e.Field) + v, ok := values.RemoveValue(data, "labels", "io.cattle.field."+e.Field) if ok { data[e.Field] = v } @@ -16,7 +19,7 @@ func (e LabelField) FromInternal(data map[string]interface{}) { func (e LabelField) ToInternal(data map[string]interface{}) { v, ok := data[e.Field] if ok { - PutValue(data, v, "labels", "io.cattle.field."+e.Field) + values.PutValue(data, v, "labels", "io.cattle.field."+e.Field) } } diff --git a/vendor/github.com/rancher/norman/types/mapper/move.go b/vendor/github.com/rancher/norman/types/mapper/move.go index dbb9f290..6ba9f0b1 100644 --- a/vendor/github.com/rancher/norman/types/mapper/move.go +++ b/vendor/github.com/rancher/norman/types/mapper/move.go @@ -8,6 +8,7 @@ import ( "github.com/rancher/norman/types" "github.com/rancher/norman/types/convert" "github.com/rancher/norman/types/definition" + "github.com/rancher/norman/types/values" ) type Move struct { @@ -17,14 +18,14 @@ type Move struct { } func (m Move) FromInternal(data map[string]interface{}) { - if v, ok := RemoveValue(data, strings.Split(m.From, "/")...); ok { - PutValue(data, v, strings.Split(m.To, "/")...) + if v, ok := values.RemoveValue(data, strings.Split(m.From, "/")...); ok { + values.PutValue(data, v, strings.Split(m.To, "/")...) } } func (m Move) ToInternal(data map[string]interface{}) { - if v, ok := RemoveValue(data, strings.Split(m.To, "/")...); ok { - PutValue(data, v, strings.Split(m.From, "/")...) + if v, ok := values.RemoveValue(data, strings.Split(m.To, "/")...); ok { + values.PutValue(data, v, strings.Split(m.From, "/")...) } } diff --git a/vendor/github.com/rancher/norman/types/mapper/object.go b/vendor/github.com/rancher/norman/types/mapper/object.go index 21329574..f31e478d 100644 --- a/vendor/github.com/rancher/norman/types/mapper/object.go +++ b/vendor/github.com/rancher/norman/types/mapper/object.go @@ -1,6 +1,8 @@ package mapper -import "github.com/rancher/norman/types" +import ( + "github.com/rancher/norman/types" +) type Object struct { types.Mappers @@ -12,8 +14,8 @@ func NewObject(mappers ...types.Mapper) Object { &Embed{Field: "metadata"}, &Embed{Field: "spec", Optional: true}, &ReadOnly{Field: "status", Optional: true}, - &Drop{"kind"}, - &Drop{"apiVersion"}, + Drop{"kind"}, + Drop{"apiVersion"}, &Scope{ IfNot: types.NamespaceScope, Mappers: []types.Mapper{ diff --git a/vendor/github.com/rancher/norman/types/mapper/set_value.go b/vendor/github.com/rancher/norman/types/mapper/set_value.go index 4f9b553b..58558693 100644 --- a/vendor/github.com/rancher/norman/types/mapper/set_value.go +++ b/vendor/github.com/rancher/norman/types/mapper/set_value.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/rancher/norman/types" + "github.com/rancher/norman/types/values" ) type SetValue struct { @@ -15,24 +16,24 @@ type SetValue struct { } func (s SetValue) FromInternal(data map[string]interface{}) { - v, ok := GetValue(data, strings.Split(s.From, "/")...) + v, ok := values.GetValue(data, strings.Split(s.From, "/")...) if !ok { return } if v == s.IfEq { - PutValue(data, s.Value, strings.Split(s.To, "/")...) + values.PutValue(data, s.Value, strings.Split(s.To, "/")...) } } func (s SetValue) ToInternal(data map[string]interface{}) { - v, ok := GetValue(data, strings.Split(s.To, "/")...) + v, ok := values.GetValue(data, strings.Split(s.To, "/")...) if !ok { return } if v == s.Value { - PutValue(data, s.IfEq, strings.Split(s.From, "/")...) + values.PutValue(data, s.IfEq, strings.Split(s.From, "/")...) } } diff --git a/vendor/github.com/rancher/norman/types/reflection.go b/vendor/github.com/rancher/norman/types/reflection.go index cbd09f96..37ceadff 100644 --- a/vendor/github.com/rancher/norman/types/reflection.go +++ b/vendor/github.com/rancher/norman/types/reflection.go @@ -142,10 +142,14 @@ func (s *Schemas) importType(version *APIVersion, t reflect.Type, overrides ...r } mappers := s.mapper(&schema.Version, schema.ID) - if schema.CanList() { - mappers = append(s.DefaultMappers, mappers...) + if s.DefaultMappers != nil { + if schema.CanList() { + mappers = append(s.DefaultMappers(), mappers...) + } + } + if s.DefaultPostMappers != nil { + mappers = append(mappers, s.DefaultPostMappers()...) } - mappers = append(mappers, s.DefaultPostMappers...) if len(mappers) > 0 { copy, err := s.newSchemaFromType(version, t, typeName) diff --git a/vendor/github.com/rancher/norman/types/schemas.go b/vendor/github.com/rancher/norman/types/schemas.go index 64a748e5..0732d31b 100644 --- a/vendor/github.com/rancher/norman/types/schemas.go +++ b/vendor/github.com/rancher/norman/types/schemas.go @@ -15,12 +15,14 @@ type SchemaCollection struct { type SchemaInitFunc func(*Schemas) *Schemas +type MappersFactory func() []Mapper + type Schemas struct { schemasByPath map[string]map[string]*Schema schemasBySubContext map[string]*Schema mappers map[string]map[string][]Mapper - DefaultMappers []Mapper - DefaultPostMappers []Mapper + DefaultMappers MappersFactory + DefaultPostMappers MappersFactory versions []APIVersion schemas []*Schema errors []error diff --git a/vendor/github.com/rancher/norman/types/mapper/values.go b/vendor/github.com/rancher/norman/types/values/values.go similarity index 99% rename from vendor/github.com/rancher/norman/types/mapper/values.go rename to vendor/github.com/rancher/norman/types/values/values.go index 41cdaba5..634957b0 100644 --- a/vendor/github.com/rancher/norman/types/mapper/values.go +++ b/vendor/github.com/rancher/norman/types/values/values.go @@ -1,4 +1,4 @@ -package mapper +package values func RemoveValue(data map[string]interface{}, keys ...string) (interface{}, bool) { for i, key := range keys {