From bef411565778882a4b0132a24c294530e84408e2 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Thu, 7 Mar 2019 11:25:37 -0700 Subject: [PATCH 1/2] Assign default namespace if not set in manifests --- pkg/deploy/controller.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/deploy/controller.go b/pkg/deploy/controller.go index 8279b9b84e..a050fceab6 100644 --- a/pkg/deploy/controller.go +++ b/pkg/deploy/controller.go @@ -74,6 +74,7 @@ type watcher struct { restConfig rest.Config discovery discovery.DiscoveryInterface clients map[schema.GroupVersionKind]*objectclient.ObjectClient + namespaced map[schema.GroupVersionKind]bool } func (w *watcher) start(ctx context.Context) { @@ -208,15 +209,25 @@ func (w *watcher) apply(addon v1.Addon, set *objectset.ObjectSet) (map[schema.Gr ds := op.NewDesiredSet(nil, set) for _, gvk := range addon.Status.GVKs { + var ( + namespaced bool + ) + client, ok := w.clients[gvk] - if !ok { - client, err = objectset.NewDiscoveredClient(gvk, w.restConfig, w.discovery) + if ok { + namespaced = w.namespaced[gvk] + } else { + client, namespaced, err = objectset.NewDiscoveredClient(gvk, w.restConfig, w.discovery) if err != nil { return nil, err } + if w.namespaced == nil { + w.namespaced = map[schema.GroupVersionKind]bool{} + } + w.namespaced[gvk] = namespaced } - ds.AddDiscoveredClient(gvk, client) + ds.AddDiscoveredClient(gvk, client, namespaced) } if err := ds.Apply(); err != nil { From 80d8d3126c1ce8b3c638c49529d75ed6e845926a Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Thu, 7 Mar 2019 12:56:57 -0700 Subject: [PATCH 2/2] Update vendor --- trash.lock | 222 +++++++++--------- vendor.conf | 2 +- vendor/github.com/rancher/norman/build.go | 5 +- .../norman/objectclient/object_client.go | 1 + .../norman/pkg/objectset/desiredset.go | 7 +- .../pkg/objectset/desiredset_process.go | 56 ++++- 6 files changed, 165 insertions(+), 128 deletions(-) diff --git a/trash.lock b/trash.lock index 1224688f8e..5500459442 100755 --- a/trash.lock +++ b/trash.lock @@ -111,7 +111,7 @@ import: - package: github.com/pkg/errors version: v0.8.0 - package: github.com/rancher/norman - version: 816007443daf04e96c7806c2a637dfab8ede9429 + version: f75e3607e96e1a5d3cbaf4ee7cea1459cc727f61 repo: https://github.com/ibuildthecloud/norman.git - package: github.com/seccomp/libseccomp-golang version: 32f571b70023028bd57d9288c20efbcb237f3ce0 @@ -159,141 +159,141 @@ import: repo: https://github.com/rancher/k3s.git transitive: true staging: true -- package: github.com/euank/go-kmsg-parser - version: v2.0.0 -- package: github.com/shurcooL/sanitized_anchor_name - version: 10ef21a441db47d8b13ebcc5fd2310f636973c77 -- package: vbom.ml/util - version: db5cfe13f5cc80a4990d98e2e1b0707a4d1a5394 -- package: github.com/MakeNowJust/heredoc - version: bb23615498cded5e105af4ce27de75b089cbe851 -- package: github.com/exponent-io/jsonpath - version: d6023ce2651d8eafb5c75bb0c7167536102ec9f5 -- package: github.com/ibuildthecloud/kvsql - version: c649f12fe5250718e4e024b8b40e7de796ab095e -- package: github.com/prometheus/client_golang - version: v0.8.0-83-ge7e903064f5e9e -- package: github.com/spf13/pflag - version: v1.0.1 -- package: github.com/googleapis/gnostic - version: 0c5108395e2debce0d731cf0287ddf7242066aba -- package: github.com/fatih/camelcase - version: f6a740d52f961c60348ebb109adde9f4635d7540 - package: github.com/mxk/go-flowrate version: cca7078d478f8520f85629ad7c68962d31ed7682 -- package: github.com/coreos/go-semver - version: v0.2.0-9-ge214231b295a8e -- package: github.com/docker/docker - version: docs-v1.12.0-rc4-2016-07-15-9510-ga9fbbdc8dd8794 - package: github.com/JeffAshton/win_pdh version: 76bb4ee9f0ab50f77826f2a2ee7fb9d3880d6ec2 -- package: github.com/miekg/dns - version: 5d001d020961ae1c184f9f8152fdc73810481677 -- package: github.com/prometheus/procfs - version: 65c1f6f8f0fc1e2185eb9863a3bc751496404259 +- package: github.com/inconshreveable/mousetrap + version: v1.0 +- package: github.com/mistifyio/go-zfs + version: v2.1.1-5-g1b4ae6fb4e77b0 - package: github.com/Azure/go-ansiterm version: d6e3b3328b783f23731bc4d058875b0371ff8109 -- package: k8s.io/klog - version: 8139d8cb77af419532b33dfa7dd09fbc5f1d344f -- package: github.com/gregjones/httpcache - version: 787624de3eb7bd915c329cba748687a3b22666a6 -- package: github.com/coreos/pkg - version: v4 -- package: github.com/daviddengcn/go-colortext - version: 511bcaf42ccd42c38aba7427b6673277bf19e2a1 +- package: github.com/docker/go-connections + version: v0.3.0 +- package: k8s.io/gengo + version: 51747d6e00da1fc578d5a333a93bb2abcbce7a95 - package: github.com/robfig/cron version: v1-53-gdf38d32658d878 -- package: github.com/hashicorp/golang-lru - version: a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4 -- package: github.com/jonboulle/clockwork - version: 72f9bd7c4e0c2a40055ab3d0f09654f730cce982 -- package: github.com/prometheus/client_model - version: model-0.0.2-12-gfa8ad6fec33561 -- package: gopkg.in/natefinch/lumberjack.v2 - version: v1.0-16-g20b71e5b60d756 -- package: github.com/mrunalp/fileutils - version: 4ee1cc9a80582a0c75febdd5cfa779ee4361cbca -- package: github.com/vishvananda/netlink - version: b2de5d10e38ecce8607e6b438b6d174f389a004e -- package: github.com/russross/blackfriday - version: v1.4-2-g300106c228d52c -- package: github.com/cyphar/filepath-securejoin - version: v0.2.1-1-gae69057f2299fb - package: github.com/chai2010/gettext-go version: c6fed771bfd517099caf0f7a961671fa8ed08723 -- package: github.com/coreos/etcd - version: v3.3.10 -- package: github.com/docker/libnetwork - version: v0.8.0-dev.2-1265-ga9cd636e378982 -- package: github.com/google/cadvisor - version: 87e237ff35b9d752ba58860a06e0ebe57816cbb7 - repo: https://github.com/ibuildthecloud/cadvisor.git +- package: github.com/russross/blackfriday + version: v1.4-2-g300106c228d52c +- package: bitbucket.org/ww/goautoneg + version: a547fc61f48d567d5b4ec6f8aee5573d8efce11d + repo: https://github.com/rancher/goautoneg.git +- package: github.com/coreos/go-semver + version: v0.2.0-9-ge214231b295a8e +- package: github.com/mindprince/gonvml + version: fee913ce8fb235edf54739d259ca0ecc226c7b8a +- package: github.com/spf13/pflag + version: v1.0.1 +- package: github.com/euank/go-kmsg-parser + version: v2.0.0 +- package: github.com/fsnotify/fsnotify + version: v1.3.1-1-gf12c6236fe7b5c +- package: github.com/prometheus/common + version: 13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207 - package: github.com/google/certificate-transparency-go version: v1.0.21 - package: golang.org/x/tools version: 2382e3994d48b1d22acc2c86bcad0a2aff028e32 -- package: github.com/docker/go-units - version: v0.3.1-11-g9e638d38cf6977 +- package: vbom.ml/util + version: db5cfe13f5cc80a4990d98e2e1b0707a4d1a5394 +- package: github.com/google/cadvisor + version: 87e237ff35b9d752ba58860a06e0ebe57816cbb7 + repo: https://github.com/ibuildthecloud/cadvisor.git +- package: github.com/hashicorp/golang-lru + version: a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4 +- package: github.com/cloudflare/cfssl + version: 1.3.2-21-g56268a613adfed +- package: github.com/docker/libnetwork + version: v0.8.0-dev.2-1265-ga9cd636e378982 +- package: github.com/prometheus/client_golang + version: v0.8.0-83-ge7e903064f5e9e +- package: sigs.k8s.io/yaml + version: v1.1.0 +- package: github.com/Nvveen/Gotty + version: cd527374f1e5bff4938207604a14f2e38a9cf512 +- package: github.com/mattn/go-shellwords + version: v1.0.3-20-gf8471b0a71ded0 +- package: github.com/gregjones/httpcache + version: 787624de3eb7bd915c329cba748687a3b22666a6 +- package: github.com/imdario/mergo + version: v0.3.5 +- package: github.com/karrick/godirwalk + version: v1.7.5 +- package: github.com/mitchellh/go-wordwrap + version: ad45545899c7b13c020ea92b2072220eefad42b8 +- package: github.com/google/btree + version: 7d79101e329e5a3adf994758c578dab82b90c017 - package: github.com/armon/circbuf version: bbbad097214e2918d8543d5201d12bfd7bca254d +- package: github.com/prometheus/procfs + version: 65c1f6f8f0fc1e2185eb9863a3bc751496404259 +- package: github.com/googleapis/gnostic + version: 0c5108395e2debce0d731cf0287ddf7242066aba +- package: github.com/peterbourgon/diskv + version: v2.0.1 +- package: github.com/vishvananda/netns + version: be1fbeda19366dea804f00efff2dd73a1642fdcc +- package: github.com/evanphx/json-patch + version: v4.1.0-19-g5858425f75500d - package: github.com/spf13/cobra version: v0.0.1-34-gc439c4fa093711 -- package: github.com/docker/go-connections - version: v0.3.0 +- package: github.com/ugorji/go + version: bdcc60b419d136a85cdf2e7cbcac34b3f1cd6e57 +- package: github.com/miekg/dns + version: 5d001d020961ae1c184f9f8152fdc73810481677 +- package: github.com/vishvananda/netlink + version: b2de5d10e38ecce8607e6b438b6d174f389a004e +- package: github.com/container-storage-interface/spec + version: v1.0.0 +- package: github.com/jteeuwen/go-bindata + version: v3.0.7-72-ga0ff2567cfb709 +- package: github.com/shurcooL/sanitized_anchor_name + version: 10ef21a441db47d8b13ebcc5fd2310f636973c77 - package: github.com/golang/groupcache version: 02826c3e79038b59d737d3b1c0a1d937f71a4433 -- package: github.com/google/btree - version: 7d79101e329e5a3adf994758c578dab82b90c017 +- package: github.com/mrunalp/fileutils + version: 4ee1cc9a80582a0c75febdd5cfa779ee4361cbca +- package: github.com/prometheus/client_model + version: model-0.0.2-12-gfa8ad6fec33561 +- package: github.com/exponent-io/jsonpath + version: d6023ce2651d8eafb5c75bb0c7167536102ec9f5 +- package: github.com/MakeNowJust/heredoc + version: bb23615498cded5e105af4ce27de75b089cbe851 +- package: github.com/coreos/etcd + version: v3.3.10 +- package: github.com/fatih/camelcase + version: f6a740d52f961c60348ebb109adde9f4635d7540 +- package: github.com/docker/docker + version: docs-v1.12.0-rc4-2016-07-15-9510-ga9fbbdc8dd8794 +- package: gopkg.in/natefinch/lumberjack.v2 + version: v1.0-16-g20b71e5b60d756 +- package: gopkg.in/square/go-jose.v2 + version: v2.1.6-4-g89060dee6a84df +- package: github.com/coreos/pkg + version: v4 - package: github.com/sigma/go-inotify version: c87b6cf5033d2c6486046f045eeebdc3d910fd38 -- package: bitbucket.org/ww/goautoneg - version: a547fc61f48d567d5b4ec6f8aee5573d8efce11d - repo: https://github.com/rancher/goautoneg.git -- package: github.com/mitchellh/go-wordwrap - version: ad45545899c7b13c020ea92b2072220eefad42b8 -- package: k8s.io/utils - version: 66066c83e385e385ccc3c964b44fd7dcd413d0ed -- package: sigs.k8s.io/yaml - version: v1.1.0 -- package: github.com/inconshreveable/mousetrap - version: v1.0 -- package: github.com/cloudflare/cfssl - version: 1.3.2-21-g56268a613adfed +- package: github.com/cyphar/filepath-securejoin + version: v0.2.1-1-gae69057f2299fb - package: github.com/renstrom/dedent version: v1.0.0-3-g020d11c3b9c0c7 - package: k8s.io/heapster version: v1.2.0-beta.1 -- package: github.com/mistifyio/go-zfs - version: v2.1.1-5-g1b4ae6fb4e77b0 +- package: github.com/docker/go-units + version: v0.3.1-11-g9e638d38cf6977 +- package: github.com/ibuildthecloud/kvsql + version: c649f12fe5250718e4e024b8b40e7de796ab095e +- package: github.com/jonboulle/clockwork + version: 72f9bd7c4e0c2a40055ab3d0f09654f730cce982 +- package: k8s.io/klog + version: 8139d8cb77af419532b33dfa7dd09fbc5f1d344f +- package: github.com/daviddengcn/go-colortext + version: 511bcaf42ccd42c38aba7427b6673277bf19e2a1 +- package: k8s.io/utils + version: 66066c83e385e385ccc3c964b44fd7dcd413d0ed - package: github.com/pborman/uuid version: ca53cad383cad2479bbba7f7a1a05797ec1386e4 -- package: github.com/prometheus/common - version: 13ba4ddd0caa9c28ca7b7bffe1dfa9ed8d5ef207 -- package: gopkg.in/square/go-jose.v2 - version: v2.1.6-4-g89060dee6a84df -- package: github.com/container-storage-interface/spec - version: v1.0.0 -- package: github.com/fsnotify/fsnotify - version: v1.3.1-1-gf12c6236fe7b5c -- package: github.com/evanphx/json-patch - version: v4.1.0-19-g5858425f75500d -- package: github.com/peterbourgon/diskv - version: v2.0.1 -- package: github.com/ugorji/go - version: bdcc60b419d136a85cdf2e7cbcac34b3f1cd6e57 -- package: github.com/imdario/mergo - version: v0.3.5 -- package: github.com/karrick/godirwalk - version: v1.7.5 -- package: github.com/mindprince/gonvml - version: fee913ce8fb235edf54739d259ca0ecc226c7b8a -- package: github.com/vishvananda/netns - version: be1fbeda19366dea804f00efff2dd73a1642fdcc -- package: k8s.io/gengo - version: 51747d6e00da1fc578d5a333a93bb2abcbce7a95 -- package: github.com/Nvveen/Gotty - version: cd527374f1e5bff4938207604a14f2e38a9cf512 -- package: github.com/mattn/go-shellwords - version: v1.0.3-20-gf8471b0a71ded0 -- package: github.com/jteeuwen/go-bindata - version: v3.0.7-72-ga0ff2567cfb709 diff --git a/vendor.conf b/vendor.conf index 83441795ca..13f1d4045c 100644 --- a/vendor.conf +++ b/vendor.conf @@ -11,7 +11,7 @@ package=github.com/opencontainers/runc/contrib/cmd/recvtty k8s.io/kubernetes v1.13.4-k3s.1 https://github.com/rancher/k3s.git transitive=true,staging=true -github.com/rancher/norman 816007443daf04e96c7806c2a637dfab8ede9429 https://github.com/ibuildthecloud/norman.git +github.com/rancher/norman f75e3607e96e1a5d3cbaf4ee7cea1459cc727f61 https://github.com/ibuildthecloud/norman.git github.com/coreos/flannel 823afe66b2266bf71f5bec24e6e28b26d70cfc7c https://github.com/ibuildthecloud/flannel.git github.com/natefinch/lumberjack aee4629129445bbdfb69aa565537dcfa16544311 github.com/gorilla/mux v1.6.2 diff --git a/vendor/github.com/rancher/norman/build.go b/vendor/github.com/rancher/norman/build.go index 34a555a10c..c169405727 100644 --- a/vendor/github.com/rancher/norman/build.go +++ b/vendor/github.com/rancher/norman/build.go @@ -82,10 +82,6 @@ func (c *Config) Build(ctx context.Context, opts *Options) (context.Context, *Se return ctx, nil, err } - if !opts.DisableControllers { - go c.masterControllers(ctx, starters, r) - } - if c.EnableAPI { if err := c.apiServer(ctx, r); err != nil { return ctx, nil, err @@ -100,6 +96,7 @@ func (c *Config) Build(ctx context.Context, opts *Options) (context.Context, *Se if !opts.DisableControllers { err = controller.SyncThenStart(ctx, c.Threadiness, starters...) + go c.masterControllers(ctx, starters, r) } return ctx, server, err diff --git a/vendor/github.com/rancher/norman/objectclient/object_client.go b/vendor/github.com/rancher/norman/objectclient/object_client.go index 01d1b930d3..6b4fcf5d9b 100644 --- a/vendor/github.com/rancher/norman/objectclient/object_client.go +++ b/vendor/github.com/rancher/norman/objectclient/object_client.go @@ -293,6 +293,7 @@ func (p *ObjectClient) Patch(name string, o runtime.Object, patchType types.Patc if len(name) == 0 { return result, errors.New("object missing name") } + logrus.Debugf("REST PATCH %s/%s/%s/%s/%s", p.getAPIPrefix(), p.gvk.Group, p.gvk.Version, p.ns, name) err := p.restClient.Patch(patchType). Prefix(p.getAPIPrefix(), p.gvk.Group, p.gvk.Version). NamespaceIfScoped(ns, p.resource.Namespaced). diff --git a/vendor/github.com/rancher/norman/pkg/objectset/desiredset.go b/vendor/github.com/rancher/norman/pkg/objectset/desiredset.go index 492d6e9b6f..536fec67c7 100644 --- a/vendor/github.com/rancher/norman/pkg/objectset/desiredset.go +++ b/vendor/github.com/rancher/norman/pkg/objectset/desiredset.go @@ -12,6 +12,7 @@ import ( type DesiredSet struct { discoveredClients map[schema.GroupVersionKind]*objectclient.ObjectClient + namespaced map[schema.GroupVersionKind]bool discovery discovery.DiscoveryInterface restConfig rest.Config remove bool @@ -25,11 +26,15 @@ type DesiredSet struct { errs []error } -func (o *DesiredSet) AddDiscoveredClient(gvk schema.GroupVersionKind, client *objectclient.ObjectClient) { +func (o *DesiredSet) AddDiscoveredClient(gvk schema.GroupVersionKind, client *objectclient.ObjectClient, namespaced bool) { if o.discoveredClients == nil { o.discoveredClients = map[schema.GroupVersionKind]*objectclient.ObjectClient{} } o.discoveredClients[gvk] = client + if o.namespaced == nil { + o.namespaced = map[schema.GroupVersionKind]bool{} + } + o.namespaced[gvk] = namespaced } func (o *DesiredSet) DiscoveredClients() map[schema.GroupVersionKind]*objectclient.ObjectClient { diff --git a/vendor/github.com/rancher/norman/pkg/objectset/desiredset_process.go b/vendor/github.com/rancher/norman/pkg/objectset/desiredset_process.go index 74d8d64cf6..4ab43fb4a6 100644 --- a/vendor/github.com/rancher/norman/pkg/objectset/desiredset_process.go +++ b/vendor/github.com/rancher/norman/pkg/objectset/desiredset_process.go @@ -25,17 +25,18 @@ import ( ) var ( - deletePolicy = v1.DeletePropagationBackground - ErrReplace = errors.New("replace object with changes") - ReplaceOnChange = func(name string, o runtime.Object, patchType types2.PatchType, data []byte, subresources ...string) (runtime.Object, error) { + defaultNamespace = "default" + deletePolicy = v1.DeletePropagationBackground + ErrReplace = errors.New("replace object with changes") + ReplaceOnChange = func(name string, o runtime.Object, patchType types2.PatchType, data []byte, subresources ...string) (runtime.Object, error) { return nil, ErrReplace } ) -func NewDiscoveredClient(gvk schema.GroupVersionKind, restConfig rest.Config, discovery discovery.DiscoveryInterface) (*objectclient.ObjectClient, error) { +func NewDiscoveredClient(gvk schema.GroupVersionKind, restConfig rest.Config, discovery discovery.DiscoveryInterface) (*objectclient.ObjectClient, bool, error) { resources, err := discovery.ServerResourcesForGroupVersion(gvk.GroupVersion().String()) if err != nil { - return nil, err + return nil, false, err } for _, resource := range resources.APIResources { @@ -49,14 +50,14 @@ func NewDiscoveredClient(gvk schema.GroupVersionKind, restConfig rest.Config, di restClient, err := restwatch.UnversionedRESTClientFor(&restConfig) if err != nil { - return nil, err + return nil, false, err } objectClient := objectclient.NewObjectClient("", restClient, &resource, gvk, &objectclient.UnstructuredObjectFactory{}) - return objectClient, nil + return objectClient, resource.Namespaced, nil } - return nil, fmt.Errorf("failed to discover client for %s", gvk) + return nil, false, fmt.Errorf("failed to discover client for %s", gvk) } func (o *DesiredSet) getControllerAndObjectClient(debugID string, gvk schema.GroupVersionKind) (controller.GenericController, *objectclient.ObjectClient, error) { @@ -74,15 +75,42 @@ func (o *DesiredSet) getControllerAndObjectClient(debugID string, gvk schema.Gro return nil, objectClient, nil } - objectClient, err := NewDiscoveredClient(gvk, o.restConfig, o.discovery) + objectClient, namespaced, err := NewDiscoveredClient(gvk, o.restConfig, o.discovery) if err != nil { return nil, nil, errors.Wrapf(err, "failed to find client for %s for %s", gvk, debugID) } - o.AddDiscoveredClient(gvk, objectClient) + o.AddDiscoveredClient(gvk, objectClient, namespaced) return nil, objectClient, nil } +func (o *DesiredSet) adjustNamespace(gvk schema.GroupVersionKind, objs map[objectKey]runtime.Object) error { + namespaced, ok := o.namespaced[gvk] + if !ok || !namespaced { + return nil + } + + for k, v := range objs { + if k.namespace != "" { + continue + } + + v = v.DeepCopyObject() + meta, err := meta.Accessor(v) + if err != nil { + return err + } + + meta.SetNamespace(defaultNamespace) + + delete(objs, k) + k.namespace = defaultNamespace + objs[k] = v + } + + return nil +} + func (o *DesiredSet) process(inputID, debugID string, set labels.Selector, gvk schema.GroupVersionKind, objs map[objectKey]runtime.Object) { controller, objectClient, err := o.getControllerAndObjectClient(debugID, gvk) if err != nil { @@ -90,6 +118,11 @@ func (o *DesiredSet) process(inputID, debugID string, set labels.Selector, gvk s return } + if err := o.adjustNamespace(gvk, objs); err != nil { + o.err(err) + return + } + patcher, ok := o.patchers[gvk] if !ok { patcher = objectClient.Patch @@ -224,7 +257,8 @@ func list(controller controller.GenericController, objectClient *objectclient.Ob } for _, obj := range list.Items { - if err := addObjectToMap(objs, &obj); err != nil { + copy := obj + if err := addObjectToMap(objs, ©); err != nil { errs = append(errs, err) } }