From c2683e103ad39c7c5a9d4ffedaf073d7973be475 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Mon, 24 Sep 2018 09:05:20 -0700 Subject: [PATCH] Update vendor --- vendor.conf | 2 +- .../norman/controller/generic_controller.go | 2 +- .../norman/generator/controller_template.go | 5 +++++ .../norman/objectclient/object_client.go | 17 ++++++++++++++++- .../rancher/norman/store/proxy/proxy_store.go | 11 +++++++---- .../rancher/norman/types/convert/convert.go | 8 ++++++-- .../github.com/rancher/norman/types/schemas.go | 7 ++++++- vendor/github.com/rancher/norman/types/types.go | 1 + 8 files changed, 43 insertions(+), 10 deletions(-) diff --git a/vendor.conf b/vendor.conf index 55cfe29c..15e6075c 100644 --- a/vendor.conf +++ b/vendor.conf @@ -5,4 +5,4 @@ k8s.io/kubernetes v1.10.5 bitbucket.org/ww/goautoneg a547fc61f48d567d5b4ec6f8aee5573d8efce11d https://github.com/rancher/goautoneg.git golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5 -github.com/rancher/norman 12c3f92bed31fe8f49f699aabecdc79725b08bb6 +github.com/rancher/norman e5c60cd6bca90fa0617a9ae07430ef6ad2a92b28 diff --git a/vendor/github.com/rancher/norman/controller/generic_controller.go b/vendor/github.com/rancher/norman/controller/generic_controller.go index 60fd3a10..f04b4426 100644 --- a/vendor/github.com/rancher/norman/controller/generic_controller.go +++ b/vendor/github.com/rancher/norman/controller/generic_controller.go @@ -204,7 +204,7 @@ func (g *genericController) processNextWorkItem() bool { } if _, ok := checkErr.(*ForgetError); err == nil || ok { if ok { - logrus.Infof("%v %v completed with dropped err: %v", g.name, key, err) + logrus.Debugf("%v %v completed with dropped err: %v", g.name, key, err) } g.queue.Forget(key) return true diff --git a/vendor/github.com/rancher/norman/generator/controller_template.go b/vendor/github.com/rancher/norman/generator/controller_template.go index 2f0d6a62..eed51605 100644 --- a/vendor/github.com/rancher/norman/generator/controller_template.go +++ b/vendor/github.com/rancher/norman/generator/controller_template.go @@ -49,6 +49,7 @@ type {{.schema.CodeName}}Lister interface { } type {{.schema.CodeName}}Controller interface { + Generic() controller.GenericController Informer() cache.SharedIndexInformer Lister() {{.schema.CodeName}}Lister AddHandler(name string, handler {{.schema.CodeName}}HandlerFunc) @@ -111,6 +112,10 @@ type {{.schema.ID}}Controller struct { controller.GenericController } +func (c *{{.schema.ID}}Controller) Generic() controller.GenericController { + return c.GenericController +} + func (c *{{.schema.ID}}Controller) Lister() {{.schema.CodeName}}Lister { return &{{.schema.ID}}Lister{ controller: c, diff --git a/vendor/github.com/rancher/norman/objectclient/object_client.go b/vendor/github.com/rancher/norman/objectclient/object_client.go index 58d4f386..29b85811 100644 --- a/vendor/github.com/rancher/norman/objectclient/object_client.go +++ b/vendor/github.com/rancher/norman/objectclient/object_client.go @@ -94,9 +94,20 @@ func (p *ObjectClient) getAPIPrefix() string { func (p *ObjectClient) Create(o runtime.Object) (runtime.Object, error) { ns := p.ns - if obj, ok := o.(metav1.Object); ok && obj.GetNamespace() != "" { + obj, ok := o.(metav1.Object) + if ok && obj.GetNamespace() != "" { ns = obj.GetNamespace() } + + if ok { + labels := obj.GetLabels() + if labels == nil { + labels = make(map[string]string) + } + labels["cattle.io/creator"] = "norman" + obj.SetLabels(labels) + } + if t, err := meta.TypeAccessor(o); err == nil { if t.GetKind() == "" { t.SetKind(p.gvk.Kind) @@ -245,6 +256,10 @@ func (d *structuredDecoder) Decode(data []byte, defaults *schema.GroupVersionKin err := json.Unmarshal(data, &into) if err != nil { + status := &metav1.Status{} + if err := json.Unmarshal(data, status); err == nil && strings.ToLower(status.Kind) == "status" { + return status, defaults, nil + } return nil, nil, err } diff --git a/vendor/github.com/rancher/norman/store/proxy/proxy_store.go b/vendor/github.com/rancher/norman/store/proxy/proxy_store.go index c5b57ab1..54f66fb7 100644 --- a/vendor/github.com/rancher/norman/store/proxy/proxy_store.go +++ b/vendor/github.com/rancher/norman/store/proxy/proxy_store.go @@ -39,7 +39,6 @@ var ( ) type ClientGetter interface { - Config(apiContext *types.APIContext, context types.StorageContext) (rest.Config, error) UnversionedClient(apiContext *types.APIContext, context types.StorageContext) (rest.Interface, error) APIExtClient(apiContext *types.APIContext, context types.StorageContext) (clientset.Interface, error) } @@ -244,8 +243,9 @@ func (s *Store) realWatch(apiContext *types.APIContext, schema *types.Schema, op decoder := streaming.NewDecoder(framer, &unstructuredDecoder{}) watcher := watch.NewStreamWatcher(restclientwatch.NewDecoder(decoder, &unstructuredDecoder{})) + watchingContext, cancelWatchingContext := context.WithCancel(apiContext.Request.Context()) go func() { - <-apiContext.Request.Context().Done() + <-watchingContext.Done() logrus.Debugf("stopping watcher for %s", schema.ID) watcher.Stop() }() @@ -262,6 +262,7 @@ func (s *Store) realWatch(apiContext *types.APIContext, schema *types.Schema, op } logrus.Debugf("closing watcher for %s", schema.ID) close(result) + cancelWatchingContext() }() return result, nil @@ -283,10 +284,11 @@ func getNamespace(apiContext *types.APIContext, opt *types.QueryOptions) string } for _, condition := range opt.Conditions { - if condition.Field == "namespaceId" && condition.Value != "" { + mod := condition.ToCondition().Modifier + if condition.Field == "namespaceId" && condition.Value != "" && mod == types.ModifierEQ { return condition.Value } - if condition.Field == "namespace" && condition.Value != "" { + if condition.Field == "namespace" && condition.Value != "" && mod == types.ModifierEQ { return condition.Value } } @@ -302,6 +304,7 @@ func (s *Store) Create(apiContext *types.APIContext, schema *types.Schema, data namespace, _ := values.GetValueN(data, "metadata", "namespace").(string) values.PutValue(data, s.getUser(apiContext), "metadata", "annotations", "field.cattle.io/creatorId") + values.PutValue(data, "norman", "metadata", "labels", "cattle.io/creator") name, _ := values.GetValueN(data, "metadata", "name").(string) if name == "" { diff --git a/vendor/github.com/rancher/norman/types/convert/convert.go b/vendor/github.com/rancher/norman/types/convert/convert.go index 6f5e61ae..9529ae4c 100644 --- a/vendor/github.com/rancher/norman/types/convert/convert.go +++ b/vendor/github.com/rancher/norman/types/convert/convert.go @@ -44,7 +44,7 @@ func Singular(value interface{}) interface{} { return value } -func ToString(value interface{}) string { +func ToStringNoTrim(value interface{}) string { if t, ok := value.(time.Time); ok { return t.Format(time.RFC3339) } @@ -52,7 +52,11 @@ func ToString(value interface{}) string { if single == nil { return "" } - return strings.TrimSpace(fmt.Sprint(single)) + return fmt.Sprint(single) +} + +func ToString(value interface{}) string { + return strings.TrimSpace(ToStringNoTrim(value)) } func ToTimestamp(value interface{}) (int64, error) { diff --git a/vendor/github.com/rancher/norman/types/schemas.go b/vendor/github.com/rancher/norman/types/schemas.go index f724c997..5d2d7d67 100644 --- a/vendor/github.com/rancher/norman/types/schemas.go +++ b/vendor/github.com/rancher/norman/types/schemas.go @@ -170,7 +170,12 @@ func (s *Schemas) embed(schema *Schema) { newSchema.ResourceFields = map[string]Field{} for k, v := range target.ResourceFields { - newSchema.ResourceFields[k] = v + // We remove the dynamic fields off the existing schema in case + // they've been removed from the dynamic schema so they won't + // be accidentally left over + if !v.DynamicField { + newSchema.ResourceFields[k] = v + } } for k, v := range schema.ResourceFields { newSchema.ResourceFields[k] = v diff --git a/vendor/github.com/rancher/norman/types/types.go b/vendor/github.com/rancher/norman/types/types.go index 88dfad3e..4951c70b 100644 --- a/vendor/github.com/rancher/norman/types/types.go +++ b/vendor/github.com/rancher/norman/types/types.go @@ -136,6 +136,7 @@ type Field struct { InvalidChars string `json:"invalidChars,omitempty"` Description string `json:"description,omitempty"` CodeName string `json:"-"` + DynamicField bool `json:"dynamicField,omitempty"` } type Action struct {