From 27ebab5e48cc63bc099a6193580d34d609ada9e8 Mon Sep 17 00:00:00 2001 From: Dan Ramich Date: Wed, 29 Aug 2018 11:58:46 -0700 Subject: [PATCH] Add label to objects created through norman --- objectclient/object_client.go | 13 ++++++++++++- store/proxy/proxy_store.go | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/objectclient/object_client.go b/objectclient/object_client.go index 58d4f386..777e6125 100644 --- a/objectclient/object_client.go +++ b/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) diff --git a/store/proxy/proxy_store.go b/store/proxy/proxy_store.go index c5b57ab1..3714bfa5 100644 --- a/store/proxy/proxy_store.go +++ b/store/proxy/proxy_store.go @@ -302,6 +302,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 == "" {