diff --git a/app/daemon.go b/app/daemon.go index b7d7a1be09..beadbe9762 100644 --- a/app/daemon.go +++ b/app/daemon.go @@ -9,7 +9,7 @@ import ( "github.com/gorilla/handlers" "github.com/pkg/errors" - "github.com/rancher/wrangler/pkg/signals" + "github.com/rancher/wrangler/v3/pkg/signals" "github.com/sirupsen/logrus" "github.com/urfave/cli" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/controller/base_controller.go b/controller/base_controller.go index a36e24be21..402a9e5a50 100644 --- a/controller/base_controller.go +++ b/controller/base_controller.go @@ -18,16 +18,17 @@ var ( type baseController struct { name string logger *logrus.Entry - queue workqueue.RateLimitingInterface + queue workqueue.TypedRateLimitingInterface[any] } func newBaseController(name string, logger logrus.FieldLogger) *baseController { + nameConfig := workqueue.TypedRateLimitingQueueConfig[any]{Name: name} return newBaseControllerWithQueue(name, logger, - workqueue.NewNamedRateLimitingQueue(EnhancedDefaultControllerRateLimiter(), name)) + workqueue.NewTypedRateLimitingQueueWithConfig[any](EnhancedDefaultControllerRateLimiter(), nameConfig)) } func newBaseControllerWithQueue(name string, logger logrus.FieldLogger, - queue workqueue.RateLimitingInterface) *baseController { + queue workqueue.TypedRateLimitingInterface[any]) *baseController { c := &baseController{ name: name, logger: logger.WithField("controller", name), diff --git a/controller/controller_manager.go b/controller/controller_manager.go index ac5987fcd9..984e041b81 100644 --- a/controller/controller_manager.go +++ b/controller/controller_manager.go @@ -310,11 +310,11 @@ func isControllerResponsibleFor(controllerID string, ds *datastore.DataStore, na // EnhancedDefaultControllerRateLimiter is an enhanced version of workqueue.DefaultControllerRateLimiter() // See https://github.com/longhorn/longhorn/issues/1058 for details -func EnhancedDefaultControllerRateLimiter() workqueue.RateLimiter { - return workqueue.NewMaxOfRateLimiter( - workqueue.NewItemExponentialFailureRateLimiter(5*time.Millisecond, 1000*time.Second), +func EnhancedDefaultControllerRateLimiter() workqueue.TypedRateLimiter[any] { + return workqueue.NewTypedMaxOfRateLimiter[any]( + workqueue.NewTypedItemExponentialFailureRateLimiter[any](5*time.Millisecond, 1000*time.Second), // 100 qps, 1000 bucket size - &workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(100), 1000)}, + &workqueue.TypedBucketRateLimiter[any]{Limiter: rate.NewLimiter(rate.Limit(100), 1000)}, ) } diff --git a/controller/monitor/snapshot_monitor.go b/controller/monitor/snapshot_monitor.go index a65cf85fb6..883734ff2e 100644 --- a/controller/monitor/snapshot_monitor.go +++ b/controller/monitor/snapshot_monitor.go @@ -70,8 +70,8 @@ type SnapshotMonitor struct { checkScheduler *gocron.Scheduler - snapshotChangeEventQueue workqueue.Interface - snapshotCheckTaskQueue workqueue.RateLimitingInterface + snapshotChangeEventQueue workqueue.TypedInterface[any] + snapshotCheckTaskQueue workqueue.TypedRateLimitingInterface[any] inProgressSnapshotCheckTasks map[string]struct{} inProgressSnapshotCheckTasksLock sync.RWMutex @@ -86,7 +86,7 @@ type SnapshotMonitor struct { } func NewSnapshotMonitor(logger logrus.FieldLogger, ds *datastore.DataStore, nodeName string, eventRecorder record.EventRecorder, - snapshotChangeEventQueue workqueue.Interface, syncCallback func(key string)) (*SnapshotMonitor, error) { + snapshotChangeEventQueue workqueue.TypedInterface[any], syncCallback func(key string)) (*SnapshotMonitor, error) { ctx, quit := context.WithCancel(context.Background()) @@ -101,9 +101,9 @@ func NewSnapshotMonitor(logger logrus.FieldLogger, ds *datastore.DataStore, node snapshotChangeEventQueue: snapshotChangeEventQueue, - snapshotCheckTaskQueue: workqueue.NewRateLimitingQueue(workqueue.NewMaxOfRateLimiter( - workqueue.NewItemExponentialFailureRateLimiter(1*time.Second, 1000*time.Second), - &workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)}, + snapshotCheckTaskQueue: workqueue.NewTypedRateLimitingQueue[any](workqueue.NewTypedMaxOfRateLimiter[any]( + workqueue.NewTypedItemExponentialFailureRateLimiter[any](1*time.Second, 1000*time.Second), + &workqueue.TypedBucketRateLimiter[any]{Limiter: rate.NewLimiter(rate.Limit(10), 100)}, )), inProgressSnapshotCheckTasks: map[string]struct{}{}, diff --git a/controller/node_controller.go b/controller/node_controller.go index 45793e4a14..2482c28de0 100644 --- a/controller/node_controller.go +++ b/controller/node_controller.go @@ -63,7 +63,7 @@ type NodeController struct { diskMonitor monitor.Monitor snapshotMonitor monitor.Monitor - snapshotChangeEventQueue workqueue.Interface + snapshotChangeEventQueue workqueue.TypedInterface[any] snapshotChangeEventQueueLock sync.Mutex ds *datastore.DataStore @@ -102,7 +102,7 @@ func NewNodeController( topologyLabelsChecker: util.IsKubernetesVersionAtLeast, - snapshotChangeEventQueue: workqueue.New(), + snapshotChangeEventQueue: workqueue.NewTyped[any](), } nc.scheduler = scheduler.NewReplicaScheduler(ds) diff --git a/controller/system_rollout_controller.go b/controller/system_rollout_controller.go index 3d293e9452..47f99728bf 100644 --- a/controller/system_rollout_controller.go +++ b/controller/system_rollout_controller.go @@ -169,12 +169,13 @@ func NewSystemRolloutController( Interface: v1core.New(kubeClient.CoreV1().RESTClient()).Events(""), }) + nameConfig := workqueue.TypedRateLimitingQueueConfig[any]{Name: SystemRolloutControllerName} c := &SystemRolloutController{ baseController: newBaseControllerWithQueue(SystemRolloutControllerName, logger, - workqueue.NewNamedRateLimitingQueue(workqueue.NewMaxOfRateLimiter( - workqueue.NewItemExponentialFailureRateLimiter(100*time.Millisecond, 2*time.Second), - &workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(100), 1000)}, - ), SystemRolloutControllerName), + workqueue.NewTypedRateLimitingQueueWithConfig[any](workqueue.NewTypedMaxOfRateLimiter[any]( + workqueue.NewTypedItemExponentialFailureRateLimiter[any](100*time.Millisecond, 2*time.Second), + &workqueue.TypedBucketRateLimiter[any]{Limiter: rate.NewLimiter(rate.Limit(100), 1000)}, + ), nameConfig), ), controllerID: controllerID, stopCh: stopCh, diff --git a/controller/uninstall_controller.go b/controller/uninstall_controller.go index 40ae3c79b5..2b7251367c 100644 --- a/controller/uninstall_controller.go +++ b/controller/uninstall_controller.go @@ -75,12 +75,13 @@ func NewUninstallController( kubeClient clientset.Interface, extensionsClient apiextensionsclientset.Interface, ) (*UninstallController, error) { + nameConfig := workqueue.TypedRateLimitingQueueConfig[any]{Name: "longhorn-uninstall"} c := &UninstallController{ baseController: newBaseControllerWithQueue("longhorn-uninstall", logger, - workqueue.NewNamedRateLimitingQueue(workqueue.NewMaxOfRateLimiter( - workqueue.NewItemExponentialFailureRateLimiter(100*time.Millisecond, 2*time.Second), - &workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(100), 1000)}, - ), "longhorn-uninstall"), + workqueue.NewTypedRateLimitingQueueWithConfig[any](workqueue.NewTypedMaxOfRateLimiter[any]( + workqueue.NewTypedItemExponentialFailureRateLimiter[any](100*time.Millisecond, 2*time.Second), + &workqueue.TypedBucketRateLimiter[any]{Limiter: rate.NewLimiter(rate.Limit(100), 1000)}, + ), nameConfig), ), namespace: namespace, force: force, diff --git a/csi/controller_server.go b/csi/controller_server.go index bad0d9bc64..a383d0be75 100644 --- a/csi/controller_server.go +++ b/csi/controller_server.go @@ -46,6 +46,7 @@ const ( ) type ControllerServer struct { + csi.UnimplementedControllerServer apiClient *longhornclient.RancherClient nodeID string caps []*csi.ControllerServiceCapability @@ -1380,7 +1381,7 @@ func (cs *ControllerServer) waitForSnapshotToBeReady(snapshotName, volumeName st func (cs *ControllerServer) ControllerModifyVolume(ctx context.Context, req *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error) { log := cs.log.WithFields(logrus.Fields{"function": "ControllerModifyVolume"}) - log.Infof("ControllerModifyVolume: called with args %+v", *req) + log.Infof("ControllerModifyVolume: called with args %v", req) return nil, status.Error(codes.Unimplemented, "") } diff --git a/csi/identity_server.go b/csi/identity_server.go index f3f4b03f59..d1f74b5a17 100644 --- a/csi/identity_server.go +++ b/csi/identity_server.go @@ -7,6 +7,7 @@ import ( ) type IdentityServer struct { + csi.UnimplementedIdentityServer driverName string version string } diff --git a/csi/node_server.go b/csi/node_server.go index e7f6952c99..cd49366c3d 100644 --- a/csi/node_server.go +++ b/csi/node_server.go @@ -48,6 +48,7 @@ var supportedFs = map[string]fsParameters{ } type NodeServer struct { + csi.UnimplementedNodeServer apiClient *longhornclient.RancherClient nodeID string caps []*csi.NodeServiceCapability diff --git a/go.mod b/go.mod index d02b9ddbb7..953df0261a 100644 --- a/go.mod +++ b/go.mod @@ -72,7 +72,7 @@ require ( github.com/prometheus/client_golang v1.20.2 github.com/rancher/dynamiclistener v0.6.0 github.com/rancher/go-rancher v0.1.1-0.20220412083059-ff12399dd57b - github.com/rancher/wrangler v1.1.2 + github.com/rancher/wrangler/v3 v3.0.0 github.com/robfig/cron v1.2.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 @@ -114,7 +114,6 @@ require ( github.com/opencontainers/runc v1.1.13 // indirect github.com/opencontainers/runtime-spec v1.1.0 // indirect github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect - github.com/rancher/wrangler/v3 v3.0.0 // indirect github.com/shirou/gopsutil/v3 v3.24.5 // indirect github.com/x448/float16 v0.8.4 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect diff --git a/go.sum b/go.sum index a5365b275e..ab096b12e6 100644 --- a/go.sum +++ b/go.sum @@ -233,8 +233,6 @@ github.com/rancher/go-rancher v0.1.1-0.20220412083059-ff12399dd57b h1:so40GMVZOZ github.com/rancher/go-rancher v0.1.1-0.20220412083059-ff12399dd57b/go.mod h1:7oQvGNiJsGvrUgB+7AH8bmdzuR0uhULfwKb43Ht0hUk= github.com/rancher/lasso v0.0.0-20240809125800-8da6f11865d5 h1:qlVhaHTT7wwrI5+AGdkYHpveuoe8Ot4TdQr7LtxmVSk= github.com/rancher/lasso v0.0.0-20240809125800-8da6f11865d5/go.mod h1:Efx/+BbH3ivmnTPLu5cA3Gc9wT5oyGS0LBcqEuYTx+A= -github.com/rancher/wrangler v1.1.2 h1:oXbXo9k7y/H4drUpb4RM1c++vT9O3rpoNEfyusGykiU= -github.com/rancher/wrangler v1.1.2/go.mod h1:2k9MyhlBdjcutcBGoOJSUAz0HgDAXnMjv81d3n/AaQc= github.com/rancher/wrangler/v3 v3.0.0 h1:IHHCA+vrghJDPxjtLk4fmeSCFhNe9fFzLFj3m2B0YpA= github.com/rancher/wrangler/v3 v3.0.0/go.mod h1:Dfckuuq7MJk2JWVBDywRlZXMxEyPxHy4XqGrPEzu5Eg= github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ= diff --git a/util/client/client.go b/util/client/client.go index c5b304b731..8f41b5d4db 100644 --- a/util/client/client.go +++ b/util/client/client.go @@ -6,8 +6,8 @@ import ( "time" "github.com/pkg/errors" - wranglerClients "github.com/rancher/wrangler/pkg/clients" - wranglerSchemes "github.com/rancher/wrangler/pkg/schemes" + wranglerClients "github.com/rancher/wrangler/v3/pkg/clients" + wranglerSchemes "github.com/rancher/wrangler/v3/pkg/schemes" "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/runtime" "k8s.io/client-go/tools/clientcmd" diff --git a/vendor/github.com/rancher/wrangler/LICENSE b/vendor/github.com/rancher/wrangler/LICENSE deleted file mode 100644 index e454a52586..0000000000 --- a/vendor/github.com/rancher/wrangler/LICENSE +++ /dev/null @@ -1,178 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/apply.go b/vendor/github.com/rancher/wrangler/pkg/apply/apply.go deleted file mode 100644 index 094ca1bb93..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/apply/apply.go +++ /dev/null @@ -1,309 +0,0 @@ -package apply - -import ( - "context" - "fmt" - "sync" - - "github.com/rancher/wrangler/pkg/apply/injectors" - "github.com/rancher/wrangler/pkg/objectset" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/client-go/discovery" - "k8s.io/client-go/dynamic" - "k8s.io/client-go/rest" - "k8s.io/client-go/tools/cache" -) - -const ( - defaultNamespace = "default" -) - -type Patcher func(namespace, name string, pt types.PatchType, data []byte) (runtime.Object, error) - -// Reconciler return false if it did not handle this object -type Reconciler func(oldObj runtime.Object, newObj runtime.Object) (bool, error) - -type ClientFactory func(gvr schema.GroupVersionResource) (dynamic.NamespaceableResourceInterface, error) - -type InformerFactory interface { - Get(gvk schema.GroupVersionKind, gvr schema.GroupVersionResource) (cache.SharedIndexInformer, error) -} - -type InformerGetter interface { - Informer() cache.SharedIndexInformer - GroupVersionKind() schema.GroupVersionKind -} - -type PatchByGVK map[schema.GroupVersionKind]map[objectset.ObjectKey]string - -func (p PatchByGVK) Add(gvk schema.GroupVersionKind, namespace, name, patch string) { - d, ok := p[gvk] - if !ok { - d = map[objectset.ObjectKey]string{} - p[gvk] = d - } - d[objectset.ObjectKey{ - Name: name, - Namespace: namespace, - }] = patch -} - -type Plan struct { - Create objectset.ObjectKeyByGVK - Delete objectset.ObjectKeyByGVK - Update PatchByGVK - Objects []runtime.Object -} - -type Apply interface { - Apply(set *objectset.ObjectSet) error - ApplyObjects(objs ...runtime.Object) error - WithContext(ctx context.Context) Apply - WithCacheTypes(igs ...InformerGetter) Apply - WithCacheTypeFactory(factory InformerFactory) Apply - WithSetID(id string) Apply - WithOwner(obj runtime.Object) Apply - WithOwnerKey(key string, gvk schema.GroupVersionKind) Apply - WithInjector(injs ...injectors.ConfigInjector) Apply - WithInjectorName(injs ...string) Apply - WithPatcher(gvk schema.GroupVersionKind, patchers Patcher) Apply - WithReconciler(gvk schema.GroupVersionKind, reconciler Reconciler) Apply - WithStrictCaching() Apply - WithDynamicLookup() Apply - WithRestrictClusterScoped() Apply - WithDefaultNamespace(ns string) Apply - WithListerNamespace(ns string) Apply - WithRateLimiting(ratelimitingQps float32) Apply - WithNoDelete() Apply - WithNoDeleteGVK(gvks ...schema.GroupVersionKind) Apply - WithGVK(gvks ...schema.GroupVersionKind) Apply - WithSetOwnerReference(controller, block bool) Apply - WithIgnorePreviousApplied() Apply - WithDiffPatch(gvk schema.GroupVersionKind, namespace, name string, patch []byte) Apply - - FindOwner(obj runtime.Object) (runtime.Object, error) - PurgeOrphan(obj runtime.Object) error - DryRun(objs ...runtime.Object) (Plan, error) -} - -func NewForConfig(cfg *rest.Config) (Apply, error) { - discovery, err := discovery.NewDiscoveryClientForConfig(cfg) - if err != nil { - return nil, err - } - - return New(discovery, NewClientFactory(cfg)), nil -} - -func New(discovery discovery.DiscoveryInterface, cf ClientFactory, igs ...InformerGetter) Apply { - a := &apply{ - clients: &clients{ - clientFactory: cf, - discovery: discovery, - namespaced: map[schema.GroupVersionKind]bool{}, - gvkToGVR: map[schema.GroupVersionKind]schema.GroupVersionResource{}, - clients: map[schema.GroupVersionKind]dynamic.NamespaceableResourceInterface{}, - }, - informers: map[schema.GroupVersionKind]cache.SharedIndexInformer{}, - } - - for _, ig := range igs { - a.informers[ig.GroupVersionKind()] = ig.Informer() - } - - return a -} - -type apply struct { - clients *clients - informers map[schema.GroupVersionKind]cache.SharedIndexInformer -} - -type clients struct { - sync.Mutex - - clientFactory ClientFactory - discovery discovery.DiscoveryInterface - namespaced map[schema.GroupVersionKind]bool - gvkToGVR map[schema.GroupVersionKind]schema.GroupVersionResource - clients map[schema.GroupVersionKind]dynamic.NamespaceableResourceInterface -} - -func (c *clients) IsNamespaced(gvk schema.GroupVersionKind) (bool, error) { - c.Lock() - ok, exists := c.namespaced[gvk] - c.Unlock() - - if exists { - return ok, nil - } - _, err := c.client(gvk) - if err != nil { - return false, err - } - - c.Lock() - defer c.Unlock() - return c.namespaced[gvk], nil -} - -func (c *clients) gvr(gvk schema.GroupVersionKind) schema.GroupVersionResource { - c.Lock() - defer c.Unlock() - return c.gvkToGVR[gvk] -} - -func (c *clients) client(gvk schema.GroupVersionKind) (dynamic.NamespaceableResourceInterface, error) { - c.Lock() - defer c.Unlock() - - if client, ok := c.clients[gvk]; ok { - return client, nil - } - - resources, err := c.discovery.ServerResourcesForGroupVersion(gvk.GroupVersion().String()) - if err != nil { - return nil, err - } - - for _, resource := range resources.APIResources { - if resource.Kind != gvk.Kind { - continue - } - - client, err := c.clientFactory(gvk.GroupVersion().WithResource(resource.Name)) - if err != nil { - return nil, err - } - - c.namespaced[gvk] = resource.Namespaced - c.clients[gvk] = client - c.gvkToGVR[gvk] = gvk.GroupVersion().WithResource(resource.Name) - return client, nil - } - - return nil, fmt.Errorf("failed to discover client for %s", gvk) -} - -func (a *apply) newDesiredSet() desiredSet { - return desiredSet{ - a: a, - defaultNamespace: defaultNamespace, - ctx: context.Background(), - ratelimitingQps: 1, - reconcilers: defaultReconcilers, - strictCaching: true, - } -} - -func (a *apply) DryRun(objs ...runtime.Object) (Plan, error) { - return a.newDesiredSet().DryRun(objs...) -} - -func (a *apply) Apply(set *objectset.ObjectSet) error { - return a.newDesiredSet().Apply(set) -} - -func (a *apply) ApplyObjects(objs ...runtime.Object) error { - os := objectset.NewObjectSet() - os.Add(objs...) - return a.newDesiredSet().Apply(os) -} - -func (a *apply) WithSetID(id string) Apply { - return a.newDesiredSet().WithSetID(id) -} - -func (a *apply) WithOwner(obj runtime.Object) Apply { - return a.newDesiredSet().WithOwner(obj) -} - -func (a *apply) WithOwnerKey(key string, gvk schema.GroupVersionKind) Apply { - return a.newDesiredSet().WithOwnerKey(key, gvk) -} - -func (a *apply) WithInjector(injs ...injectors.ConfigInjector) Apply { - return a.newDesiredSet().WithInjector(injs...) -} - -func (a *apply) WithInjectorName(injs ...string) Apply { - return a.newDesiredSet().WithInjectorName(injs...) -} - -func (a *apply) WithCacheTypes(igs ...InformerGetter) Apply { - return a.newDesiredSet().WithCacheTypes(igs...) -} - -func (a *apply) WithCacheTypeFactory(factory InformerFactory) Apply { - return a.newDesiredSet().WithCacheTypeFactory(factory) -} - -func (a *apply) WithGVK(gvks ...schema.GroupVersionKind) Apply { - return a.newDesiredSet().WithGVK(gvks...) -} - -func (a *apply) WithPatcher(gvk schema.GroupVersionKind, patcher Patcher) Apply { - return a.newDesiredSet().WithPatcher(gvk, patcher) -} - -func (a *apply) WithReconciler(gvk schema.GroupVersionKind, reconciler Reconciler) Apply { - return a.newDesiredSet().WithReconciler(gvk, reconciler) -} - -func (a *apply) WithStrictCaching() Apply { - return a.newDesiredSet().WithStrictCaching() -} - -func (a *apply) WithDynamicLookup() Apply { - return a.newDesiredSet().WithDynamicLookup() -} - -func (a *apply) WithRestrictClusterScoped() Apply { - return a.newDesiredSet().WithRestrictClusterScoped() -} - -func (a *apply) WithDefaultNamespace(ns string) Apply { - return a.newDesiredSet().WithDefaultNamespace(ns) -} - -func (a *apply) WithListerNamespace(ns string) Apply { - return a.newDesiredSet().WithListerNamespace(ns) -} - -func (a *apply) WithRateLimiting(ratelimitingQps float32) Apply { - return a.newDesiredSet().WithRateLimiting(ratelimitingQps) -} - -func (a *apply) WithNoDelete() Apply { - return a.newDesiredSet().WithNoDelete() -} - -func (a *apply) WithNoDeleteGVK(gvks ...schema.GroupVersionKind) Apply { - return a.newDesiredSet().WithNoDeleteGVK(gvks...) -} - -func (a *apply) WithSetOwnerReference(controller, block bool) Apply { - return a.newDesiredSet().WithSetOwnerReference(controller, block) -} - -func (a *apply) WithContext(ctx context.Context) Apply { - return a.newDesiredSet().WithContext(ctx) -} - -func (a *apply) WithIgnorePreviousApplied() Apply { - return a.newDesiredSet().WithIgnorePreviousApplied() -} - -func (a *apply) FindOwner(obj runtime.Object) (runtime.Object, error) { - return a.newDesiredSet().FindOwner(obj) -} - -func (a *apply) PurgeOrphan(obj runtime.Object) error { - return a.newDesiredSet().PurgeOrphan(obj) -} - -func (a *apply) WithDiffPatch(gvk schema.GroupVersionKind, namespace, name string, patch []byte) Apply { - return a.newDesiredSet().WithDiffPatch(gvk, namespace, name, patch) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/client_factory.go b/vendor/github.com/rancher/wrangler/pkg/apply/client_factory.go deleted file mode 100644 index 0bde5b7887..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/apply/client_factory.go +++ /dev/null @@ -1,18 +0,0 @@ -package apply - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/dynamic" - "k8s.io/client-go/rest" -) - -func NewClientFactory(config *rest.Config) ClientFactory { - return func(gvr schema.GroupVersionResource) (dynamic.NamespaceableResourceInterface, error) { - client, err := dynamic.NewForConfig(config) - if err != nil { - return nil, err - } - - return client.Resource(gvr), nil - } -} diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset.go b/vendor/github.com/rancher/wrangler/pkg/apply/desiredset.go deleted file mode 100644 index cb192d59a8..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset.go +++ /dev/null @@ -1,275 +0,0 @@ -package apply - -import ( - "context" - "errors" - "fmt" - - "github.com/rancher/wrangler/pkg/apply/injectors" - "github.com/rancher/wrangler/pkg/kv" - "github.com/rancher/wrangler/pkg/merr" - "github.com/rancher/wrangler/pkg/objectset" - "github.com/sirupsen/logrus" - "k8s.io/apimachinery/pkg/api/meta" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/tools/cache" -) - -// Indexer name added for cached types -const byHash = "wrangler.byObjectSetHash" - -type patchKey struct { - schema.GroupVersionKind - objectset.ObjectKey -} - -type desiredSet struct { - a *apply - ctx context.Context - defaultNamespace string - listerNamespace string - ignorePreviousApplied bool - setOwnerReference bool - ownerReferenceController bool - ownerReferenceBlock bool - strictCaching bool - restrictClusterScoped bool - pruneTypes map[schema.GroupVersionKind]cache.SharedIndexInformer - patchers map[schema.GroupVersionKind]Patcher - reconcilers map[schema.GroupVersionKind]Reconciler - diffPatches map[patchKey][][]byte - informerFactory InformerFactory - remove bool - noDelete bool - noDeleteGVK map[schema.GroupVersionKind]struct{} - setID string - objs *objectset.ObjectSet - owner runtime.Object - injectors []injectors.ConfigInjector - ratelimitingQps float32 - injectorNames []string - errs []error - - createPlan bool - plan Plan -} - -func (o *desiredSet) err(err error) error { - o.errs = append(o.errs, err) - return o.Err() -} - -func (o desiredSet) Err() error { - return merr.NewErrors(append(o.errs, o.objs.Err())...) -} - -func (o desiredSet) DryRun(objs ...runtime.Object) (Plan, error) { - o.objs = objectset.NewObjectSet() - o.objs.Add(objs...) - return o.dryRun() -} - -func (o desiredSet) Apply(set *objectset.ObjectSet) error { - if set == nil { - set = objectset.NewObjectSet() - } - o.objs = set - return o.apply() -} - -func (o desiredSet) ApplyObjects(objs ...runtime.Object) error { - os := objectset.NewObjectSet() - os.Add(objs...) - return o.Apply(os) -} - -func (o desiredSet) WithDiffPatch(gvk schema.GroupVersionKind, namespace, name string, patch []byte) Apply { - patches := map[patchKey][][]byte{} - for k, v := range o.diffPatches { - patches[k] = v - } - key := patchKey{ - GroupVersionKind: gvk, - ObjectKey: objectset.ObjectKey{ - Name: name, - Namespace: namespace, - }, - } - patches[key] = append(patches[key], patch) - o.diffPatches = patches - return o -} - -// WithGVK uses a known listing of existing gvks to modify the the prune types to allow for deletion of objects -func (o desiredSet) WithGVK(gvks ...schema.GroupVersionKind) Apply { - pruneTypes := make(map[schema.GroupVersionKind]cache.SharedIndexInformer, len(gvks)) - for k, v := range o.pruneTypes { - pruneTypes[k] = v - } - for _, gvk := range gvks { - pruneTypes[gvk] = nil - } - o.pruneTypes = pruneTypes - return o -} - -func (o desiredSet) WithSetID(id string) Apply { - o.setID = id - return o -} - -func (o desiredSet) WithOwnerKey(key string, gvk schema.GroupVersionKind) Apply { - obj := &v1.PartialObjectMetadata{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(gvk) - o.owner = obj - return o -} - -func (o desiredSet) WithOwner(obj runtime.Object) Apply { - o.owner = obj - return o -} - -func (o desiredSet) WithSetOwnerReference(controller, block bool) Apply { - o.setOwnerReference = true - o.ownerReferenceController = controller - o.ownerReferenceBlock = block - return o -} - -func (o desiredSet) WithInjector(injs ...injectors.ConfigInjector) Apply { - o.injectors = append(o.injectors, injs...) - return o -} - -func (o desiredSet) WithInjectorName(injs ...string) Apply { - o.injectorNames = append(o.injectorNames, injs...) - return o -} - -func (o desiredSet) WithCacheTypeFactory(factory InformerFactory) Apply { - o.informerFactory = factory - return o -} - -func (o desiredSet) WithIgnorePreviousApplied() Apply { - o.ignorePreviousApplied = true - return o -} - -func (o desiredSet) WithCacheTypes(igs ...InformerGetter) Apply { - pruneTypes := make(map[schema.GroupVersionKind]cache.SharedIndexInformer, len(igs)) - for k, v := range o.pruneTypes { - pruneTypes[k] = v - } - - for _, ig := range igs { - informer := ig.Informer() - if err := addIndexerByHash(informer.GetIndexer()); err != nil { - // Ignore repeatedly adding the same indexer for different types - if !errors.Is(err, indexerAlreadyExistsErr) { - logrus.Warnf("Problem adding hash indexer to informer [%s]: %v", ig.GroupVersionKind().Kind, err) - } - } - pruneTypes[ig.GroupVersionKind()] = informer - } - - o.pruneTypes = pruneTypes - return o -} - -// addIndexerByHash an Informer to index objects by the hash annotation value -func addIndexerByHash(indexer cache.Indexer) error { - if _, alreadyAdded := indexer.GetIndexers()[byHash]; alreadyAdded { - return fmt.Errorf("adding indexer %q: %w", byHash, indexerAlreadyExistsErr) - } - return indexer.AddIndexers(map[string]cache.IndexFunc{ - byHash: func(obj interface{}) ([]string, error) { - metadata, err := meta.Accessor(obj) - if err != nil { - return nil, err - } - labels := metadata.GetLabels() - if labels == nil || labels[LabelHash] == "" { - return nil, nil - } - return []string{labels[LabelHash]}, nil - }, - }) -} - -func (o desiredSet) WithPatcher(gvk schema.GroupVersionKind, patcher Patcher) Apply { - patchers := map[schema.GroupVersionKind]Patcher{} - for k, v := range o.patchers { - patchers[k] = v - } - patchers[gvk] = patcher - o.patchers = patchers - return o -} - -func (o desiredSet) WithReconciler(gvk schema.GroupVersionKind, reconciler Reconciler) Apply { - reconcilers := map[schema.GroupVersionKind]Reconciler{} - for k, v := range o.reconcilers { - reconcilers[k] = v - } - reconcilers[gvk] = reconciler - o.reconcilers = reconcilers - return o -} - -func (o desiredSet) WithStrictCaching() Apply { - o.strictCaching = true - return o -} -func (o desiredSet) WithDynamicLookup() Apply { - o.strictCaching = false - return o -} - -func (o desiredSet) WithRestrictClusterScoped() Apply { - o.restrictClusterScoped = true - return o -} - -func (o desiredSet) WithDefaultNamespace(ns string) Apply { - if ns == "" { - o.defaultNamespace = defaultNamespace - } else { - o.defaultNamespace = ns - } - return o -} - -func (o desiredSet) WithListerNamespace(ns string) Apply { - o.listerNamespace = ns - return o -} - -func (o desiredSet) WithRateLimiting(ratelimitingQps float32) Apply { - o.ratelimitingQps = ratelimitingQps - return o -} - -func (o desiredSet) WithNoDelete() Apply { - o.noDelete = true - return o -} - -func (o desiredSet) WithNoDeleteGVK(gvks ...schema.GroupVersionKind) Apply { - if o.noDeleteGVK == nil { - o.noDeleteGVK = make(map[schema.GroupVersionKind]struct{}) - } - for _, curr := range gvks { - o.noDeleteGVK[curr] = struct{}{} - } - return o -} - -func (o desiredSet) WithContext(ctx context.Context) Apply { - o.ctx = ctx - return o -} diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_apply.go b/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_apply.go deleted file mode 100644 index cb68e4e8ea..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_apply.go +++ /dev/null @@ -1,281 +0,0 @@ -package apply - -import ( - "crypto/sha1" - "encoding/hex" - "fmt" - "sync" - "time" - - "github.com/sirupsen/logrus" - - gvk2 "github.com/rancher/wrangler/pkg/gvk" - - "github.com/pkg/errors" - "github.com/rancher/wrangler/pkg/apply/injectors" - "github.com/rancher/wrangler/pkg/objectset" - "k8s.io/apimachinery/pkg/api/meta" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/selection" - "k8s.io/client-go/util/flowcontrol" -) - -const ( - LabelID = "objectset.rio.cattle.io/id" - LabelGVK = "objectset.rio.cattle.io/owner-gvk" - LabelName = "objectset.rio.cattle.io/owner-name" - LabelNamespace = "objectset.rio.cattle.io/owner-namespace" - LabelHash = "objectset.rio.cattle.io/hash" - LabelPrefix = "objectset.rio.cattle.io/" - LabelPrune = "objectset.rio.cattle.io/prune" -) - -var ( - hashOrder = []string{ - LabelID, - LabelGVK, - LabelName, - LabelNamespace, - } - rls = map[string]flowcontrol.RateLimiter{} - rlsLock sync.Mutex - indexerAlreadyExistsErr = errors.New("an indexer with the same already exists") -) - -func (o *desiredSet) getRateLimit(labelHash string) flowcontrol.RateLimiter { - var rl flowcontrol.RateLimiter - - rlsLock.Lock() - defer rlsLock.Unlock() - if o.remove { - delete(rls, labelHash) - } else { - rl = rls[labelHash] - if rl == nil { - rl = flowcontrol.NewTokenBucketRateLimiter(o.ratelimitingQps, 10) - rls[labelHash] = rl - } - } - - return rl -} - -func (o *desiredSet) dryRun() (Plan, error) { - o.createPlan = true - o.plan.Create = objectset.ObjectKeyByGVK{} - o.plan.Update = PatchByGVK{} - o.plan.Delete = objectset.ObjectKeyByGVK{} - err := o.apply() - return o.plan, err -} - -func (o *desiredSet) apply() error { - if o.objs == nil || o.objs.Len() == 0 { - o.remove = true - } - - if err := o.Err(); err != nil { - return err - } - - labelSet, annotationSet, err := GetLabelsAndAnnotations(o.setID, o.owner) - if err != nil { - return o.err(err) - } - - rl := o.getRateLimit(labelSet[LabelHash]) - if rl != nil { - t := time.Now() - rl.Accept() - if d := time.Now().Sub(t); d.Seconds() > 1 { - logrus.Infof("rate limited %s(%s) %s", o.setID, labelSet, d) - } - } - - objList, err := o.injectLabelsAndAnnotations(labelSet, annotationSet) - if err != nil { - return o.err(err) - } - - objList, err = o.runInjectors(objList) - if err != nil { - return o.err(err) - } - - objs := o.collect(objList) - - debugID := o.debugID() - sel, err := GetSelector(labelSet) - if err != nil { - return o.err(err) - } - - for _, gvk := range o.objs.GVKOrder(o.knownGVK()...) { - o.process(debugID, sel, gvk, objs[gvk]) - } - - return o.Err() -} - -func (o *desiredSet) knownGVK() (ret []schema.GroupVersionKind) { - for k := range o.pruneTypes { - ret = append(ret, k) - } - return -} - -func (o *desiredSet) debugID() string { - if o.owner == nil { - return o.setID - } - metadata, err := meta.Accessor(o.owner) - if err != nil { - return o.setID - } - - return fmt.Sprintf("%s %s", o.setID, objectset.ObjectKey{ - Namespace: metadata.GetNamespace(), - Name: metadata.GetName(), - }) -} - -func (o *desiredSet) collect(objList []runtime.Object) objectset.ObjectByGVK { - result := objectset.ObjectByGVK{} - for _, obj := range objList { - _, _ = result.Add(obj) - } - return result -} - -func (o *desiredSet) runInjectors(objList []runtime.Object) ([]runtime.Object, error) { - var err error - - for _, inj := range o.injectors { - if inj == nil { - continue - } - - objList, err = inj(objList) - if err != nil { - return nil, err - } - } - - for _, name := range o.injectorNames { - inj := injectors.Get(name) - if inj == nil { - continue - } - - objList, err = inj(objList) - if err != nil { - return nil, err - } - } - - return objList, nil -} - -// GetSelectorFromOwner returns the label selector for the owner object which is useful -// to list the dependents -func GetSelectorFromOwner(setID string, owner runtime.Object) (labels.Selector, error) { - // Build the labels, we want the hash label for the lister - ownerLabel, _, err := GetLabelsAndAnnotations(setID, owner) - if err != nil { - return nil, err - } - return GetSelector(ownerLabel) -} - -func GetSelector(labelSet map[string]string) (labels.Selector, error) { - req, err := labels.NewRequirement(LabelHash, selection.Equals, []string{labelSet[LabelHash]}) - if err != nil { - return nil, err - } - return labels.NewSelector().Add(*req), nil -} - -func GetLabelsAndAnnotations(setID string, owner runtime.Object) (map[string]string, map[string]string, error) { - if setID == "" && owner == nil { - return nil, nil, fmt.Errorf("set ID or owner must be set") - } - - annotations := map[string]string{ - LabelID: setID, - } - - if owner != nil { - gvk, err := gvk2.Get(owner) - if err != nil { - return nil, nil, err - } - annotations[LabelGVK] = gvk.String() - metadata, err := meta.Accessor(owner) - if err != nil { - return nil, nil, fmt.Errorf("failed to get metadata for %s", gvk) - } - annotations[LabelName] = metadata.GetName() - annotations[LabelNamespace] = metadata.GetNamespace() - } - - labels := map[string]string{ - LabelHash: objectSetHash(annotations), - } - - return labels, annotations, nil -} - -func (o *desiredSet) injectLabelsAndAnnotations(labels, annotations map[string]string) ([]runtime.Object, error) { - var result []runtime.Object - - for _, objMap := range o.objs.ObjectsByGVK() { - for key, obj := range objMap { - obj = obj.DeepCopyObject() - meta, err := meta.Accessor(obj) - if err != nil { - return nil, errors.Wrapf(err, "failed to get metadata for %s", key) - } - - setLabels(meta, labels) - setAnnotations(meta, annotations) - - result = append(result, obj) - } - } - - return result, nil -} - -func setAnnotations(meta metav1.Object, annotations map[string]string) { - objAnn := meta.GetAnnotations() - if objAnn == nil { - objAnn = map[string]string{} - } - delete(objAnn, LabelApplied) - for k, v := range annotations { - objAnn[k] = v - } - meta.SetAnnotations(objAnn) -} - -func setLabels(meta metav1.Object, labels map[string]string) { - objLabels := meta.GetLabels() - if objLabels == nil { - objLabels = map[string]string{} - } - for k, v := range labels { - objLabels[k] = v - } - meta.SetLabels(objLabels) -} - -func objectSetHash(labels map[string]string) string { - dig := sha1.New() - for _, key := range hashOrder { - dig.Write([]byte(labels[key])) - } - return hex.EncodeToString(dig.Sum(nil)) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go b/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go deleted file mode 100644 index 15abe6dc97..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go +++ /dev/null @@ -1,454 +0,0 @@ -package apply - -import ( - "bytes" - "compress/gzip" - "encoding/base64" - "io/ioutil" - "strings" - - jsonpatch "github.com/evanphx/json-patch" - "github.com/pkg/errors" - data2 "github.com/rancher/wrangler/pkg/data" - "github.com/rancher/wrangler/pkg/data/convert" - "github.com/rancher/wrangler/pkg/objectset" - patch2 "github.com/rancher/wrangler/pkg/patch" - "github.com/sirupsen/logrus" - "k8s.io/apimachinery/pkg/api/meta" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/json" - "k8s.io/apimachinery/pkg/util/jsonmergepatch" - "k8s.io/apimachinery/pkg/util/strategicpatch" - "k8s.io/client-go/dynamic" -) - -const ( - LabelApplied = "objectset.rio.cattle.io/applied" -) - -var ( - knownListKeys = map[string]bool{ - "apiVersion": true, - "containerPort": true, - "devicePath": true, - "ip": true, - "kind": true, - "mountPath": true, - "name": true, - "port": true, - "topologyKey": true, - "type": true, - } -) - -func prepareObjectForCreate(gvk schema.GroupVersionKind, obj runtime.Object) (runtime.Object, error) { - serialized, err := serializeApplied(obj) - if err != nil { - return nil, err - } - - obj = obj.DeepCopyObject() - m, err := meta.Accessor(obj) - if err != nil { - return nil, err - } - annotations := m.GetAnnotations() - if annotations == nil { - annotations = map[string]string{} - } - - annotations[LabelApplied] = appliedToAnnotation(serialized) - m.SetAnnotations(annotations) - - typed, err := meta.TypeAccessor(obj) - if err != nil { - return nil, err - } - - apiVersion, kind := gvk.ToAPIVersionAndKind() - typed.SetAPIVersion(apiVersion) - typed.SetKind(kind) - - return obj, nil -} - -func originalAndModified(gvk schema.GroupVersionKind, oldMetadata v1.Object, newObject runtime.Object) ([]byte, []byte, error) { - original, err := getOriginalBytes(gvk, oldMetadata) - if err != nil { - return nil, nil, err - } - - newObject, err = prepareObjectForCreate(gvk, newObject) - if err != nil { - return nil, nil, err - } - - modified, err := json.Marshal(newObject) - - return original, modified, err -} - -func emptyMaps(data map[string]interface{}, keys ...string) bool { - for _, key := range append(keys, "__invalid_key__") { - if len(data) == 0 { - // map is empty so all children are empty too - return true - } else if len(data) > 1 { - // map has more than one key so not empty - return false - } - - value, ok := data[key] - if !ok { - // map has one key but not what we are expecting so not considered empty - return false - } - - data = convert.ToMapInterface(value) - } - - return true -} - -func sanitizePatch(patch []byte, removeObjectSetAnnotation bool) ([]byte, error) { - mod := false - data := map[string]interface{}{} - err := json.Unmarshal(patch, &data) - if err != nil { - return nil, err - } - - if _, ok := data["kind"]; ok { - mod = true - delete(data, "kind") - } - - if _, ok := data["apiVersion"]; ok { - mod = true - delete(data, "apiVersion") - } - - if _, ok := data["status"]; ok { - mod = true - delete(data, "status") - } - - if deleted := removeCreationTimestamp(data); deleted { - mod = true - } - - if removeObjectSetAnnotation { - metadata := convert.ToMapInterface(data2.GetValueN(data, "metadata")) - annotations := convert.ToMapInterface(data2.GetValueN(data, "metadata", "annotations")) - for k := range annotations { - if strings.HasPrefix(k, LabelPrefix) { - mod = true - delete(annotations, k) - } - } - if mod && len(annotations) == 0 { - delete(metadata, "annotations") - if len(metadata) == 0 { - delete(data, "metadata") - } - } - } - - if emptyMaps(data, "metadata", "annotations") { - return []byte("{}"), nil - } - - if !mod { - return patch, nil - } - - return json.Marshal(data) -} - -func applyPatch(gvk schema.GroupVersionKind, reconciler Reconciler, patcher Patcher, debugID string, ignoreOriginal bool, oldObject, newObject runtime.Object, diffPatches [][]byte) (bool, error) { - oldMetadata, err := meta.Accessor(oldObject) - if err != nil { - return false, err - } - - original, modified, err := originalAndModified(gvk, oldMetadata, newObject) - if err != nil { - return false, err - } - - if ignoreOriginal { - original = nil - } - - current, err := json.Marshal(oldObject) - if err != nil { - return false, err - } - - patchType, patch, err := doPatch(gvk, original, modified, current, diffPatches) - if err != nil { - return false, errors.Wrap(err, "patch generation") - } - - if string(patch) == "{}" { - return false, nil - } - - patch, err = sanitizePatch(patch, false) - if err != nil { - return false, err - } - - if string(patch) == "{}" { - return false, nil - } - - logrus.Debugf("DesiredSet - Patch %s %s/%s for %s -- [PATCH:%s, ORIGINAL:%s, MODIFIED:%s, CURRENT:%s]", gvk, oldMetadata.GetNamespace(), oldMetadata.GetName(), debugID, patch, original, modified, current) - if reconciler != nil { - newObject, err := prepareObjectForCreate(gvk, newObject) - if err != nil { - return false, err - } - originalObject, err := getOriginalObject(gvk, oldMetadata) - if err != nil { - return false, err - } - if originalObject == nil { - originalObject = oldObject - } - handled, err := reconciler(originalObject, newObject) - if err != nil { - return false, err - } - if handled { - return true, nil - } - } - - logrus.Debugf("DesiredSet - Updated %s %s/%s for %s -- %s %s", gvk, oldMetadata.GetNamespace(), oldMetadata.GetName(), debugID, patchType, patch) - _, err = patcher(oldMetadata.GetNamespace(), oldMetadata.GetName(), patchType, patch) - - return true, err -} - -func (o *desiredSet) compareObjects(gvk schema.GroupVersionKind, reconciler Reconciler, patcher Patcher, client dynamic.NamespaceableResourceInterface, debugID string, oldObject, newObject runtime.Object, force bool) error { - oldMetadata, err := meta.Accessor(oldObject) - if err != nil { - return err - } - - if o.createPlan { - o.plan.Objects = append(o.plan.Objects, oldObject) - } - - diffPatches := o.diffPatches[patchKey{ - GroupVersionKind: gvk, - ObjectKey: objectset.ObjectKey{ - Namespace: oldMetadata.GetNamespace(), - Name: oldMetadata.GetName(), - }, - }] - diffPatches = append(diffPatches, o.diffPatches[patchKey{ - GroupVersionKind: gvk, - }]...) - - if ran, err := applyPatch(gvk, reconciler, patcher, debugID, o.ignorePreviousApplied, oldObject, newObject, diffPatches); err != nil { - return err - } else if !ran { - logrus.Debugf("DesiredSet - No change(2) %s %s/%s for %s", gvk, oldMetadata.GetNamespace(), oldMetadata.GetName(), debugID) - } - - return nil -} - -func removeCreationTimestamp(data map[string]interface{}) bool { - metadata, ok := data["metadata"] - if !ok { - return false - } - - data = convert.ToMapInterface(metadata) - if _, ok := data["creationTimestamp"]; ok { - delete(data, "creationTimestamp") - return true - } - - return false -} - -func getOriginalObject(gvk schema.GroupVersionKind, obj v1.Object) (runtime.Object, error) { - original := appliedFromAnnotation(obj.GetAnnotations()[LabelApplied]) - if len(original) == 0 { - return nil, nil - } - - mapObj := map[string]interface{}{} - err := json.Unmarshal(original, &mapObj) - if err != nil { - return nil, err - } - - removeCreationTimestamp(mapObj) - return prepareObjectForCreate(gvk, &unstructured.Unstructured{ - Object: mapObj, - }) -} - -func getOriginalBytes(gvk schema.GroupVersionKind, obj v1.Object) ([]byte, error) { - objCopy, err := getOriginalObject(gvk, obj) - if err != nil { - return nil, err - } - if objCopy == nil { - return []byte("{}"), nil - } - return json.Marshal(objCopy) -} - -func appliedFromAnnotation(str string) []byte { - if len(str) == 0 || str[0] == '{' { - return []byte(str) - } - - b, err := base64.RawStdEncoding.DecodeString(str) - if err != nil { - return nil - } - - r, err := gzip.NewReader(bytes.NewBuffer(b)) - if err != nil { - return nil - } - - b, err = ioutil.ReadAll(r) - if err != nil { - return nil - } - - return b -} - -func pruneList(data []interface{}) []interface{} { - result := make([]interface{}, 0, len(data)) - for _, v := range data { - switch typed := v.(type) { - case map[string]interface{}: - result = append(result, pruneValues(typed, true)) - case []interface{}: - result = append(result, pruneList(typed)) - default: - result = append(result, v) - } - } - return result -} - -func pruneValues(data map[string]interface{}, isList bool) map[string]interface{} { - result := map[string]interface{}{} - for k, v := range data { - switch typed := v.(type) { - case map[string]interface{}: - result[k] = pruneValues(typed, false) - case []interface{}: - result[k] = pruneList(typed) - default: - if isList && knownListKeys[k] { - result[k] = v - } else { - switch x := v.(type) { - case string: - if len(x) > 64 { - result[k] = x[:64] - } else { - result[k] = v - } - case []byte: - result[k] = nil - default: - result[k] = v - } - } - } - } - return result -} - -func serializeApplied(obj runtime.Object) ([]byte, error) { - data, err := convert.EncodeToMap(obj) - if err != nil { - return nil, err - } - data = pruneValues(data, false) - return json.Marshal(data) -} - -func appliedToAnnotation(b []byte) string { - buf := &bytes.Buffer{} - w := gzip.NewWriter(buf) - if _, err := w.Write(b); err != nil { - return string(b) - } - if err := w.Close(); err != nil { - return string(b) - } - return base64.RawStdEncoding.EncodeToString(buf.Bytes()) -} - -func stripIgnores(original, modified, current []byte, patches [][]byte) ([]byte, []byte, []byte, error) { - for _, patch := range patches { - patch, err := jsonpatch.DecodePatch(patch) - if err != nil { - return nil, nil, nil, err - } - if len(original) > 0 { - b, err := patch.Apply(original) - if err == nil { - original = b - } - } - b, err := patch.Apply(modified) - if err == nil { - modified = b - } - b, err = patch.Apply(current) - if err == nil { - current = b - } - } - - return original, modified, current, nil -} - -// doPatch is adapted from "kubectl apply" -func doPatch(gvk schema.GroupVersionKind, original, modified, current []byte, diffPatch [][]byte) (types.PatchType, []byte, error) { - var ( - patchType types.PatchType - patch []byte - ) - - original, modified, current, err := stripIgnores(original, modified, current, diffPatch) - if err != nil { - return patchType, nil, err - } - - patchType, lookupPatchMeta, err := patch2.GetMergeStyle(gvk) - if err != nil { - return patchType, nil, err - } - - if patchType == types.StrategicMergePatchType { - patch, err = strategicpatch.CreateThreeWayMergePatch(original, modified, current, lookupPatchMeta, true) - } else { - patch, err = jsonmergepatch.CreateThreeWayJSONMergePatch(original, modified, current) - } - - if err != nil { - logrus.Errorf("Failed to calcuated patch: %v", err) - } - - return patchType, patch, err -} diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_crud.go b/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_crud.go deleted file mode 100644 index 901650ca69..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_crud.go +++ /dev/null @@ -1,72 +0,0 @@ -package apply - -import ( - "bytes" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/util/json" - "k8s.io/client-go/dynamic" -) - -var ( - deletePolicy = v1.DeletePropagationBackground -) - -func (o *desiredSet) toUnstructured(obj runtime.Object) (*unstructured.Unstructured, error) { - unstruct, ok := obj.(*unstructured.Unstructured) - if ok { - return unstruct, nil - } - - buf := &bytes.Buffer{} - if err := json.NewEncoder(buf).Encode(obj); err != nil { - return nil, err - } - - unstruct = &unstructured.Unstructured{ - Object: map[string]interface{}{}, - } - - return unstruct, json.Unmarshal(buf.Bytes(), &unstruct.Object) -} - -func (o *desiredSet) create(nsed bool, namespace string, client dynamic.NamespaceableResourceInterface, obj runtime.Object) (runtime.Object, error) { - unstr, err := o.toUnstructured(obj) - if err != nil { - return nil, err - } - - if nsed { - return client.Namespace(namespace).Create(o.ctx, unstr, v1.CreateOptions{}) - } - return client.Create(o.ctx, unstr, v1.CreateOptions{}) -} - -func (o *desiredSet) get(nsed bool, namespace, name string, client dynamic.NamespaceableResourceInterface) (runtime.Object, error) { - if nsed { - return client.Namespace(namespace).Get(o.ctx, name, v1.GetOptions{}) - } - return client.Get(o.ctx, name, v1.GetOptions{}) -} - -func (o *desiredSet) delete(nsed bool, namespace, name string, client dynamic.NamespaceableResourceInterface, force bool, gvk schema.GroupVersionKind) error { - if !force { - if o.noDelete { - return nil - } - if _, ok := o.noDeleteGVK[gvk]; ok { - return nil - } - } - opts := v1.DeleteOptions{ - PropagationPolicy: &deletePolicy, - } - if nsed { - return client.Namespace(namespace).Delete(o.ctx, name, opts) - } - - return client.Delete(o.ctx, name, opts) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_owner.go b/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_owner.go deleted file mode 100644 index dbe87dad9a..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_owner.go +++ /dev/null @@ -1,153 +0,0 @@ -package apply - -import ( - "fmt" - "strings" - - "github.com/rancher/wrangler/pkg/gvk" - - "github.com/rancher/wrangler/pkg/kv" - - "github.com/pkg/errors" - namer "github.com/rancher/wrangler/pkg/name" - apierrors "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/api/meta" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/dynamic" - "k8s.io/client-go/tools/cache" -) - -var ( - ErrOwnerNotFound = errors.New("owner not found") - ErrNoInformerFound = errors.New("informer not found") -) - -func notFound(name string, gvk schema.GroupVersionKind) error { - // this is not proper, but does it really matter that much? If you find this - // line while researching a bug, then the answer is probably yes. - resource := namer.GuessPluralName(strings.ToLower(gvk.Kind)) - return apierrors.NewNotFound(schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, name) -} - -func getGVK(gvkLabel string, gvk *schema.GroupVersionKind) error { - parts := strings.Split(gvkLabel, ", Kind=") - if len(parts) != 2 { - return fmt.Errorf("invalid GVK format: %s", gvkLabel) - } - gvk.Group, gvk.Version = kv.Split(parts[0], "/") - gvk.Kind = parts[1] - return nil -} - -func (o desiredSet) FindOwner(obj runtime.Object) (runtime.Object, error) { - if obj == nil { - return nil, ErrOwnerNotFound - } - meta, err := meta.Accessor(obj) - if err != nil { - return nil, err - } - - var ( - debugID = fmt.Sprintf("%s/%s", meta.GetNamespace(), meta.GetName()) - gvkLabel = meta.GetAnnotations()[LabelGVK] - namespace = meta.GetAnnotations()[LabelNamespace] - name = meta.GetAnnotations()[LabelName] - gvk schema.GroupVersionKind - ) - - if gvkLabel == "" { - return nil, ErrOwnerNotFound - } - - if err := getGVK(gvkLabel, &gvk); err != nil { - return nil, err - } - - cache, client, err := o.getControllerAndClient(debugID, gvk) - if err != nil { - return nil, err - } - - if cache != nil { - return o.fromCache(cache, namespace, name, gvk) - } - - return o.fromClient(client, namespace, name, gvk) -} - -func (o *desiredSet) fromClient(client dynamic.NamespaceableResourceInterface, namespace, name string, gvk schema.GroupVersionKind) (runtime.Object, error) { - var ( - err error - obj interface{} - ) - if namespace == "" { - obj, err = client.Get(o.ctx, name, metav1.GetOptions{}) - } else { - obj, err = client.Namespace(namespace).Get(o.ctx, name, metav1.GetOptions{}) - } - if err != nil { - return nil, err - } - if ro, ok := obj.(runtime.Object); ok { - return ro, nil - } - return nil, notFound(name, gvk) -} - -func (o *desiredSet) fromCache(cache cache.SharedInformer, namespace, name string, gvk schema.GroupVersionKind) (runtime.Object, error) { - var key string - if namespace == "" { - key = name - } else { - key = namespace + "/" + name - } - item, ok, err := cache.GetStore().GetByKey(key) - if err != nil { - return nil, err - } else if !ok { - return nil, notFound(name, gvk) - } else if ro, ok := item.(runtime.Object); ok { - return ro, nil - } - return nil, notFound(name, gvk) -} - -func (o desiredSet) PurgeOrphan(obj runtime.Object) error { - if obj == nil { - return nil - } - - meta, err := meta.Accessor(obj) - if err != nil { - return err - } - - if _, err := o.FindOwner(obj); apierrors.IsNotFound(err) { - gvk, err := gvk.Get(obj) - if err != nil { - return err - } - - o.strictCaching = false - _, client, err := o.getControllerAndClient(meta.GetName(), gvk) - if err != nil { - return err - } - if meta.GetNamespace() == "" { - return client.Delete(o.ctx, meta.GetName(), metav1.DeleteOptions{}) - } else { - return client.Namespace(meta.GetNamespace()).Delete(o.ctx, meta.GetName(), metav1.DeleteOptions{}) - } - } else if err == ErrOwnerNotFound { - return nil - } else if err != nil { - return err - } - return nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_process.go b/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_process.go deleted file mode 100644 index 84710113bc..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/apply/desiredset_process.go +++ /dev/null @@ -1,542 +0,0 @@ -package apply - -import ( - "context" - "fmt" - "sort" - "sync" - - "github.com/pkg/errors" - gvk2 "github.com/rancher/wrangler/pkg/gvk" - "github.com/rancher/wrangler/pkg/merr" - "github.com/rancher/wrangler/pkg/objectset" - "github.com/sirupsen/logrus" - "golang.org/x/sync/errgroup" - errors2 "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/api/meta" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - types2 "k8s.io/apimachinery/pkg/types" - "k8s.io/client-go/dynamic" - "k8s.io/client-go/tools/cache" -) - -var ( - 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 (o *desiredSet) getControllerAndClient(debugID string, gvk schema.GroupVersionKind) (cache.SharedIndexInformer, dynamic.NamespaceableResourceInterface, error) { - // client needs to be accessed first so that the gvk->gvr mapping gets cached - client, err := o.a.clients.client(gvk) - if err != nil { - return nil, nil, err - } - - informer, ok := o.pruneTypes[gvk] - if !ok { - informer = o.a.informers[gvk] - } - if informer == nil && o.informerFactory != nil { - newInformer, err := o.informerFactory.Get(gvk, o.a.clients.gvr(gvk)) - if err != nil { - return nil, nil, errors.Wrapf(err, "failed to construct informer for %v for %s", gvk, debugID) - } - informer = newInformer - } - if informer == nil && o.strictCaching { - return nil, nil, fmt.Errorf("failed to find informer for %s for %s: %w", gvk, debugID, ErrNoInformerFound) - } - - return informer, client, nil -} - -func (o *desiredSet) assignOwnerReference(gvk schema.GroupVersionKind, objs objectset.ObjectByKey) error { - if o.owner == nil { - return fmt.Errorf("no owner set to assign owner reference") - } - ownerMeta, err := meta.Accessor(o.owner) - if err != nil { - return err - } - ownerGVK, err := gvk2.Get(o.owner) - if err != nil { - return err - } - ownerNSed, err := o.a.clients.IsNamespaced(ownerGVK) - if err != nil { - return err - } - - for k, v := range objs { - // can't set owners across boundaries - if ownerNSed { - if nsed, err := o.a.clients.IsNamespaced(gvk); err != nil { - return err - } else if !nsed { - continue - } - } - - assignNS := false - assignOwner := true - if nsed, err := o.a.clients.IsNamespaced(gvk); err != nil { - return err - } else if nsed { - if k.Namespace == "" { - assignNS = true - } else if k.Namespace != ownerMeta.GetNamespace() && ownerNSed { - assignOwner = false - } - } - - if !assignOwner { - continue - } - - v = v.DeepCopyObject() - meta, err := meta.Accessor(v) - if err != nil { - return err - } - - if assignNS { - meta.SetNamespace(ownerMeta.GetNamespace()) - } - - shouldSet := true - for _, of := range meta.GetOwnerReferences() { - if ownerMeta.GetUID() == of.UID { - shouldSet = false - break - } - } - - if shouldSet { - meta.SetOwnerReferences(append(meta.GetOwnerReferences(), v1.OwnerReference{ - APIVersion: ownerGVK.GroupVersion().String(), - Kind: ownerGVK.Kind, - Name: ownerMeta.GetName(), - UID: ownerMeta.GetUID(), - Controller: &o.ownerReferenceController, - BlockOwnerDeletion: &o.ownerReferenceBlock, - })) - } - - objs[k] = v - - if assignNS { - delete(objs, k) - k.Namespace = ownerMeta.GetNamespace() - objs[k] = v - } - } - - return nil -} - -func (o *desiredSet) adjustNamespace(gvk schema.GroupVersionKind, objs objectset.ObjectByKey) error { - for k, v := range objs { - if k.Namespace != "" { - continue - } - - v = v.DeepCopyObject() - meta, err := meta.Accessor(v) - if err != nil { - return err - } - - meta.SetNamespace(o.defaultNamespace) - delete(objs, k) - k.Namespace = o.defaultNamespace - objs[k] = v - } - - return nil -} - -func (o *desiredSet) clearNamespace(objs objectset.ObjectByKey) error { - for k, v := range objs { - if k.Namespace == "" { - continue - } - - v = v.DeepCopyObject() - meta, err := meta.Accessor(v) - if err != nil { - return err - } - - meta.SetNamespace("") - - delete(objs, k) - k.Namespace = "" - objs[k] = v - } - - return nil -} - -func (o *desiredSet) createPatcher(client dynamic.NamespaceableResourceInterface) Patcher { - return func(namespace, name string, pt types2.PatchType, data []byte) (object runtime.Object, e error) { - if namespace != "" { - return client.Namespace(namespace).Patch(o.ctx, name, pt, data, v1.PatchOptions{}) - } - return client.Patch(o.ctx, name, pt, data, v1.PatchOptions{}) - } -} - -func (o *desiredSet) filterCrossVersion(gvk schema.GroupVersionKind, keys []objectset.ObjectKey) []objectset.ObjectKey { - result := make([]objectset.ObjectKey, 0, len(keys)) - gk := gvk.GroupKind() - for _, key := range keys { - if o.objs.Contains(gk, key) { - continue - } - if key.Namespace == o.defaultNamespace && o.objs.Contains(gk, objectset.ObjectKey{Name: key.Name}) { - continue - } - result = append(result, key) - } - return result -} - -func (o *desiredSet) process(debugID string, set labels.Selector, gvk schema.GroupVersionKind, objs objectset.ObjectByKey) { - controller, client, err := o.getControllerAndClient(debugID, gvk) - if err != nil { - o.err(err) - return - } - - nsed, err := o.a.clients.IsNamespaced(gvk) - if err != nil { - o.err(err) - return - } - - if !nsed && o.restrictClusterScoped { - o.err(fmt.Errorf("invalid cluster scoped gvk: %v", gvk)) - return - } - - if o.setOwnerReference && o.owner != nil { - if err := o.assignOwnerReference(gvk, objs); err != nil { - o.err(err) - return - } - } - - if nsed { - if err := o.adjustNamespace(gvk, objs); err != nil { - o.err(err) - return - } - } else { - if err := o.clearNamespace(objs); err != nil { - o.err(err) - return - } - } - - patcher, ok := o.patchers[gvk] - if !ok { - patcher = o.createPatcher(client) - } - - reconciler := o.reconcilers[gvk] - - existing, err := o.list(nsed, controller, client, set, objs) - if err != nil { - o.err(errors.Wrapf(err, "failed to list %s for %s", gvk, debugID)) - return - } - - toCreate, toDelete, toUpdate := compareSets(existing, objs) - - // check for resources in the objectset but under a different version of the same group/kind - toDelete = o.filterCrossVersion(gvk, toDelete) - - if o.createPlan { - o.plan.Create[gvk] = toCreate - o.plan.Delete[gvk] = toDelete - - reconciler = nil - patcher = func(namespace, name string, pt types2.PatchType, data []byte) (runtime.Object, error) { - data, err := sanitizePatch(data, true) - if err != nil { - return nil, err - } - if string(data) != "{}" { - o.plan.Update.Add(gvk, namespace, name, string(data)) - } - return nil, nil - } - - toCreate = nil - toDelete = nil - } - - createF := func(k objectset.ObjectKey) { - obj := objs[k] - obj, err := prepareObjectForCreate(gvk, obj) - if err != nil { - o.err(errors.Wrapf(err, "failed to prepare create %s %s for %s", k, gvk, debugID)) - return - } - - _, err = o.create(nsed, k.Namespace, client, obj) - if errors2.IsAlreadyExists(err) { - // Taking over an object that wasn't previously managed by us - existingObj, err := o.get(nsed, k.Namespace, k.Name, client) - if err == nil { - toUpdate = append(toUpdate, k) - existing[k] = existingObj - return - } - } - if err != nil { - o.err(errors.Wrapf(err, "failed to create %s %s for %s", k, gvk, debugID)) - return - } - logrus.Debugf("DesiredSet - Created %s %s for %s", gvk, k, debugID) - } - - deleteF := func(k objectset.ObjectKey, force bool) { - if err := o.delete(nsed, k.Namespace, k.Name, client, force, gvk); err != nil { - o.err(errors.Wrapf(err, "failed to delete %s %s for %s", k, gvk, debugID)) - return - } - logrus.Debugf("DesiredSet - Delete %s %s for %s", gvk, k, debugID) - } - - updateF := func(k objectset.ObjectKey) { - err := o.compareObjects(gvk, reconciler, patcher, client, debugID, existing[k], objs[k], len(toCreate) > 0 || len(toDelete) > 0) - if err == ErrReplace { - deleteF(k, true) - o.err(fmt.Errorf("DesiredSet - Replace Wait %s %s for %s", gvk, k, debugID)) - } else if err != nil { - o.err(errors.Wrapf(err, "failed to update %s %s for %s", k, gvk, debugID)) - } - } - - for _, k := range toCreate { - createF(k) - } - - for _, k := range toUpdate { - updateF(k) - } - - for _, k := range toDelete { - deleteF(k, false) - } -} - -func (o *desiredSet) list(namespaced bool, informer cache.SharedIndexInformer, client dynamic.NamespaceableResourceInterface, selector labels.Selector, desiredObjects objectset.ObjectByKey) (map[objectset.ObjectKey]runtime.Object, error) { - var ( - errs []error - objs = objectset.ObjectByKey{} - ) - - if informer == nil { - // If a lister namespace is set, assume all objects belong to the listerNamespace. If the - // desiredSet has an owner but no lister namespace, list objects from all namespaces to ensure - // we're cleaning up any owned resources. Otherwise, search only objects from the namespaces - // used by the objects. Note: desiredSets without owners will never return objects to delete; - // deletion requires an owner to track object references across multiple apply runs. - var namespaces []string - if o.listerNamespace != "" { - namespaces = append(namespaces, o.listerNamespace) - } else { - namespaces = desiredObjects.Namespaces() - } - - if o.owner != nil && o.listerNamespace == "" { - // owner set and unspecified lister namespace, search all namespaces - err := allNamespaceList(o.ctx, client, selector, func(obj unstructured.Unstructured) { - if err := addObjectToMap(objs, &obj); err != nil { - errs = append(errs, err) - } - }) - if err != nil { - errs = append(errs, err) - } - } else { - // no owner or lister namespace intentionally restricted; only search in specified namespaces - err := multiNamespaceList(o.ctx, namespaces, client, selector, func(obj unstructured.Unstructured) { - if err := addObjectToMap(objs, &obj); err != nil { - errs = append(errs, err) - } - }) - if err != nil { - errs = append(errs, err) - } - } - - return objs, merr.NewErrors(errs...) - } - - var namespace string - if namespaced { - namespace = o.listerNamespace - } - - // Special case for listing only by hash using indexers - indexer := informer.GetIndexer() - if hash, ok := getIndexableHash(indexer, selector); ok { - return listByHash(indexer, hash, namespace) - } - - if err := cache.ListAllByNamespace(indexer, namespace, selector, func(obj interface{}) { - if err := addObjectToMap(objs, obj); err != nil { - errs = append(errs, err) - } - }); err != nil { - errs = append(errs, err) - } - - return objs, merr.NewErrors(errs...) -} - -func shouldPrune(obj runtime.Object) bool { - meta, err := meta.Accessor(obj) - if err != nil { - return true - } - return meta.GetLabels()[LabelPrune] != "false" -} - -func compareSets(existingSet, newSet objectset.ObjectByKey) (toCreate, toDelete, toUpdate []objectset.ObjectKey) { - for k := range newSet { - if _, ok := existingSet[k]; ok { - toUpdate = append(toUpdate, k) - } else { - toCreate = append(toCreate, k) - } - } - - for k, obj := range existingSet { - if _, ok := newSet[k]; !ok { - if shouldPrune(obj) { - toDelete = append(toDelete, k) - } - } - } - - sortObjectKeys(toCreate) - sortObjectKeys(toDelete) - sortObjectKeys(toUpdate) - - return -} - -func sortObjectKeys(keys []objectset.ObjectKey) { - sort.Slice(keys, func(i, j int) bool { - return keys[i].String() < keys[j].String() - }) -} - -func addObjectToMap(objs objectset.ObjectByKey, obj interface{}) error { - metadata, err := meta.Accessor(obj) - if err != nil { - return err - } - - objs[objectset.ObjectKey{ - Namespace: metadata.GetNamespace(), - Name: metadata.GetName(), - }] = obj.(runtime.Object) - - return nil -} - -// allNamespaceList lists objects across all namespaces. -func allNamespaceList(ctx context.Context, baseClient dynamic.NamespaceableResourceInterface, selector labels.Selector, appendFn func(obj unstructured.Unstructured)) error { - list, err := baseClient.List(ctx, v1.ListOptions{ - LabelSelector: selector.String(), - }) - if err != nil { - return err - } - for _, obj := range list.Items { - appendFn(obj) - } - return nil -} - -// multiNamespaceList lists objects across all given namespaces, because requests are concurrent it is possible for appendFn to be called before errors are reported. -func multiNamespaceList(ctx context.Context, namespaces []string, baseClient dynamic.NamespaceableResourceInterface, selector labels.Selector, appendFn func(obj unstructured.Unstructured)) error { - var mu sync.Mutex - wg, _ctx := errgroup.WithContext(ctx) - - // list all namespaces concurrently - for _, namespace := range namespaces { - namespace := namespace - wg.Go(func() error { - list, err := baseClient.Namespace(namespace).List(_ctx, v1.ListOptions{ - LabelSelector: selector.String(), - }) - if err != nil { - return err - } - - mu.Lock() - for _, obj := range list.Items { - appendFn(obj) - } - mu.Unlock() - - return nil - }) - } - - return wg.Wait() -} - -// getIndexableHash detects if provided selector can be replaced by using the hash index, if configured, in which case returns the hash value -func getIndexableHash(indexer cache.Indexer, selector labels.Selector) (string, bool) { - // Check if indexer was added - if indexer == nil || indexer.GetIndexers()[byHash] == nil { - return "", false - } - - // Check specific case of listing with exact hash label selector - if req, selectable := selector.Requirements(); len(req) != 1 || !selectable { - return "", false - } - - return selector.RequiresExactMatch(LabelHash) -} - -// inNamespace checks whether a given object is a Kubernetes object and is part of the provided namespace -func inNamespace(namespace string, obj interface{}) bool { - metadata, err := meta.Accessor(obj) - return err == nil && metadata.GetNamespace() == namespace -} - -// listByHash use a pre-configured indexer to list objects of a certain type by their hash label -func listByHash(indexer cache.Indexer, hash string, namespace string) (map[objectset.ObjectKey]runtime.Object, error) { - var ( - errs []error - objs = objectset.ObjectByKey{} - ) - res, err := indexer.ByIndex(byHash, hash) - if err != nil { - return nil, err - } - for _, obj := range res { - if namespace != "" && !inNamespace(namespace, obj) { - continue - } - if err := addObjectToMap(objs, obj); err != nil { - errs = append(errs, err) - } - } - return objs, merr.NewErrors(errs...) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/injectors/registry.go b/vendor/github.com/rancher/wrangler/pkg/apply/injectors/registry.go deleted file mode 100644 index d9fd143050..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/apply/injectors/registry.go +++ /dev/null @@ -1,21 +0,0 @@ -package injectors - -import "k8s.io/apimachinery/pkg/runtime" - -var ( - injectors = map[string]ConfigInjector{} - order []string -) - -type ConfigInjector func(config []runtime.Object) ([]runtime.Object, error) - -func Register(name string, injector ConfigInjector) { - if _, ok := injectors[name]; !ok { - order = append(order, name) - } - injectors[name] = injector -} - -func Get(name string) ConfigInjector { - return injectors[name] -} diff --git a/vendor/github.com/rancher/wrangler/pkg/apply/reconcilers.go b/vendor/github.com/rancher/wrangler/pkg/apply/reconcilers.go deleted file mode 100644 index 98dad4729e..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/apply/reconcilers.go +++ /dev/null @@ -1,166 +0,0 @@ -package apply - -import ( - "encoding/json" - "fmt" - "reflect" - - appsv1 "k8s.io/api/apps/v1" - batchv1 "k8s.io/api/batch/v1" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -var ( - defaultReconcilers = map[schema.GroupVersionKind]Reconciler{ - v1.SchemeGroupVersion.WithKind("Secret"): reconcileSecret, - v1.SchemeGroupVersion.WithKind("Service"): reconcileService, - batchv1.SchemeGroupVersion.WithKind("Job"): reconcileJob, - appsv1.SchemeGroupVersion.WithKind("Deployment"): reconcileDeployment, - appsv1.SchemeGroupVersion.WithKind("DaemonSet"): reconcileDaemonSet, - } -) - -func reconcileDaemonSet(oldObj, newObj runtime.Object) (bool, error) { - oldSvc, ok := oldObj.(*appsv1.DaemonSet) - if !ok { - oldSvc = &appsv1.DaemonSet{} - if err := convertObj(oldObj, oldSvc); err != nil { - return false, err - } - } - newSvc, ok := newObj.(*appsv1.DaemonSet) - if !ok { - newSvc = &appsv1.DaemonSet{} - if err := convertObj(newObj, newSvc); err != nil { - return false, err - } - } - - if !equality.Semantic.DeepEqual(oldSvc.Spec.Selector, newSvc.Spec.Selector) { - return false, ErrReplace - } - - return false, nil -} - -func reconcileDeployment(oldObj, newObj runtime.Object) (bool, error) { - oldSvc, ok := oldObj.(*appsv1.Deployment) - if !ok { - oldSvc = &appsv1.Deployment{} - if err := convertObj(oldObj, oldSvc); err != nil { - return false, err - } - } - newSvc, ok := newObj.(*appsv1.Deployment) - if !ok { - newSvc = &appsv1.Deployment{} - if err := convertObj(newObj, newSvc); err != nil { - return false, err - } - } - - if !equality.Semantic.DeepEqual(oldSvc.Spec.Selector, newSvc.Spec.Selector) { - return false, ErrReplace - } - - return false, nil -} - -func reconcileSecret(oldObj, newObj runtime.Object) (bool, error) { - oldSvc, ok := oldObj.(*v1.Secret) - if !ok { - oldSvc = &v1.Secret{} - if err := convertObj(oldObj, oldSvc); err != nil { - return false, err - } - } - newSvc, ok := newObj.(*v1.Secret) - if !ok { - newSvc = &v1.Secret{} - if err := convertObj(newObj, newSvc); err != nil { - return false, err - } - } - - if newSvc.Type != "" && oldSvc.Type != newSvc.Type { - return false, ErrReplace - } - - return false, nil -} - -func reconcileService(oldObj, newObj runtime.Object) (bool, error) { - oldSvc, ok := oldObj.(*v1.Service) - if !ok { - oldSvc = &v1.Service{} - if err := convertObj(oldObj, oldSvc); err != nil { - return false, err - } - } - newSvc, ok := newObj.(*v1.Service) - if !ok { - newSvc = &v1.Service{} - if err := convertObj(newObj, newSvc); err != nil { - return false, err - } - } - - if newSvc.Spec.Type != "" && oldSvc.Spec.Type != newSvc.Spec.Type { - return false, ErrReplace - } - - return false, nil -} - -func reconcileJob(oldObj, newObj runtime.Object) (bool, error) { - oldJob, ok := oldObj.(*batchv1.Job) - if !ok { - oldJob = &batchv1.Job{} - if err := convertObj(oldObj, oldJob); err != nil { - return false, err - } - } - - newJob, ok := newObj.(*batchv1.Job) - if !ok { - newJob = &batchv1.Job{} - if err := convertObj(newObj, newJob); err != nil { - return false, err - } - } - - // We round trip the object here because when serializing to the applied - // annotation values are truncated to 64 bytes. - prunedJob, err := getOriginalObject(newJob.GroupVersionKind(), newJob) - if err != nil { - return false, err - } - - newPrunedJob := &batchv1.Job{} - if err := convertObj(prunedJob, newPrunedJob); err != nil { - return false, err - } - - if !equality.Semantic.DeepEqual(oldJob.Spec.Template, newPrunedJob.Spec.Template) { - return false, ErrReplace - } - - return false, nil -} - -func convertObj(src interface{}, obj interface{}) error { - uObj, ok := src.(*unstructured.Unstructured) - if !ok { - return fmt.Errorf("expected unstructured but got %v", reflect.TypeOf(src)) - } - - bytes, err := uObj.MarshalJSON() - if err != nil { - return err - } - return json.Unmarshal(bytes, obj) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/condition/condition.go b/vendor/github.com/rancher/wrangler/pkg/condition/condition.go deleted file mode 100644 index ace8dea311..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/condition/condition.go +++ /dev/null @@ -1,260 +0,0 @@ -package condition - -import ( - "reflect" - "time" - - "github.com/rancher/wrangler/pkg/generic" - "github.com/sirupsen/logrus" -) - -type Cond string - -func (c Cond) GetStatus(obj interface{}) string { - return getStatus(obj, string(c)) -} - -func (c Cond) SetError(obj interface{}, reason string, err error) { - if err == nil || err == generic.ErrSkip { - c.True(obj) - c.Message(obj, "") - c.Reason(obj, reason) - return - } - if reason == "" { - reason = "Error" - } - c.False(obj) - c.Message(obj, err.Error()) - c.Reason(obj, reason) -} - -func (c Cond) MatchesError(obj interface{}, reason string, err error) bool { - if err == nil { - return c.IsTrue(obj) && - c.GetMessage(obj) == "" && - c.GetReason(obj) == reason - } - if reason == "" { - reason = "Error" - } - return c.IsFalse(obj) && - c.GetMessage(obj) == err.Error() && - c.GetReason(obj) == reason -} - -func (c Cond) SetStatus(obj interface{}, status string) { - setStatus(obj, string(c), status) -} - -func (c Cond) SetStatusBool(obj interface{}, val bool) { - if val { - setStatus(obj, string(c), "True") - } else { - setStatus(obj, string(c), "False") - } -} - -func (c Cond) True(obj interface{}) { - setStatus(obj, string(c), "True") -} - -func (c Cond) IsTrue(obj interface{}) bool { - return getStatus(obj, string(c)) == "True" -} - -func (c Cond) False(obj interface{}) { - setStatus(obj, string(c), "False") -} - -func (c Cond) IsFalse(obj interface{}) bool { - return getStatus(obj, string(c)) == "False" -} - -func (c Cond) Unknown(obj interface{}) { - setStatus(obj, string(c), "Unknown") -} - -func (c Cond) IsUnknown(obj interface{}) bool { - return getStatus(obj, string(c)) == "Unknown" -} - -func (c Cond) LastUpdated(obj interface{}, ts string) { - setTS(obj, string(c), ts) -} - -func (c Cond) GetLastUpdated(obj interface{}) string { - return getTS(obj, string(c)) -} - -func (c Cond) CreateUnknownIfNotExists(obj interface{}) { - condSlice := getValue(obj, "Status", "Conditions") - if !condSlice.IsValid() { - condSlice = getValue(obj, "Conditions") - } - cond := findCond(obj, condSlice, string(c)) - if cond == nil { - c.Unknown(obj) - } -} - -func (c Cond) Reason(obj interface{}, reason string) { - cond := findOrCreateCond(obj, string(c)) - getFieldValue(cond, "Reason").SetString(reason) -} - -func (c Cond) GetReason(obj interface{}) string { - cond := findOrNotCreateCond(obj, string(c)) - if cond == nil { - return "" - } - return getFieldValue(*cond, "Reason").String() -} - -func (c Cond) SetMessageIfBlank(obj interface{}, message string) { - if c.GetMessage(obj) == "" { - c.Message(obj, message) - } -} - -func (c Cond) Message(obj interface{}, message string) { - cond := findOrCreateCond(obj, string(c)) - setValue(cond, "Message", message) -} - -func (c Cond) GetMessage(obj interface{}) string { - cond := findOrNotCreateCond(obj, string(c)) - if cond == nil { - return "" - } - return getFieldValue(*cond, "Message").String() -} - -func touchTS(value reflect.Value) { - now := time.Now().UTC().Format(time.RFC3339) - getFieldValue(value, "LastUpdateTime").SetString(now) -} - -func getStatus(obj interface{}, condName string) string { - cond := findOrNotCreateCond(obj, condName) - if cond == nil { - return "" - } - return getFieldValue(*cond, "Status").String() -} - -func setTS(obj interface{}, condName, ts string) { - cond := findOrCreateCond(obj, condName) - getFieldValue(cond, "LastUpdateTime").SetString(ts) -} - -func getTS(obj interface{}, condName string) string { - cond := findOrNotCreateCond(obj, condName) - if cond == nil { - return "" - } - return getFieldValue(*cond, "LastUpdateTime").String() -} - -func setStatus(obj interface{}, condName, status string) { - if reflect.TypeOf(obj).Kind() != reflect.Ptr { - panic("obj passed must be a pointer") - } - cond := findOrCreateCond(obj, condName) - setValue(cond, "Status", status) -} - -func setValue(cond reflect.Value, fieldName, newValue string) { - value := getFieldValue(cond, fieldName) - if value.String() != newValue { - value.SetString(newValue) - touchTS(cond) - } -} - -func findOrNotCreateCond(obj interface{}, condName string) *reflect.Value { - condSlice := getValue(obj, "Status", "Conditions") - if !condSlice.IsValid() { - condSlice = getValue(obj, "Conditions") - } - return findCond(obj, condSlice, condName) -} - -func findOrCreateCond(obj interface{}, condName string) reflect.Value { - condSlice := getValue(obj, "Status", "Conditions") - if !condSlice.IsValid() { - condSlice = getValue(obj, "Conditions") - } - cond := findCond(obj, condSlice, condName) - if cond != nil { - return *cond - } - - newCond := reflect.New(condSlice.Type().Elem()).Elem() - newCond.FieldByName("Type").SetString(condName) - newCond.FieldByName("Status").SetString("Unknown") - condSlice.Set(reflect.Append(condSlice, newCond)) - return *findCond(obj, condSlice, condName) -} - -func findCond(obj interface{}, val reflect.Value, name string) *reflect.Value { - defer func() { - if recover() != nil { - logrus.Fatalf("failed to find .Status.Conditions field on %v", reflect.TypeOf(obj)) - } - }() - - for i := 0; i < val.Len(); i++ { - cond := val.Index(i) - typeVal := getFieldValue(cond, "Type") - if typeVal.String() == name { - return &cond - } - } - - return nil -} - -func getValue(obj interface{}, name ...string) reflect.Value { - if obj == nil { - return reflect.Value{} - } - v := reflect.ValueOf(obj) - t := v.Type() - if t.Kind() == reflect.Ptr { - v = v.Elem() - } - - field := v.FieldByName(name[0]) - if len(name) == 1 { - return field - } - return getFieldValue(field, name[1:]...) -} - -func getFieldValue(v reflect.Value, name ...string) reflect.Value { - if !v.IsValid() { - return v - } - field := v.FieldByName(name[0]) - if len(name) == 1 { - return field - } - return getFieldValue(field, name[1:]...) -} - -func Error(reason string, err error) error { - return &conditionError{ - reason: reason, - message: err.Error(), - } -} - -type conditionError struct { - reason string - message string -} - -func (e *conditionError) Error() string { - return e.message -} diff --git a/vendor/github.com/rancher/wrangler/pkg/data/convert/convert.go b/vendor/github.com/rancher/wrangler/pkg/data/convert/convert.go deleted file mode 100644 index ff67f04900..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/data/convert/convert.go +++ /dev/null @@ -1,314 +0,0 @@ -package convert - -import ( - "bytes" - "encoding/json" - "errors" - "fmt" - "strconv" - "strings" - "time" - "unicode" - - "golang.org/x/text/cases" - "golang.org/x/text/language" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" -) - -func Singular(value interface{}) interface{} { - if slice, ok := value.([]string); ok { - if len(slice) == 0 { - return nil - } - return slice[0] - } - if slice, ok := value.([]interface{}); ok { - if len(slice) == 0 { - return nil - } - return slice[0] - } - return value -} - -func ToStringNoTrim(value interface{}) string { - if t, ok := value.(time.Time); ok { - return t.Format(time.RFC3339) - } - single := Singular(value) - if single == nil { - return "" - } - return fmt.Sprint(single) -} - -func ToString(value interface{}) string { - return strings.TrimSpace(ToStringNoTrim(value)) -} - -func ToTimestamp(value interface{}) (int64, error) { - str := ToString(value) - if str == "" { - return 0, errors.New("invalid date") - } - t, err := time.Parse(time.RFC3339, str) - if err != nil { - return 0, err - } - return t.UnixNano() / 1000000, nil -} - -func ToBool(value interface{}) bool { - value = Singular(value) - - b, ok := value.(bool) - if ok { - return b - } - - str := strings.ToLower(ToString(value)) - return str == "true" || str == "t" || str == "yes" || str == "y" -} - -func ToNumber(value interface{}) (int64, error) { - value = Singular(value) - - i, ok := value.(int64) - if ok { - return i, nil - } - f, ok := value.(float64) - if ok { - return int64(f), nil - } - if n, ok := value.(json.Number); ok { - i, err := n.Int64() - if err == nil { - return i, nil - } - f, err := n.Float64() - return int64(f), err - } - return strconv.ParseInt(ToString(value), 10, 64) -} - -func ToFloat(value interface{}) (float64, error) { - value = Singular(value) - - f64, ok := value.(float64) - if ok { - return f64, nil - } - - f32, ok := value.(float32) - if ok { - return float64(f32), nil - } - - if n, ok := value.(json.Number); ok { - i, err := n.Int64() - if err == nil { - return float64(i), nil - } - f, err := n.Float64() - return float64(f), err - } - return strconv.ParseFloat(ToString(value), 64) -} - -func Capitalize(s string) string { - if len(s) <= 1 { - return strings.ToUpper(s) - } - - return strings.ToUpper(s[:1]) + s[1:] -} - -func Uncapitalize(s string) string { - if len(s) <= 1 { - return strings.ToLower(s) - } - - return strings.ToLower(s[:1]) + s[1:] -} - -func LowerTitle(input string) string { - runes := []rune(input) - for i := 0; i < len(runes); i++ { - if unicode.IsUpper(runes[i]) && - (i == 0 || - i == len(runes)-1 || - unicode.IsUpper(runes[i+1])) { - runes[i] = unicode.ToLower(runes[i]) - } else { - break - } - } - - return string(runes) -} - -func IsEmptyValue(v interface{}) bool { - if v == nil || v == "" || v == 0 || v == false { - return true - } - if m, ok := v.(map[string]interface{}); ok { - return len(m) == 0 - } - if s, ok := v.([]interface{}); ok { - return len(s) == 0 - } - return false -} - -func ToMapInterface(obj interface{}) map[string]interface{} { - v, _ := obj.(map[string]interface{}) - return v -} - -func ToInterfaceSlice(obj interface{}) []interface{} { - if v, ok := obj.([]interface{}); ok { - return v - } - return nil -} - -func ToMapSlice(obj interface{}) []map[string]interface{} { - if v, ok := obj.([]map[string]interface{}); ok { - return v - } - vs, _ := obj.([]interface{}) - var result []map[string]interface{} - for _, item := range vs { - if v, ok := item.(map[string]interface{}); ok { - result = append(result, v) - } else { - return nil - } - } - - return result -} - -func ToStringSlice(data interface{}) []string { - if v, ok := data.([]string); ok { - return v - } - if v, ok := data.([]interface{}); ok { - var result []string - for _, item := range v { - result = append(result, ToString(item)) - } - return result - } - if v, ok := data.(string); ok { - return []string{v} - } - return nil -} - -func ToObj(data interface{}, into interface{}) error { - bytes, err := json.Marshal(data) - if err != nil { - return err - } - return json.Unmarshal(bytes, into) -} - -func EncodeToMap(obj interface{}) (map[string]interface{}, error) { - if m, ok := obj.(map[string]interface{}); ok { - return m, nil - } - - if unstr, ok := obj.(*unstructured.Unstructured); ok { - return unstr.Object, nil - } - - b, err := json.Marshal(obj) - if err != nil { - return nil, err - } - result := map[string]interface{}{} - dec := json.NewDecoder(bytes.NewBuffer(b)) - dec.UseNumber() - return result, dec.Decode(&result) -} - -func ToJSONKey(str string) string { - parts := strings.Split(str, "_") - for i := 1; i < len(parts); i++ { - caser := cases.Title(language.English) - parts[i] = caser.String(parts[i]) - } - - return strings.Join(parts, "") -} - -func ToYAMLKey(str string) string { - var result []rune - cap := false - - for i, r := range []rune(str) { - if i == 0 { - if unicode.IsUpper(r) { - cap = true - } - result = append(result, unicode.ToLower(r)) - continue - } - - if unicode.IsUpper(r) { - if cap { - result = append(result, unicode.ToLower(r)) - } else { - result = append(result, '_', unicode.ToLower(r)) - } - } else { - cap = false - result = append(result, r) - } - } - - return string(result) -} - -func ToArgKey(str string) string { - var ( - result []rune - input = []rune(str) - ) - cap := false - - for i := 0; i < len(input); i++ { - r := input[i] - if i == 0 { - if unicode.IsUpper(r) { - cap = true - } - result = append(result, unicode.ToLower(r)) - continue - } - - if unicode.IsUpper(r) { - if cap { - result = append(result, unicode.ToLower(r)) - } else if len(input) > i+2 && - unicode.IsUpper(input[i]) && - unicode.IsUpper(input[i+1]) && - unicode.IsUpper(input[i+2]) { - result = append(result, '-', - unicode.ToLower(input[i]), - unicode.ToLower(input[i+1]), - unicode.ToLower(input[i+2])) - i += 2 - } else { - result = append(result, '-', unicode.ToLower(r)) - } - } else { - cap = false - result = append(result, r) - } - } - - return "--" + string(result) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/data/data.go b/vendor/github.com/rancher/wrangler/pkg/data/data.go deleted file mode 100644 index 46a3ccb74f..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/data/data.go +++ /dev/null @@ -1,67 +0,0 @@ -package data - -import ( - "github.com/rancher/wrangler/pkg/data/convert" -) - -type List []map[string]interface{} - -type Object map[string]interface{} - -func New() Object { - return map[string]interface{}{} -} - -func Convert(obj interface{}) (Object, error) { - data, err := convert.EncodeToMap(obj) - if err != nil { - return nil, err - } - return data, nil -} - -func (o Object) Map(names ...string) Object { - v := GetValueN(o, names...) - m := convert.ToMapInterface(v) - return m -} - -func (o Object) Slice(names ...string) (result []Object) { - v := GetValueN(o, names...) - for _, item := range convert.ToInterfaceSlice(v) { - result = append(result, convert.ToMapInterface(item)) - } - return -} - -func (o Object) Values() (result []Object) { - for k := range o { - result = append(result, o.Map(k)) - } - return -} - -func (o Object) String(names ...string) string { - v := GetValueN(o, names...) - return convert.ToString(v) -} - -func (o Object) StringSlice(names ...string) []string { - v := GetValueN(o, names...) - return convert.ToStringSlice(v) -} - -func (o Object) Set(key string, obj interface{}) { - if o == nil { - return - } - o[key] = obj -} - -func (o Object) SetNested(obj interface{}, key ...string) { - PutValue(o, obj, key...) -} - -func (o Object) Bool(key ...string) bool { - return convert.ToBool(GetValueN(o, key...)) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/data/merge.go b/vendor/github.com/rancher/wrangler/pkg/data/merge.go deleted file mode 100644 index 8e5de4c050..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/data/merge.go +++ /dev/null @@ -1,53 +0,0 @@ -package data - -func MergeMaps(base, overlay map[string]interface{}) map[string]interface{} { - result := map[string]interface{}{} - for k, v := range base { - result[k] = v - } - for k, v := range overlay { - if baseMap, overlayMap, bothMaps := bothMaps(result[k], v); bothMaps { - v = MergeMaps(baseMap, overlayMap) - } - result[k] = v - } - return result -} - -func bothMaps(left, right interface{}) (map[string]interface{}, map[string]interface{}, bool) { - leftMap, ok := left.(map[string]interface{}) - if !ok { - return nil, nil, false - } - rightMap, ok := right.(map[string]interface{}) - return leftMap, rightMap, ok -} - -func bothSlices(left, right interface{}) ([]interface{}, []interface{}, bool) { - leftSlice, ok := left.([]interface{}) - if !ok { - return nil, nil, false - } - rightSlice, ok := right.([]interface{}) - return leftSlice, rightSlice, ok -} - -func MergeMapsConcatSlice(base, overlay map[string]interface{}) map[string]interface{} { - result := map[string]interface{}{} - for k, v := range base { - result[k] = v - } - for k, v := range overlay { - if baseMap, overlayMap, bothMaps := bothMaps(result[k], v); bothMaps { - v = MergeMaps(baseMap, overlayMap) - } else if baseSlice, overlaySlice, bothSlices := bothSlices(result[k], v); bothSlices { - s := make([]interface{}, 0, len(baseSlice)+len(overlaySlice)) - s = append(s, baseSlice...) - s = append(s, overlaySlice...) - v = s - } - result[k] = v - } - return result - -} diff --git a/vendor/github.com/rancher/wrangler/pkg/data/values.go b/vendor/github.com/rancher/wrangler/pkg/data/values.go deleted file mode 100644 index 87ff6159f7..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/data/values.go +++ /dev/null @@ -1,58 +0,0 @@ -package data - -func RemoveValue(data map[string]interface{}, keys ...string) (interface{}, bool) { - for i, key := range keys { - if i == len(keys)-1 { - val, ok := data[key] - delete(data, key) - return val, ok - } - data, _ = data[key].(map[string]interface{}) - } - - return nil, false -} - -func GetValueN(data map[string]interface{}, keys ...string) interface{} { - val, _ := GetValue(data, keys...) - return val -} - -func GetValue(data map[string]interface{}, keys ...string) (interface{}, bool) { - for i, key := range keys { - if i == len(keys)-1 { - val, ok := data[key] - return val, ok - } - data, _ = data[key].(map[string]interface{}) - } - - return nil, false -} - -func PutValue(data map[string]interface{}, val interface{}, keys ...string) { - if data == nil { - return - } - - // This is so ugly - for i, key := range keys { - if i == len(keys)-1 { - data[key] = val - } else { - newData, ok := data[key] - if ok { - newMap, ok := newData.(map[string]interface{}) - if ok { - data = newMap - } else { - return - } - } else { - newMap := map[string]interface{}{} - data[key] = newMap - data = newMap - } - } - } -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1/mutatingwebhookconfiguration.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1/mutatingwebhookconfiguration.go deleted file mode 100644 index 5da43d712b..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1/mutatingwebhookconfiguration.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/admissionregistration/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type MutatingWebhookConfigurationHandler func(string, *v1.MutatingWebhookConfiguration) (*v1.MutatingWebhookConfiguration, error) - -type MutatingWebhookConfigurationController interface { - generic.ControllerMeta - MutatingWebhookConfigurationClient - - OnChange(ctx context.Context, name string, sync MutatingWebhookConfigurationHandler) - OnRemove(ctx context.Context, name string, sync MutatingWebhookConfigurationHandler) - Enqueue(name string) - EnqueueAfter(name string, duration time.Duration) - - Cache() MutatingWebhookConfigurationCache -} - -type MutatingWebhookConfigurationClient interface { - Create(*v1.MutatingWebhookConfiguration) (*v1.MutatingWebhookConfiguration, error) - Update(*v1.MutatingWebhookConfiguration) (*v1.MutatingWebhookConfiguration, error) - - Delete(name string, options *metav1.DeleteOptions) error - Get(name string, options metav1.GetOptions) (*v1.MutatingWebhookConfiguration, error) - List(opts metav1.ListOptions) (*v1.MutatingWebhookConfigurationList, error) - Watch(opts metav1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.MutatingWebhookConfiguration, err error) -} - -type MutatingWebhookConfigurationCache interface { - Get(name string) (*v1.MutatingWebhookConfiguration, error) - List(selector labels.Selector) ([]*v1.MutatingWebhookConfiguration, error) - - AddIndexer(indexName string, indexer MutatingWebhookConfigurationIndexer) - GetByIndex(indexName, key string) ([]*v1.MutatingWebhookConfiguration, error) -} - -type MutatingWebhookConfigurationIndexer func(obj *v1.MutatingWebhookConfiguration) ([]string, error) - -type mutatingWebhookConfigurationController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewMutatingWebhookConfigurationController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) MutatingWebhookConfigurationController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &mutatingWebhookConfigurationController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromMutatingWebhookConfigurationHandlerToHandler(sync MutatingWebhookConfigurationHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.MutatingWebhookConfiguration - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.MutatingWebhookConfiguration)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *mutatingWebhookConfigurationController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.MutatingWebhookConfiguration)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateMutatingWebhookConfigurationDeepCopyOnChange(client MutatingWebhookConfigurationClient, obj *v1.MutatingWebhookConfiguration, handler func(obj *v1.MutatingWebhookConfiguration) (*v1.MutatingWebhookConfiguration, error)) (*v1.MutatingWebhookConfiguration, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *mutatingWebhookConfigurationController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *mutatingWebhookConfigurationController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *mutatingWebhookConfigurationController) OnChange(ctx context.Context, name string, sync MutatingWebhookConfigurationHandler) { - c.AddGenericHandler(ctx, name, FromMutatingWebhookConfigurationHandlerToHandler(sync)) -} - -func (c *mutatingWebhookConfigurationController) OnRemove(ctx context.Context, name string, sync MutatingWebhookConfigurationHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromMutatingWebhookConfigurationHandlerToHandler(sync))) -} - -func (c *mutatingWebhookConfigurationController) Enqueue(name string) { - c.controller.Enqueue("", name) -} - -func (c *mutatingWebhookConfigurationController) EnqueueAfter(name string, duration time.Duration) { - c.controller.EnqueueAfter("", name, duration) -} - -func (c *mutatingWebhookConfigurationController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *mutatingWebhookConfigurationController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *mutatingWebhookConfigurationController) Cache() MutatingWebhookConfigurationCache { - return &mutatingWebhookConfigurationCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *mutatingWebhookConfigurationController) Create(obj *v1.MutatingWebhookConfiguration) (*v1.MutatingWebhookConfiguration, error) { - result := &v1.MutatingWebhookConfiguration{} - return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{}) -} - -func (c *mutatingWebhookConfigurationController) Update(obj *v1.MutatingWebhookConfiguration) (*v1.MutatingWebhookConfiguration, error) { - result := &v1.MutatingWebhookConfiguration{} - return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *mutatingWebhookConfigurationController) Delete(name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), "", name, *options) -} - -func (c *mutatingWebhookConfigurationController) Get(name string, options metav1.GetOptions) (*v1.MutatingWebhookConfiguration, error) { - result := &v1.MutatingWebhookConfiguration{} - return result, c.client.Get(context.TODO(), "", name, result, options) -} - -func (c *mutatingWebhookConfigurationController) List(opts metav1.ListOptions) (*v1.MutatingWebhookConfigurationList, error) { - result := &v1.MutatingWebhookConfigurationList{} - return result, c.client.List(context.TODO(), "", result, opts) -} - -func (c *mutatingWebhookConfigurationController) Watch(opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), "", opts) -} - -func (c *mutatingWebhookConfigurationController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.MutatingWebhookConfiguration, error) { - result := &v1.MutatingWebhookConfiguration{} - return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type mutatingWebhookConfigurationCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *mutatingWebhookConfigurationCache) Get(name string) (*v1.MutatingWebhookConfiguration, error) { - obj, exists, err := c.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.MutatingWebhookConfiguration), nil -} - -func (c *mutatingWebhookConfigurationCache) List(selector labels.Selector) (ret []*v1.MutatingWebhookConfiguration, err error) { - - err = cache.ListAll(c.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.MutatingWebhookConfiguration)) - }) - - return ret, err -} - -func (c *mutatingWebhookConfigurationCache) AddIndexer(indexName string, indexer MutatingWebhookConfigurationIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.MutatingWebhookConfiguration)) - }, - })) -} - -func (c *mutatingWebhookConfigurationCache) GetByIndex(indexName, key string) (result []*v1.MutatingWebhookConfiguration, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.MutatingWebhookConfiguration, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.MutatingWebhookConfiguration)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1/validatingwebhookconfiguration.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1/validatingwebhookconfiguration.go deleted file mode 100644 index 1d8aa0445b..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1/validatingwebhookconfiguration.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/admissionregistration/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type ValidatingWebhookConfigurationHandler func(string, *v1.ValidatingWebhookConfiguration) (*v1.ValidatingWebhookConfiguration, error) - -type ValidatingWebhookConfigurationController interface { - generic.ControllerMeta - ValidatingWebhookConfigurationClient - - OnChange(ctx context.Context, name string, sync ValidatingWebhookConfigurationHandler) - OnRemove(ctx context.Context, name string, sync ValidatingWebhookConfigurationHandler) - Enqueue(name string) - EnqueueAfter(name string, duration time.Duration) - - Cache() ValidatingWebhookConfigurationCache -} - -type ValidatingWebhookConfigurationClient interface { - Create(*v1.ValidatingWebhookConfiguration) (*v1.ValidatingWebhookConfiguration, error) - Update(*v1.ValidatingWebhookConfiguration) (*v1.ValidatingWebhookConfiguration, error) - - Delete(name string, options *metav1.DeleteOptions) error - Get(name string, options metav1.GetOptions) (*v1.ValidatingWebhookConfiguration, error) - List(opts metav1.ListOptions) (*v1.ValidatingWebhookConfigurationList, error) - Watch(opts metav1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ValidatingWebhookConfiguration, err error) -} - -type ValidatingWebhookConfigurationCache interface { - Get(name string) (*v1.ValidatingWebhookConfiguration, error) - List(selector labels.Selector) ([]*v1.ValidatingWebhookConfiguration, error) - - AddIndexer(indexName string, indexer ValidatingWebhookConfigurationIndexer) - GetByIndex(indexName, key string) ([]*v1.ValidatingWebhookConfiguration, error) -} - -type ValidatingWebhookConfigurationIndexer func(obj *v1.ValidatingWebhookConfiguration) ([]string, error) - -type validatingWebhookConfigurationController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewValidatingWebhookConfigurationController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ValidatingWebhookConfigurationController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &validatingWebhookConfigurationController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromValidatingWebhookConfigurationHandlerToHandler(sync ValidatingWebhookConfigurationHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.ValidatingWebhookConfiguration - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.ValidatingWebhookConfiguration)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *validatingWebhookConfigurationController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.ValidatingWebhookConfiguration)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateValidatingWebhookConfigurationDeepCopyOnChange(client ValidatingWebhookConfigurationClient, obj *v1.ValidatingWebhookConfiguration, handler func(obj *v1.ValidatingWebhookConfiguration) (*v1.ValidatingWebhookConfiguration, error)) (*v1.ValidatingWebhookConfiguration, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *validatingWebhookConfigurationController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *validatingWebhookConfigurationController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *validatingWebhookConfigurationController) OnChange(ctx context.Context, name string, sync ValidatingWebhookConfigurationHandler) { - c.AddGenericHandler(ctx, name, FromValidatingWebhookConfigurationHandlerToHandler(sync)) -} - -func (c *validatingWebhookConfigurationController) OnRemove(ctx context.Context, name string, sync ValidatingWebhookConfigurationHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromValidatingWebhookConfigurationHandlerToHandler(sync))) -} - -func (c *validatingWebhookConfigurationController) Enqueue(name string) { - c.controller.Enqueue("", name) -} - -func (c *validatingWebhookConfigurationController) EnqueueAfter(name string, duration time.Duration) { - c.controller.EnqueueAfter("", name, duration) -} - -func (c *validatingWebhookConfigurationController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *validatingWebhookConfigurationController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *validatingWebhookConfigurationController) Cache() ValidatingWebhookConfigurationCache { - return &validatingWebhookConfigurationCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *validatingWebhookConfigurationController) Create(obj *v1.ValidatingWebhookConfiguration) (*v1.ValidatingWebhookConfiguration, error) { - result := &v1.ValidatingWebhookConfiguration{} - return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{}) -} - -func (c *validatingWebhookConfigurationController) Update(obj *v1.ValidatingWebhookConfiguration) (*v1.ValidatingWebhookConfiguration, error) { - result := &v1.ValidatingWebhookConfiguration{} - return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *validatingWebhookConfigurationController) Delete(name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), "", name, *options) -} - -func (c *validatingWebhookConfigurationController) Get(name string, options metav1.GetOptions) (*v1.ValidatingWebhookConfiguration, error) { - result := &v1.ValidatingWebhookConfiguration{} - return result, c.client.Get(context.TODO(), "", name, result, options) -} - -func (c *validatingWebhookConfigurationController) List(opts metav1.ListOptions) (*v1.ValidatingWebhookConfigurationList, error) { - result := &v1.ValidatingWebhookConfigurationList{} - return result, c.client.List(context.TODO(), "", result, opts) -} - -func (c *validatingWebhookConfigurationController) Watch(opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), "", opts) -} - -func (c *validatingWebhookConfigurationController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.ValidatingWebhookConfiguration, error) { - result := &v1.ValidatingWebhookConfiguration{} - return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type validatingWebhookConfigurationCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *validatingWebhookConfigurationCache) Get(name string) (*v1.ValidatingWebhookConfiguration, error) { - obj, exists, err := c.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.ValidatingWebhookConfiguration), nil -} - -func (c *validatingWebhookConfigurationCache) List(selector labels.Selector) (ret []*v1.ValidatingWebhookConfiguration, err error) { - - err = cache.ListAll(c.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ValidatingWebhookConfiguration)) - }) - - return ret, err -} - -func (c *validatingWebhookConfigurationCache) AddIndexer(indexName string, indexer ValidatingWebhookConfigurationIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.ValidatingWebhookConfiguration)) - }, - })) -} - -func (c *validatingWebhookConfigurationCache) GetByIndex(indexName, key string) (result []*v1.ValidatingWebhookConfiguration, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.ValidatingWebhookConfiguration, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.ValidatingWebhookConfiguration)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1/customresourcedefinition.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1/customresourcedefinition.go deleted file mode 100644 index 1d57b7c1b3..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1/customresourcedefinition.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type CustomResourceDefinitionHandler func(string, *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) - -type CustomResourceDefinitionController interface { - generic.ControllerMeta - CustomResourceDefinitionClient - - OnChange(ctx context.Context, name string, sync CustomResourceDefinitionHandler) - OnRemove(ctx context.Context, name string, sync CustomResourceDefinitionHandler) - Enqueue(name string) - EnqueueAfter(name string, duration time.Duration) - - Cache() CustomResourceDefinitionCache -} - -type CustomResourceDefinitionClient interface { - Create(*v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) - Update(*v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) - UpdateStatus(*v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) - Delete(name string, options *metav1.DeleteOptions) error - Get(name string, options metav1.GetOptions) (*v1.CustomResourceDefinition, error) - List(opts metav1.ListOptions) (*v1.CustomResourceDefinitionList, error) - Watch(opts metav1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.CustomResourceDefinition, err error) -} - -type CustomResourceDefinitionCache interface { - Get(name string) (*v1.CustomResourceDefinition, error) - List(selector labels.Selector) ([]*v1.CustomResourceDefinition, error) - - AddIndexer(indexName string, indexer CustomResourceDefinitionIndexer) - GetByIndex(indexName, key string) ([]*v1.CustomResourceDefinition, error) -} - -type CustomResourceDefinitionIndexer func(obj *v1.CustomResourceDefinition) ([]string, error) - -type customResourceDefinitionController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewCustomResourceDefinitionController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) CustomResourceDefinitionController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &customResourceDefinitionController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromCustomResourceDefinitionHandlerToHandler(sync CustomResourceDefinitionHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.CustomResourceDefinition - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.CustomResourceDefinition)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *customResourceDefinitionController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.CustomResourceDefinition)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateCustomResourceDefinitionDeepCopyOnChange(client CustomResourceDefinitionClient, obj *v1.CustomResourceDefinition, handler func(obj *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error)) (*v1.CustomResourceDefinition, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *customResourceDefinitionController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *customResourceDefinitionController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *customResourceDefinitionController) OnChange(ctx context.Context, name string, sync CustomResourceDefinitionHandler) { - c.AddGenericHandler(ctx, name, FromCustomResourceDefinitionHandlerToHandler(sync)) -} - -func (c *customResourceDefinitionController) OnRemove(ctx context.Context, name string, sync CustomResourceDefinitionHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromCustomResourceDefinitionHandlerToHandler(sync))) -} - -func (c *customResourceDefinitionController) Enqueue(name string) { - c.controller.Enqueue("", name) -} - -func (c *customResourceDefinitionController) EnqueueAfter(name string, duration time.Duration) { - c.controller.EnqueueAfter("", name, duration) -} - -func (c *customResourceDefinitionController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *customResourceDefinitionController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *customResourceDefinitionController) Cache() CustomResourceDefinitionCache { - return &customResourceDefinitionCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *customResourceDefinitionController) Create(obj *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) { - result := &v1.CustomResourceDefinition{} - return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{}) -} - -func (c *customResourceDefinitionController) Update(obj *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) { - result := &v1.CustomResourceDefinition{} - return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *customResourceDefinitionController) UpdateStatus(obj *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) { - result := &v1.CustomResourceDefinition{} - return result, c.client.UpdateStatus(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *customResourceDefinitionController) Delete(name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), "", name, *options) -} - -func (c *customResourceDefinitionController) Get(name string, options metav1.GetOptions) (*v1.CustomResourceDefinition, error) { - result := &v1.CustomResourceDefinition{} - return result, c.client.Get(context.TODO(), "", name, result, options) -} - -func (c *customResourceDefinitionController) List(opts metav1.ListOptions) (*v1.CustomResourceDefinitionList, error) { - result := &v1.CustomResourceDefinitionList{} - return result, c.client.List(context.TODO(), "", result, opts) -} - -func (c *customResourceDefinitionController) Watch(opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), "", opts) -} - -func (c *customResourceDefinitionController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.CustomResourceDefinition, error) { - result := &v1.CustomResourceDefinition{} - return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type customResourceDefinitionCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *customResourceDefinitionCache) Get(name string) (*v1.CustomResourceDefinition, error) { - obj, exists, err := c.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.CustomResourceDefinition), nil -} - -func (c *customResourceDefinitionCache) List(selector labels.Selector) (ret []*v1.CustomResourceDefinition, err error) { - - err = cache.ListAll(c.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.CustomResourceDefinition)) - }) - - return ret, err -} - -func (c *customResourceDefinitionCache) AddIndexer(indexName string, indexer CustomResourceDefinitionIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.CustomResourceDefinition)) - }, - })) -} - -func (c *customResourceDefinitionCache) GetByIndex(indexName, key string) (result []*v1.CustomResourceDefinition, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.CustomResourceDefinition, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.CustomResourceDefinition)) - } - return result, nil -} - -// CustomResourceDefinitionStatusHandler is executed for every added or modified CustomResourceDefinition. Should return the new status to be updated -type CustomResourceDefinitionStatusHandler func(obj *v1.CustomResourceDefinition, status v1.CustomResourceDefinitionStatus) (v1.CustomResourceDefinitionStatus, error) - -// CustomResourceDefinitionGeneratingHandler is the top-level handler that is executed for every CustomResourceDefinition event. It extends CustomResourceDefinitionStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type CustomResourceDefinitionGeneratingHandler func(obj *v1.CustomResourceDefinition, status v1.CustomResourceDefinitionStatus) ([]runtime.Object, v1.CustomResourceDefinitionStatus, error) - -// RegisterCustomResourceDefinitionStatusHandler configures a CustomResourceDefinitionController to execute a CustomResourceDefinitionStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterCustomResourceDefinitionStatusHandler(ctx context.Context, controller CustomResourceDefinitionController, condition condition.Cond, name string, handler CustomResourceDefinitionStatusHandler) { - statusHandler := &customResourceDefinitionStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromCustomResourceDefinitionHandlerToHandler(statusHandler.sync)) -} - -// RegisterCustomResourceDefinitionGeneratingHandler configures a CustomResourceDefinitionController to execute a CustomResourceDefinitionGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterCustomResourceDefinitionGeneratingHandler(ctx context.Context, controller CustomResourceDefinitionController, apply apply.Apply, - condition condition.Cond, name string, handler CustomResourceDefinitionGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &customResourceDefinitionGeneratingHandler{ - CustomResourceDefinitionGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterCustomResourceDefinitionStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type customResourceDefinitionStatusHandler struct { - client CustomResourceDefinitionClient - condition condition.Cond - handler CustomResourceDefinitionStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *customResourceDefinitionStatusHandler) sync(key string, obj *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type customResourceDefinitionGeneratingHandler struct { - CustomResourceDefinitionGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *customResourceDefinitionGeneratingHandler) Remove(key string, obj *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.CustomResourceDefinition{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured CustomResourceDefinitionGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *customResourceDefinitionGeneratingHandler) Handle(obj *v1.CustomResourceDefinition, status v1.CustomResourceDefinitionStatus) (v1.CustomResourceDefinitionStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.CustomResourceDefinitionGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *customResourceDefinitionGeneratingHandler) isNewResourceVersion(obj *v1.CustomResourceDefinition) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *customResourceDefinitionGeneratingHandler) storeResourceVersion(obj *v1.CustomResourceDefinition) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/v1/apiservice.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/v1/apiservice.go deleted file mode 100644 index eda87f4872..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/v1/apiservice.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" - v1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" -) - -type APIServiceHandler func(string, *v1.APIService) (*v1.APIService, error) - -type APIServiceController interface { - generic.ControllerMeta - APIServiceClient - - OnChange(ctx context.Context, name string, sync APIServiceHandler) - OnRemove(ctx context.Context, name string, sync APIServiceHandler) - Enqueue(name string) - EnqueueAfter(name string, duration time.Duration) - - Cache() APIServiceCache -} - -type APIServiceClient interface { - Create(*v1.APIService) (*v1.APIService, error) - Update(*v1.APIService) (*v1.APIService, error) - UpdateStatus(*v1.APIService) (*v1.APIService, error) - Delete(name string, options *metav1.DeleteOptions) error - Get(name string, options metav1.GetOptions) (*v1.APIService, error) - List(opts metav1.ListOptions) (*v1.APIServiceList, error) - Watch(opts metav1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.APIService, err error) -} - -type APIServiceCache interface { - Get(name string) (*v1.APIService, error) - List(selector labels.Selector) ([]*v1.APIService, error) - - AddIndexer(indexName string, indexer APIServiceIndexer) - GetByIndex(indexName, key string) ([]*v1.APIService, error) -} - -type APIServiceIndexer func(obj *v1.APIService) ([]string, error) - -type aPIServiceController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewAPIServiceController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) APIServiceController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &aPIServiceController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromAPIServiceHandlerToHandler(sync APIServiceHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.APIService - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.APIService)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *aPIServiceController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.APIService)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateAPIServiceDeepCopyOnChange(client APIServiceClient, obj *v1.APIService, handler func(obj *v1.APIService) (*v1.APIService, error)) (*v1.APIService, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *aPIServiceController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *aPIServiceController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *aPIServiceController) OnChange(ctx context.Context, name string, sync APIServiceHandler) { - c.AddGenericHandler(ctx, name, FromAPIServiceHandlerToHandler(sync)) -} - -func (c *aPIServiceController) OnRemove(ctx context.Context, name string, sync APIServiceHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromAPIServiceHandlerToHandler(sync))) -} - -func (c *aPIServiceController) Enqueue(name string) { - c.controller.Enqueue("", name) -} - -func (c *aPIServiceController) EnqueueAfter(name string, duration time.Duration) { - c.controller.EnqueueAfter("", name, duration) -} - -func (c *aPIServiceController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *aPIServiceController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *aPIServiceController) Cache() APIServiceCache { - return &aPIServiceCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *aPIServiceController) Create(obj *v1.APIService) (*v1.APIService, error) { - result := &v1.APIService{} - return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{}) -} - -func (c *aPIServiceController) Update(obj *v1.APIService) (*v1.APIService, error) { - result := &v1.APIService{} - return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *aPIServiceController) UpdateStatus(obj *v1.APIService) (*v1.APIService, error) { - result := &v1.APIService{} - return result, c.client.UpdateStatus(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *aPIServiceController) Delete(name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), "", name, *options) -} - -func (c *aPIServiceController) Get(name string, options metav1.GetOptions) (*v1.APIService, error) { - result := &v1.APIService{} - return result, c.client.Get(context.TODO(), "", name, result, options) -} - -func (c *aPIServiceController) List(opts metav1.ListOptions) (*v1.APIServiceList, error) { - result := &v1.APIServiceList{} - return result, c.client.List(context.TODO(), "", result, opts) -} - -func (c *aPIServiceController) Watch(opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), "", opts) -} - -func (c *aPIServiceController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.APIService, error) { - result := &v1.APIService{} - return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type aPIServiceCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *aPIServiceCache) Get(name string) (*v1.APIService, error) { - obj, exists, err := c.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.APIService), nil -} - -func (c *aPIServiceCache) List(selector labels.Selector) (ret []*v1.APIService, err error) { - - err = cache.ListAll(c.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.APIService)) - }) - - return ret, err -} - -func (c *aPIServiceCache) AddIndexer(indexName string, indexer APIServiceIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.APIService)) - }, - })) -} - -func (c *aPIServiceCache) GetByIndex(indexName, key string) (result []*v1.APIService, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.APIService, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.APIService)) - } - return result, nil -} - -// APIServiceStatusHandler is executed for every added or modified APIService. Should return the new status to be updated -type APIServiceStatusHandler func(obj *v1.APIService, status v1.APIServiceStatus) (v1.APIServiceStatus, error) - -// APIServiceGeneratingHandler is the top-level handler that is executed for every APIService event. It extends APIServiceStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type APIServiceGeneratingHandler func(obj *v1.APIService, status v1.APIServiceStatus) ([]runtime.Object, v1.APIServiceStatus, error) - -// RegisterAPIServiceStatusHandler configures a APIServiceController to execute a APIServiceStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterAPIServiceStatusHandler(ctx context.Context, controller APIServiceController, condition condition.Cond, name string, handler APIServiceStatusHandler) { - statusHandler := &aPIServiceStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromAPIServiceHandlerToHandler(statusHandler.sync)) -} - -// RegisterAPIServiceGeneratingHandler configures a APIServiceController to execute a APIServiceGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterAPIServiceGeneratingHandler(ctx context.Context, controller APIServiceController, apply apply.Apply, - condition condition.Cond, name string, handler APIServiceGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &aPIServiceGeneratingHandler{ - APIServiceGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterAPIServiceStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type aPIServiceStatusHandler struct { - client APIServiceClient - condition condition.Cond - handler APIServiceStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *aPIServiceStatusHandler) sync(key string, obj *v1.APIService) (*v1.APIService, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type aPIServiceGeneratingHandler struct { - APIServiceGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *aPIServiceGeneratingHandler) Remove(key string, obj *v1.APIService) (*v1.APIService, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.APIService{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured APIServiceGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *aPIServiceGeneratingHandler) Handle(obj *v1.APIService, status v1.APIServiceStatus) (v1.APIServiceStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.APIServiceGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *aPIServiceGeneratingHandler) isNewResourceVersion(obj *v1.APIService) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *aPIServiceGeneratingHandler) storeResourceVersion(obj *v1.APIService) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/daemonset.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/daemonset.go deleted file mode 100644 index 2eb133d41a..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/daemonset.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/api/apps/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type DaemonSetHandler func(string, *v1.DaemonSet) (*v1.DaemonSet, error) - -type DaemonSetController interface { - generic.ControllerMeta - DaemonSetClient - - OnChange(ctx context.Context, name string, sync DaemonSetHandler) - OnRemove(ctx context.Context, name string, sync DaemonSetHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() DaemonSetCache -} - -type DaemonSetClient interface { - Create(*v1.DaemonSet) (*v1.DaemonSet, error) - Update(*v1.DaemonSet) (*v1.DaemonSet, error) - UpdateStatus(*v1.DaemonSet) (*v1.DaemonSet, error) - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.DaemonSet, error) - List(namespace string, opts metav1.ListOptions) (*v1.DaemonSetList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.DaemonSet, err error) -} - -type DaemonSetCache interface { - Get(namespace, name string) (*v1.DaemonSet, error) - List(namespace string, selector labels.Selector) ([]*v1.DaemonSet, error) - - AddIndexer(indexName string, indexer DaemonSetIndexer) - GetByIndex(indexName, key string) ([]*v1.DaemonSet, error) -} - -type DaemonSetIndexer func(obj *v1.DaemonSet) ([]string, error) - -type daemonSetController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewDaemonSetController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) DaemonSetController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &daemonSetController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromDaemonSetHandlerToHandler(sync DaemonSetHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.DaemonSet - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.DaemonSet)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *daemonSetController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.DaemonSet)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateDaemonSetDeepCopyOnChange(client DaemonSetClient, obj *v1.DaemonSet, handler func(obj *v1.DaemonSet) (*v1.DaemonSet, error)) (*v1.DaemonSet, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *daemonSetController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *daemonSetController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *daemonSetController) OnChange(ctx context.Context, name string, sync DaemonSetHandler) { - c.AddGenericHandler(ctx, name, FromDaemonSetHandlerToHandler(sync)) -} - -func (c *daemonSetController) OnRemove(ctx context.Context, name string, sync DaemonSetHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromDaemonSetHandlerToHandler(sync))) -} - -func (c *daemonSetController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *daemonSetController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *daemonSetController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *daemonSetController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *daemonSetController) Cache() DaemonSetCache { - return &daemonSetCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *daemonSetController) Create(obj *v1.DaemonSet) (*v1.DaemonSet, error) { - result := &v1.DaemonSet{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *daemonSetController) Update(obj *v1.DaemonSet) (*v1.DaemonSet, error) { - result := &v1.DaemonSet{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *daemonSetController) UpdateStatus(obj *v1.DaemonSet) (*v1.DaemonSet, error) { - result := &v1.DaemonSet{} - return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *daemonSetController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *daemonSetController) Get(namespace, name string, options metav1.GetOptions) (*v1.DaemonSet, error) { - result := &v1.DaemonSet{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *daemonSetController) List(namespace string, opts metav1.ListOptions) (*v1.DaemonSetList, error) { - result := &v1.DaemonSetList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *daemonSetController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *daemonSetController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.DaemonSet, error) { - result := &v1.DaemonSet{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type daemonSetCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *daemonSetCache) Get(namespace, name string) (*v1.DaemonSet, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.DaemonSet), nil -} - -func (c *daemonSetCache) List(namespace string, selector labels.Selector) (ret []*v1.DaemonSet, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.DaemonSet)) - }) - - return ret, err -} - -func (c *daemonSetCache) AddIndexer(indexName string, indexer DaemonSetIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.DaemonSet)) - }, - })) -} - -func (c *daemonSetCache) GetByIndex(indexName, key string) (result []*v1.DaemonSet, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.DaemonSet, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.DaemonSet)) - } - return result, nil -} - -// DaemonSetStatusHandler is executed for every added or modified DaemonSet. Should return the new status to be updated -type DaemonSetStatusHandler func(obj *v1.DaemonSet, status v1.DaemonSetStatus) (v1.DaemonSetStatus, error) - -// DaemonSetGeneratingHandler is the top-level handler that is executed for every DaemonSet event. It extends DaemonSetStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type DaemonSetGeneratingHandler func(obj *v1.DaemonSet, status v1.DaemonSetStatus) ([]runtime.Object, v1.DaemonSetStatus, error) - -// RegisterDaemonSetStatusHandler configures a DaemonSetController to execute a DaemonSetStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterDaemonSetStatusHandler(ctx context.Context, controller DaemonSetController, condition condition.Cond, name string, handler DaemonSetStatusHandler) { - statusHandler := &daemonSetStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromDaemonSetHandlerToHandler(statusHandler.sync)) -} - -// RegisterDaemonSetGeneratingHandler configures a DaemonSetController to execute a DaemonSetGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterDaemonSetGeneratingHandler(ctx context.Context, controller DaemonSetController, apply apply.Apply, - condition condition.Cond, name string, handler DaemonSetGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &daemonSetGeneratingHandler{ - DaemonSetGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterDaemonSetStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type daemonSetStatusHandler struct { - client DaemonSetClient - condition condition.Cond - handler DaemonSetStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *daemonSetStatusHandler) sync(key string, obj *v1.DaemonSet) (*v1.DaemonSet, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type daemonSetGeneratingHandler struct { - DaemonSetGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *daemonSetGeneratingHandler) Remove(key string, obj *v1.DaemonSet) (*v1.DaemonSet, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.DaemonSet{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured DaemonSetGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *daemonSetGeneratingHandler) Handle(obj *v1.DaemonSet, status v1.DaemonSetStatus) (v1.DaemonSetStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.DaemonSetGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *daemonSetGeneratingHandler) isNewResourceVersion(obj *v1.DaemonSet) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *daemonSetGeneratingHandler) storeResourceVersion(obj *v1.DaemonSet) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/deployment.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/deployment.go deleted file mode 100644 index c067aa5ba6..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/deployment.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/api/apps/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type DeploymentHandler func(string, *v1.Deployment) (*v1.Deployment, error) - -type DeploymentController interface { - generic.ControllerMeta - DeploymentClient - - OnChange(ctx context.Context, name string, sync DeploymentHandler) - OnRemove(ctx context.Context, name string, sync DeploymentHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() DeploymentCache -} - -type DeploymentClient interface { - Create(*v1.Deployment) (*v1.Deployment, error) - Update(*v1.Deployment) (*v1.Deployment, error) - UpdateStatus(*v1.Deployment) (*v1.Deployment, error) - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.Deployment, error) - List(namespace string, opts metav1.ListOptions) (*v1.DeploymentList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Deployment, err error) -} - -type DeploymentCache interface { - Get(namespace, name string) (*v1.Deployment, error) - List(namespace string, selector labels.Selector) ([]*v1.Deployment, error) - - AddIndexer(indexName string, indexer DeploymentIndexer) - GetByIndex(indexName, key string) ([]*v1.Deployment, error) -} - -type DeploymentIndexer func(obj *v1.Deployment) ([]string, error) - -type deploymentController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewDeploymentController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) DeploymentController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &deploymentController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromDeploymentHandlerToHandler(sync DeploymentHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.Deployment - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.Deployment)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *deploymentController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.Deployment)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateDeploymentDeepCopyOnChange(client DeploymentClient, obj *v1.Deployment, handler func(obj *v1.Deployment) (*v1.Deployment, error)) (*v1.Deployment, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *deploymentController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *deploymentController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *deploymentController) OnChange(ctx context.Context, name string, sync DeploymentHandler) { - c.AddGenericHandler(ctx, name, FromDeploymentHandlerToHandler(sync)) -} - -func (c *deploymentController) OnRemove(ctx context.Context, name string, sync DeploymentHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromDeploymentHandlerToHandler(sync))) -} - -func (c *deploymentController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *deploymentController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *deploymentController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *deploymentController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *deploymentController) Cache() DeploymentCache { - return &deploymentCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *deploymentController) Create(obj *v1.Deployment) (*v1.Deployment, error) { - result := &v1.Deployment{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *deploymentController) Update(obj *v1.Deployment) (*v1.Deployment, error) { - result := &v1.Deployment{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *deploymentController) UpdateStatus(obj *v1.Deployment) (*v1.Deployment, error) { - result := &v1.Deployment{} - return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *deploymentController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *deploymentController) Get(namespace, name string, options metav1.GetOptions) (*v1.Deployment, error) { - result := &v1.Deployment{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *deploymentController) List(namespace string, opts metav1.ListOptions) (*v1.DeploymentList, error) { - result := &v1.DeploymentList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *deploymentController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *deploymentController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Deployment, error) { - result := &v1.Deployment{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type deploymentCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *deploymentCache) Get(namespace, name string) (*v1.Deployment, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.Deployment), nil -} - -func (c *deploymentCache) List(namespace string, selector labels.Selector) (ret []*v1.Deployment, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Deployment)) - }) - - return ret, err -} - -func (c *deploymentCache) AddIndexer(indexName string, indexer DeploymentIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.Deployment)) - }, - })) -} - -func (c *deploymentCache) GetByIndex(indexName, key string) (result []*v1.Deployment, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.Deployment, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.Deployment)) - } - return result, nil -} - -// DeploymentStatusHandler is executed for every added or modified Deployment. Should return the new status to be updated -type DeploymentStatusHandler func(obj *v1.Deployment, status v1.DeploymentStatus) (v1.DeploymentStatus, error) - -// DeploymentGeneratingHandler is the top-level handler that is executed for every Deployment event. It extends DeploymentStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type DeploymentGeneratingHandler func(obj *v1.Deployment, status v1.DeploymentStatus) ([]runtime.Object, v1.DeploymentStatus, error) - -// RegisterDeploymentStatusHandler configures a DeploymentController to execute a DeploymentStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterDeploymentStatusHandler(ctx context.Context, controller DeploymentController, condition condition.Cond, name string, handler DeploymentStatusHandler) { - statusHandler := &deploymentStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromDeploymentHandlerToHandler(statusHandler.sync)) -} - -// RegisterDeploymentGeneratingHandler configures a DeploymentController to execute a DeploymentGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterDeploymentGeneratingHandler(ctx context.Context, controller DeploymentController, apply apply.Apply, - condition condition.Cond, name string, handler DeploymentGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &deploymentGeneratingHandler{ - DeploymentGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterDeploymentStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type deploymentStatusHandler struct { - client DeploymentClient - condition condition.Cond - handler DeploymentStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *deploymentStatusHandler) sync(key string, obj *v1.Deployment) (*v1.Deployment, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type deploymentGeneratingHandler struct { - DeploymentGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *deploymentGeneratingHandler) Remove(key string, obj *v1.Deployment) (*v1.Deployment, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.Deployment{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured DeploymentGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *deploymentGeneratingHandler) Handle(obj *v1.Deployment, status v1.DeploymentStatus) (v1.DeploymentStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.DeploymentGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *deploymentGeneratingHandler) isNewResourceVersion(obj *v1.Deployment) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *deploymentGeneratingHandler) storeResourceVersion(obj *v1.Deployment) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/statefulset.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/statefulset.go deleted file mode 100644 index 04a055aa1c..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/statefulset.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/api/apps/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type StatefulSetHandler func(string, *v1.StatefulSet) (*v1.StatefulSet, error) - -type StatefulSetController interface { - generic.ControllerMeta - StatefulSetClient - - OnChange(ctx context.Context, name string, sync StatefulSetHandler) - OnRemove(ctx context.Context, name string, sync StatefulSetHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() StatefulSetCache -} - -type StatefulSetClient interface { - Create(*v1.StatefulSet) (*v1.StatefulSet, error) - Update(*v1.StatefulSet) (*v1.StatefulSet, error) - UpdateStatus(*v1.StatefulSet) (*v1.StatefulSet, error) - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.StatefulSet, error) - List(namespace string, opts metav1.ListOptions) (*v1.StatefulSetList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.StatefulSet, err error) -} - -type StatefulSetCache interface { - Get(namespace, name string) (*v1.StatefulSet, error) - List(namespace string, selector labels.Selector) ([]*v1.StatefulSet, error) - - AddIndexer(indexName string, indexer StatefulSetIndexer) - GetByIndex(indexName, key string) ([]*v1.StatefulSet, error) -} - -type StatefulSetIndexer func(obj *v1.StatefulSet) ([]string, error) - -type statefulSetController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewStatefulSetController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) StatefulSetController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &statefulSetController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromStatefulSetHandlerToHandler(sync StatefulSetHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.StatefulSet - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.StatefulSet)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *statefulSetController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.StatefulSet)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateStatefulSetDeepCopyOnChange(client StatefulSetClient, obj *v1.StatefulSet, handler func(obj *v1.StatefulSet) (*v1.StatefulSet, error)) (*v1.StatefulSet, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *statefulSetController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *statefulSetController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *statefulSetController) OnChange(ctx context.Context, name string, sync StatefulSetHandler) { - c.AddGenericHandler(ctx, name, FromStatefulSetHandlerToHandler(sync)) -} - -func (c *statefulSetController) OnRemove(ctx context.Context, name string, sync StatefulSetHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromStatefulSetHandlerToHandler(sync))) -} - -func (c *statefulSetController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *statefulSetController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *statefulSetController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *statefulSetController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *statefulSetController) Cache() StatefulSetCache { - return &statefulSetCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *statefulSetController) Create(obj *v1.StatefulSet) (*v1.StatefulSet, error) { - result := &v1.StatefulSet{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *statefulSetController) Update(obj *v1.StatefulSet) (*v1.StatefulSet, error) { - result := &v1.StatefulSet{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *statefulSetController) UpdateStatus(obj *v1.StatefulSet) (*v1.StatefulSet, error) { - result := &v1.StatefulSet{} - return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *statefulSetController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *statefulSetController) Get(namespace, name string, options metav1.GetOptions) (*v1.StatefulSet, error) { - result := &v1.StatefulSet{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *statefulSetController) List(namespace string, opts metav1.ListOptions) (*v1.StatefulSetList, error) { - result := &v1.StatefulSetList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *statefulSetController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *statefulSetController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.StatefulSet, error) { - result := &v1.StatefulSet{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type statefulSetCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *statefulSetCache) Get(namespace, name string) (*v1.StatefulSet, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.StatefulSet), nil -} - -func (c *statefulSetCache) List(namespace string, selector labels.Selector) (ret []*v1.StatefulSet, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.StatefulSet)) - }) - - return ret, err -} - -func (c *statefulSetCache) AddIndexer(indexName string, indexer StatefulSetIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.StatefulSet)) - }, - })) -} - -func (c *statefulSetCache) GetByIndex(indexName, key string) (result []*v1.StatefulSet, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.StatefulSet, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.StatefulSet)) - } - return result, nil -} - -// StatefulSetStatusHandler is executed for every added or modified StatefulSet. Should return the new status to be updated -type StatefulSetStatusHandler func(obj *v1.StatefulSet, status v1.StatefulSetStatus) (v1.StatefulSetStatus, error) - -// StatefulSetGeneratingHandler is the top-level handler that is executed for every StatefulSet event. It extends StatefulSetStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type StatefulSetGeneratingHandler func(obj *v1.StatefulSet, status v1.StatefulSetStatus) ([]runtime.Object, v1.StatefulSetStatus, error) - -// RegisterStatefulSetStatusHandler configures a StatefulSetController to execute a StatefulSetStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterStatefulSetStatusHandler(ctx context.Context, controller StatefulSetController, condition condition.Cond, name string, handler StatefulSetStatusHandler) { - statusHandler := &statefulSetStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromStatefulSetHandlerToHandler(statusHandler.sync)) -} - -// RegisterStatefulSetGeneratingHandler configures a StatefulSetController to execute a StatefulSetGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterStatefulSetGeneratingHandler(ctx context.Context, controller StatefulSetController, apply apply.Apply, - condition condition.Cond, name string, handler StatefulSetGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &statefulSetGeneratingHandler{ - StatefulSetGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterStatefulSetStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type statefulSetStatusHandler struct { - client StatefulSetClient - condition condition.Cond - handler StatefulSetStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *statefulSetStatusHandler) sync(key string, obj *v1.StatefulSet) (*v1.StatefulSet, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type statefulSetGeneratingHandler struct { - StatefulSetGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *statefulSetGeneratingHandler) Remove(key string, obj *v1.StatefulSet) (*v1.StatefulSet, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.StatefulSet{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured StatefulSetGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *statefulSetGeneratingHandler) Handle(obj *v1.StatefulSet, status v1.StatefulSetStatus) (v1.StatefulSetStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.StatefulSetGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *statefulSetGeneratingHandler) isNewResourceVersion(obj *v1.StatefulSet) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *statefulSetGeneratingHandler) storeResourceVersion(obj *v1.StatefulSet) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/v1/job.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/v1/job.go deleted file mode 100644 index c97e79d48f..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/v1/job.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/api/batch/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type JobHandler func(string, *v1.Job) (*v1.Job, error) - -type JobController interface { - generic.ControllerMeta - JobClient - - OnChange(ctx context.Context, name string, sync JobHandler) - OnRemove(ctx context.Context, name string, sync JobHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() JobCache -} - -type JobClient interface { - Create(*v1.Job) (*v1.Job, error) - Update(*v1.Job) (*v1.Job, error) - UpdateStatus(*v1.Job) (*v1.Job, error) - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.Job, error) - List(namespace string, opts metav1.ListOptions) (*v1.JobList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Job, err error) -} - -type JobCache interface { - Get(namespace, name string) (*v1.Job, error) - List(namespace string, selector labels.Selector) ([]*v1.Job, error) - - AddIndexer(indexName string, indexer JobIndexer) - GetByIndex(indexName, key string) ([]*v1.Job, error) -} - -type JobIndexer func(obj *v1.Job) ([]string, error) - -type jobController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewJobController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) JobController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &jobController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromJobHandlerToHandler(sync JobHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.Job - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.Job)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *jobController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.Job)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateJobDeepCopyOnChange(client JobClient, obj *v1.Job, handler func(obj *v1.Job) (*v1.Job, error)) (*v1.Job, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *jobController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *jobController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *jobController) OnChange(ctx context.Context, name string, sync JobHandler) { - c.AddGenericHandler(ctx, name, FromJobHandlerToHandler(sync)) -} - -func (c *jobController) OnRemove(ctx context.Context, name string, sync JobHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromJobHandlerToHandler(sync))) -} - -func (c *jobController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *jobController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *jobController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *jobController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *jobController) Cache() JobCache { - return &jobCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *jobController) Create(obj *v1.Job) (*v1.Job, error) { - result := &v1.Job{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *jobController) Update(obj *v1.Job) (*v1.Job, error) { - result := &v1.Job{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *jobController) UpdateStatus(obj *v1.Job) (*v1.Job, error) { - result := &v1.Job{} - return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *jobController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *jobController) Get(namespace, name string, options metav1.GetOptions) (*v1.Job, error) { - result := &v1.Job{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *jobController) List(namespace string, opts metav1.ListOptions) (*v1.JobList, error) { - result := &v1.JobList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *jobController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *jobController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Job, error) { - result := &v1.Job{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type jobCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *jobCache) Get(namespace, name string) (*v1.Job, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.Job), nil -} - -func (c *jobCache) List(namespace string, selector labels.Selector) (ret []*v1.Job, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Job)) - }) - - return ret, err -} - -func (c *jobCache) AddIndexer(indexName string, indexer JobIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.Job)) - }, - })) -} - -func (c *jobCache) GetByIndex(indexName, key string) (result []*v1.Job, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.Job, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.Job)) - } - return result, nil -} - -// JobStatusHandler is executed for every added or modified Job. Should return the new status to be updated -type JobStatusHandler func(obj *v1.Job, status v1.JobStatus) (v1.JobStatus, error) - -// JobGeneratingHandler is the top-level handler that is executed for every Job event. It extends JobStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type JobGeneratingHandler func(obj *v1.Job, status v1.JobStatus) ([]runtime.Object, v1.JobStatus, error) - -// RegisterJobStatusHandler configures a JobController to execute a JobStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterJobStatusHandler(ctx context.Context, controller JobController, condition condition.Cond, name string, handler JobStatusHandler) { - statusHandler := &jobStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromJobHandlerToHandler(statusHandler.sync)) -} - -// RegisterJobGeneratingHandler configures a JobController to execute a JobGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterJobGeneratingHandler(ctx context.Context, controller JobController, apply apply.Apply, - condition condition.Cond, name string, handler JobGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &jobGeneratingHandler{ - JobGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterJobStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type jobStatusHandler struct { - client JobClient - condition condition.Cond - handler JobStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *jobStatusHandler) sync(key string, obj *v1.Job) (*v1.Job, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type jobGeneratingHandler struct { - JobGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *jobGeneratingHandler) Remove(key string, obj *v1.Job) (*v1.Job, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.Job{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured JobGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *jobGeneratingHandler) Handle(obj *v1.Job, status v1.JobStatus) (v1.JobStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.JobGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *jobGeneratingHandler) isNewResourceVersion(obj *v1.Job) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *jobGeneratingHandler) storeResourceVersion(obj *v1.Job) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/factory.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/factory.go deleted file mode 100644 index b19523b160..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/factory.go +++ /dev/null @@ -1,72 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package core - -import ( - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - "k8s.io/client-go/rest" -) - -type Factory struct { - *generic.Factory -} - -func NewFactoryFromConfigOrDie(config *rest.Config) *Factory { - f, err := NewFactoryFromConfig(config) - if err != nil { - panic(err) - } - return f -} - -func NewFactoryFromConfig(config *rest.Config) (*Factory, error) { - return NewFactoryFromConfigWithOptions(config, nil) -} - -func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*Factory, error) { - return NewFactoryFromConfigWithOptions(config, &FactoryOptions{ - Namespace: namespace, - }) -} - -type FactoryOptions = generic.FactoryOptions - -func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) { - f, err := generic.NewFactoryFromConfigWithOptions(config, opts) - return &Factory{ - Factory: f, - }, err -} - -func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory { - f, err := NewFactoryFromConfigWithOptions(config, opts) - if err != nil { - panic(err) - } - return f -} - -func (c *Factory) Core() Interface { - return New(c.ControllerFactory()) -} - -func (c *Factory) WithAgent(userAgent string) Interface { - return New(controller.NewSharedControllerFactoryWithAgent(userAgent, c.ControllerFactory())) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/configmap.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/configmap.go deleted file mode 100644 index d56e1d87b4..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/configmap.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type ConfigMapHandler func(string, *v1.ConfigMap) (*v1.ConfigMap, error) - -type ConfigMapController interface { - generic.ControllerMeta - ConfigMapClient - - OnChange(ctx context.Context, name string, sync ConfigMapHandler) - OnRemove(ctx context.Context, name string, sync ConfigMapHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() ConfigMapCache -} - -type ConfigMapClient interface { - Create(*v1.ConfigMap) (*v1.ConfigMap, error) - Update(*v1.ConfigMap) (*v1.ConfigMap, error) - - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.ConfigMap, error) - List(namespace string, opts metav1.ListOptions) (*v1.ConfigMapList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ConfigMap, err error) -} - -type ConfigMapCache interface { - Get(namespace, name string) (*v1.ConfigMap, error) - List(namespace string, selector labels.Selector) ([]*v1.ConfigMap, error) - - AddIndexer(indexName string, indexer ConfigMapIndexer) - GetByIndex(indexName, key string) ([]*v1.ConfigMap, error) -} - -type ConfigMapIndexer func(obj *v1.ConfigMap) ([]string, error) - -type configMapController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewConfigMapController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ConfigMapController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &configMapController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromConfigMapHandlerToHandler(sync ConfigMapHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.ConfigMap - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.ConfigMap)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *configMapController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.ConfigMap)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateConfigMapDeepCopyOnChange(client ConfigMapClient, obj *v1.ConfigMap, handler func(obj *v1.ConfigMap) (*v1.ConfigMap, error)) (*v1.ConfigMap, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *configMapController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *configMapController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *configMapController) OnChange(ctx context.Context, name string, sync ConfigMapHandler) { - c.AddGenericHandler(ctx, name, FromConfigMapHandlerToHandler(sync)) -} - -func (c *configMapController) OnRemove(ctx context.Context, name string, sync ConfigMapHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromConfigMapHandlerToHandler(sync))) -} - -func (c *configMapController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *configMapController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *configMapController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *configMapController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *configMapController) Cache() ConfigMapCache { - return &configMapCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *configMapController) Create(obj *v1.ConfigMap) (*v1.ConfigMap, error) { - result := &v1.ConfigMap{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *configMapController) Update(obj *v1.ConfigMap) (*v1.ConfigMap, error) { - result := &v1.ConfigMap{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *configMapController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *configMapController) Get(namespace, name string, options metav1.GetOptions) (*v1.ConfigMap, error) { - result := &v1.ConfigMap{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *configMapController) List(namespace string, opts metav1.ListOptions) (*v1.ConfigMapList, error) { - result := &v1.ConfigMapList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *configMapController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *configMapController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.ConfigMap, error) { - result := &v1.ConfigMap{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type configMapCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *configMapCache) Get(namespace, name string) (*v1.ConfigMap, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.ConfigMap), nil -} - -func (c *configMapCache) List(namespace string, selector labels.Selector) (ret []*v1.ConfigMap, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ConfigMap)) - }) - - return ret, err -} - -func (c *configMapCache) AddIndexer(indexName string, indexer ConfigMapIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.ConfigMap)) - }, - })) -} - -func (c *configMapCache) GetByIndex(indexName, key string) (result []*v1.ConfigMap, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.ConfigMap, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.ConfigMap)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/endpoints.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/endpoints.go deleted file mode 100644 index 742c38be00..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/endpoints.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type EndpointsHandler func(string, *v1.Endpoints) (*v1.Endpoints, error) - -type EndpointsController interface { - generic.ControllerMeta - EndpointsClient - - OnChange(ctx context.Context, name string, sync EndpointsHandler) - OnRemove(ctx context.Context, name string, sync EndpointsHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() EndpointsCache -} - -type EndpointsClient interface { - Create(*v1.Endpoints) (*v1.Endpoints, error) - Update(*v1.Endpoints) (*v1.Endpoints, error) - - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.Endpoints, error) - List(namespace string, opts metav1.ListOptions) (*v1.EndpointsList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Endpoints, err error) -} - -type EndpointsCache interface { - Get(namespace, name string) (*v1.Endpoints, error) - List(namespace string, selector labels.Selector) ([]*v1.Endpoints, error) - - AddIndexer(indexName string, indexer EndpointsIndexer) - GetByIndex(indexName, key string) ([]*v1.Endpoints, error) -} - -type EndpointsIndexer func(obj *v1.Endpoints) ([]string, error) - -type endpointsController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewEndpointsController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) EndpointsController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &endpointsController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromEndpointsHandlerToHandler(sync EndpointsHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.Endpoints - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.Endpoints)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *endpointsController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.Endpoints)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateEndpointsDeepCopyOnChange(client EndpointsClient, obj *v1.Endpoints, handler func(obj *v1.Endpoints) (*v1.Endpoints, error)) (*v1.Endpoints, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *endpointsController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *endpointsController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *endpointsController) OnChange(ctx context.Context, name string, sync EndpointsHandler) { - c.AddGenericHandler(ctx, name, FromEndpointsHandlerToHandler(sync)) -} - -func (c *endpointsController) OnRemove(ctx context.Context, name string, sync EndpointsHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromEndpointsHandlerToHandler(sync))) -} - -func (c *endpointsController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *endpointsController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *endpointsController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *endpointsController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *endpointsController) Cache() EndpointsCache { - return &endpointsCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *endpointsController) Create(obj *v1.Endpoints) (*v1.Endpoints, error) { - result := &v1.Endpoints{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *endpointsController) Update(obj *v1.Endpoints) (*v1.Endpoints, error) { - result := &v1.Endpoints{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *endpointsController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *endpointsController) Get(namespace, name string, options metav1.GetOptions) (*v1.Endpoints, error) { - result := &v1.Endpoints{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *endpointsController) List(namespace string, opts metav1.ListOptions) (*v1.EndpointsList, error) { - result := &v1.EndpointsList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *endpointsController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *endpointsController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Endpoints, error) { - result := &v1.Endpoints{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type endpointsCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *endpointsCache) Get(namespace, name string) (*v1.Endpoints, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.Endpoints), nil -} - -func (c *endpointsCache) List(namespace string, selector labels.Selector) (ret []*v1.Endpoints, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Endpoints)) - }) - - return ret, err -} - -func (c *endpointsCache) AddIndexer(indexName string, indexer EndpointsIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.Endpoints)) - }, - })) -} - -func (c *endpointsCache) GetByIndex(indexName, key string) (result []*v1.Endpoints, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.Endpoints, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.Endpoints)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/event.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/event.go deleted file mode 100644 index b052ef91ac..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/event.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type EventHandler func(string, *v1.Event) (*v1.Event, error) - -type EventController interface { - generic.ControllerMeta - EventClient - - OnChange(ctx context.Context, name string, sync EventHandler) - OnRemove(ctx context.Context, name string, sync EventHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() EventCache -} - -type EventClient interface { - Create(*v1.Event) (*v1.Event, error) - Update(*v1.Event) (*v1.Event, error) - - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.Event, error) - List(namespace string, opts metav1.ListOptions) (*v1.EventList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Event, err error) -} - -type EventCache interface { - Get(namespace, name string) (*v1.Event, error) - List(namespace string, selector labels.Selector) ([]*v1.Event, error) - - AddIndexer(indexName string, indexer EventIndexer) - GetByIndex(indexName, key string) ([]*v1.Event, error) -} - -type EventIndexer func(obj *v1.Event) ([]string, error) - -type eventController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewEventController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) EventController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &eventController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromEventHandlerToHandler(sync EventHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.Event - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.Event)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *eventController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.Event)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateEventDeepCopyOnChange(client EventClient, obj *v1.Event, handler func(obj *v1.Event) (*v1.Event, error)) (*v1.Event, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *eventController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *eventController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *eventController) OnChange(ctx context.Context, name string, sync EventHandler) { - c.AddGenericHandler(ctx, name, FromEventHandlerToHandler(sync)) -} - -func (c *eventController) OnRemove(ctx context.Context, name string, sync EventHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromEventHandlerToHandler(sync))) -} - -func (c *eventController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *eventController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *eventController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *eventController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *eventController) Cache() EventCache { - return &eventCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *eventController) Create(obj *v1.Event) (*v1.Event, error) { - result := &v1.Event{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *eventController) Update(obj *v1.Event) (*v1.Event, error) { - result := &v1.Event{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *eventController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *eventController) Get(namespace, name string, options metav1.GetOptions) (*v1.Event, error) { - result := &v1.Event{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *eventController) List(namespace string, opts metav1.ListOptions) (*v1.EventList, error) { - result := &v1.EventList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *eventController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *eventController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Event, error) { - result := &v1.Event{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type eventCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *eventCache) Get(namespace, name string) (*v1.Event, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.Event), nil -} - -func (c *eventCache) List(namespace string, selector labels.Selector) (ret []*v1.Event, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Event)) - }) - - return ret, err -} - -func (c *eventCache) AddIndexer(indexName string, indexer EventIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.Event)) - }, - })) -} - -func (c *eventCache) GetByIndex(indexName, key string) (result []*v1.Event, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.Event, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.Event)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/interface.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/interface.go deleted file mode 100644 index a53c56bd1c..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/interface.go +++ /dev/null @@ -1,88 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/schemes" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -func init() { - schemes.Register(v1.AddToScheme) -} - -type Interface interface { - ConfigMap() ConfigMapController - Endpoints() EndpointsController - Event() EventController - Namespace() NamespaceController - Node() NodeController - PersistentVolume() PersistentVolumeController - PersistentVolumeClaim() PersistentVolumeClaimController - Pod() PodController - Secret() SecretController - Service() ServiceController - ServiceAccount() ServiceAccountController -} - -func New(controllerFactory controller.SharedControllerFactory) Interface { - return &version{ - controllerFactory: controllerFactory, - } -} - -type version struct { - controllerFactory controller.SharedControllerFactory -} - -func (c *version) ConfigMap() ConfigMapController { - return NewConfigMapController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ConfigMap"}, "configmaps", true, c.controllerFactory) -} -func (c *version) Endpoints() EndpointsController { - return NewEndpointsController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Endpoints"}, "endpoints", true, c.controllerFactory) -} -func (c *version) Event() EventController { - return NewEventController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Event"}, "events", true, c.controllerFactory) -} -func (c *version) Namespace() NamespaceController { - return NewNamespaceController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Namespace"}, "namespaces", false, c.controllerFactory) -} -func (c *version) Node() NodeController { - return NewNodeController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Node"}, "nodes", false, c.controllerFactory) -} -func (c *version) PersistentVolume() PersistentVolumeController { - return NewPersistentVolumeController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolume"}, "persistentvolumes", false, c.controllerFactory) -} -func (c *version) PersistentVolumeClaim() PersistentVolumeClaimController { - return NewPersistentVolumeClaimController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolumeClaim"}, "persistentvolumeclaims", true, c.controllerFactory) -} -func (c *version) Pod() PodController { - return NewPodController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"}, "pods", true, c.controllerFactory) -} -func (c *version) Secret() SecretController { - return NewSecretController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Secret"}, "secrets", true, c.controllerFactory) -} -func (c *version) Service() ServiceController { - return NewServiceController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "Service"}, "services", true, c.controllerFactory) -} -func (c *version) ServiceAccount() ServiceAccountController { - return NewServiceAccountController(schema.GroupVersionKind{Group: "", Version: "v1", Kind: "ServiceAccount"}, "serviceaccounts", true, c.controllerFactory) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/namespace.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/namespace.go deleted file mode 100644 index 3f97d67557..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/namespace.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type NamespaceHandler func(string, *v1.Namespace) (*v1.Namespace, error) - -type NamespaceController interface { - generic.ControllerMeta - NamespaceClient - - OnChange(ctx context.Context, name string, sync NamespaceHandler) - OnRemove(ctx context.Context, name string, sync NamespaceHandler) - Enqueue(name string) - EnqueueAfter(name string, duration time.Duration) - - Cache() NamespaceCache -} - -type NamespaceClient interface { - Create(*v1.Namespace) (*v1.Namespace, error) - Update(*v1.Namespace) (*v1.Namespace, error) - UpdateStatus(*v1.Namespace) (*v1.Namespace, error) - Delete(name string, options *metav1.DeleteOptions) error - Get(name string, options metav1.GetOptions) (*v1.Namespace, error) - List(opts metav1.ListOptions) (*v1.NamespaceList, error) - Watch(opts metav1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Namespace, err error) -} - -type NamespaceCache interface { - Get(name string) (*v1.Namespace, error) - List(selector labels.Selector) ([]*v1.Namespace, error) - - AddIndexer(indexName string, indexer NamespaceIndexer) - GetByIndex(indexName, key string) ([]*v1.Namespace, error) -} - -type NamespaceIndexer func(obj *v1.Namespace) ([]string, error) - -type namespaceController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewNamespaceController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) NamespaceController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &namespaceController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromNamespaceHandlerToHandler(sync NamespaceHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.Namespace - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.Namespace)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *namespaceController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.Namespace)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateNamespaceDeepCopyOnChange(client NamespaceClient, obj *v1.Namespace, handler func(obj *v1.Namespace) (*v1.Namespace, error)) (*v1.Namespace, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *namespaceController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *namespaceController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *namespaceController) OnChange(ctx context.Context, name string, sync NamespaceHandler) { - c.AddGenericHandler(ctx, name, FromNamespaceHandlerToHandler(sync)) -} - -func (c *namespaceController) OnRemove(ctx context.Context, name string, sync NamespaceHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromNamespaceHandlerToHandler(sync))) -} - -func (c *namespaceController) Enqueue(name string) { - c.controller.Enqueue("", name) -} - -func (c *namespaceController) EnqueueAfter(name string, duration time.Duration) { - c.controller.EnqueueAfter("", name, duration) -} - -func (c *namespaceController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *namespaceController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *namespaceController) Cache() NamespaceCache { - return &namespaceCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *namespaceController) Create(obj *v1.Namespace) (*v1.Namespace, error) { - result := &v1.Namespace{} - return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{}) -} - -func (c *namespaceController) Update(obj *v1.Namespace) (*v1.Namespace, error) { - result := &v1.Namespace{} - return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *namespaceController) UpdateStatus(obj *v1.Namespace) (*v1.Namespace, error) { - result := &v1.Namespace{} - return result, c.client.UpdateStatus(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *namespaceController) Delete(name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), "", name, *options) -} - -func (c *namespaceController) Get(name string, options metav1.GetOptions) (*v1.Namespace, error) { - result := &v1.Namespace{} - return result, c.client.Get(context.TODO(), "", name, result, options) -} - -func (c *namespaceController) List(opts metav1.ListOptions) (*v1.NamespaceList, error) { - result := &v1.NamespaceList{} - return result, c.client.List(context.TODO(), "", result, opts) -} - -func (c *namespaceController) Watch(opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), "", opts) -} - -func (c *namespaceController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Namespace, error) { - result := &v1.Namespace{} - return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type namespaceCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *namespaceCache) Get(name string) (*v1.Namespace, error) { - obj, exists, err := c.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.Namespace), nil -} - -func (c *namespaceCache) List(selector labels.Selector) (ret []*v1.Namespace, err error) { - - err = cache.ListAll(c.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Namespace)) - }) - - return ret, err -} - -func (c *namespaceCache) AddIndexer(indexName string, indexer NamespaceIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.Namespace)) - }, - })) -} - -func (c *namespaceCache) GetByIndex(indexName, key string) (result []*v1.Namespace, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.Namespace, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.Namespace)) - } - return result, nil -} - -// NamespaceStatusHandler is executed for every added or modified Namespace. Should return the new status to be updated -type NamespaceStatusHandler func(obj *v1.Namespace, status v1.NamespaceStatus) (v1.NamespaceStatus, error) - -// NamespaceGeneratingHandler is the top-level handler that is executed for every Namespace event. It extends NamespaceStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type NamespaceGeneratingHandler func(obj *v1.Namespace, status v1.NamespaceStatus) ([]runtime.Object, v1.NamespaceStatus, error) - -// RegisterNamespaceStatusHandler configures a NamespaceController to execute a NamespaceStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterNamespaceStatusHandler(ctx context.Context, controller NamespaceController, condition condition.Cond, name string, handler NamespaceStatusHandler) { - statusHandler := &namespaceStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromNamespaceHandlerToHandler(statusHandler.sync)) -} - -// RegisterNamespaceGeneratingHandler configures a NamespaceController to execute a NamespaceGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterNamespaceGeneratingHandler(ctx context.Context, controller NamespaceController, apply apply.Apply, - condition condition.Cond, name string, handler NamespaceGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &namespaceGeneratingHandler{ - NamespaceGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterNamespaceStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type namespaceStatusHandler struct { - client NamespaceClient - condition condition.Cond - handler NamespaceStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *namespaceStatusHandler) sync(key string, obj *v1.Namespace) (*v1.Namespace, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type namespaceGeneratingHandler struct { - NamespaceGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *namespaceGeneratingHandler) Remove(key string, obj *v1.Namespace) (*v1.Namespace, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.Namespace{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured NamespaceGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *namespaceGeneratingHandler) Handle(obj *v1.Namespace, status v1.NamespaceStatus) (v1.NamespaceStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.NamespaceGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *namespaceGeneratingHandler) isNewResourceVersion(obj *v1.Namespace) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *namespaceGeneratingHandler) storeResourceVersion(obj *v1.Namespace) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/node.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/node.go deleted file mode 100644 index 1bd956bfe8..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/node.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type NodeHandler func(string, *v1.Node) (*v1.Node, error) - -type NodeController interface { - generic.ControllerMeta - NodeClient - - OnChange(ctx context.Context, name string, sync NodeHandler) - OnRemove(ctx context.Context, name string, sync NodeHandler) - Enqueue(name string) - EnqueueAfter(name string, duration time.Duration) - - Cache() NodeCache -} - -type NodeClient interface { - Create(*v1.Node) (*v1.Node, error) - Update(*v1.Node) (*v1.Node, error) - UpdateStatus(*v1.Node) (*v1.Node, error) - Delete(name string, options *metav1.DeleteOptions) error - Get(name string, options metav1.GetOptions) (*v1.Node, error) - List(opts metav1.ListOptions) (*v1.NodeList, error) - Watch(opts metav1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Node, err error) -} - -type NodeCache interface { - Get(name string) (*v1.Node, error) - List(selector labels.Selector) ([]*v1.Node, error) - - AddIndexer(indexName string, indexer NodeIndexer) - GetByIndex(indexName, key string) ([]*v1.Node, error) -} - -type NodeIndexer func(obj *v1.Node) ([]string, error) - -type nodeController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewNodeController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) NodeController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &nodeController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromNodeHandlerToHandler(sync NodeHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.Node - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.Node)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *nodeController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.Node)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateNodeDeepCopyOnChange(client NodeClient, obj *v1.Node, handler func(obj *v1.Node) (*v1.Node, error)) (*v1.Node, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *nodeController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *nodeController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *nodeController) OnChange(ctx context.Context, name string, sync NodeHandler) { - c.AddGenericHandler(ctx, name, FromNodeHandlerToHandler(sync)) -} - -func (c *nodeController) OnRemove(ctx context.Context, name string, sync NodeHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromNodeHandlerToHandler(sync))) -} - -func (c *nodeController) Enqueue(name string) { - c.controller.Enqueue("", name) -} - -func (c *nodeController) EnqueueAfter(name string, duration time.Duration) { - c.controller.EnqueueAfter("", name, duration) -} - -func (c *nodeController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *nodeController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *nodeController) Cache() NodeCache { - return &nodeCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *nodeController) Create(obj *v1.Node) (*v1.Node, error) { - result := &v1.Node{} - return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{}) -} - -func (c *nodeController) Update(obj *v1.Node) (*v1.Node, error) { - result := &v1.Node{} - return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *nodeController) UpdateStatus(obj *v1.Node) (*v1.Node, error) { - result := &v1.Node{} - return result, c.client.UpdateStatus(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *nodeController) Delete(name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), "", name, *options) -} - -func (c *nodeController) Get(name string, options metav1.GetOptions) (*v1.Node, error) { - result := &v1.Node{} - return result, c.client.Get(context.TODO(), "", name, result, options) -} - -func (c *nodeController) List(opts metav1.ListOptions) (*v1.NodeList, error) { - result := &v1.NodeList{} - return result, c.client.List(context.TODO(), "", result, opts) -} - -func (c *nodeController) Watch(opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), "", opts) -} - -func (c *nodeController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Node, error) { - result := &v1.Node{} - return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type nodeCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *nodeCache) Get(name string) (*v1.Node, error) { - obj, exists, err := c.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.Node), nil -} - -func (c *nodeCache) List(selector labels.Selector) (ret []*v1.Node, err error) { - - err = cache.ListAll(c.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Node)) - }) - - return ret, err -} - -func (c *nodeCache) AddIndexer(indexName string, indexer NodeIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.Node)) - }, - })) -} - -func (c *nodeCache) GetByIndex(indexName, key string) (result []*v1.Node, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.Node, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.Node)) - } - return result, nil -} - -// NodeStatusHandler is executed for every added or modified Node. Should return the new status to be updated -type NodeStatusHandler func(obj *v1.Node, status v1.NodeStatus) (v1.NodeStatus, error) - -// NodeGeneratingHandler is the top-level handler that is executed for every Node event. It extends NodeStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type NodeGeneratingHandler func(obj *v1.Node, status v1.NodeStatus) ([]runtime.Object, v1.NodeStatus, error) - -// RegisterNodeStatusHandler configures a NodeController to execute a NodeStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterNodeStatusHandler(ctx context.Context, controller NodeController, condition condition.Cond, name string, handler NodeStatusHandler) { - statusHandler := &nodeStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromNodeHandlerToHandler(statusHandler.sync)) -} - -// RegisterNodeGeneratingHandler configures a NodeController to execute a NodeGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterNodeGeneratingHandler(ctx context.Context, controller NodeController, apply apply.Apply, - condition condition.Cond, name string, handler NodeGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &nodeGeneratingHandler{ - NodeGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterNodeStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type nodeStatusHandler struct { - client NodeClient - condition condition.Cond - handler NodeStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *nodeStatusHandler) sync(key string, obj *v1.Node) (*v1.Node, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type nodeGeneratingHandler struct { - NodeGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *nodeGeneratingHandler) Remove(key string, obj *v1.Node) (*v1.Node, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.Node{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured NodeGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *nodeGeneratingHandler) Handle(obj *v1.Node, status v1.NodeStatus) (v1.NodeStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.NodeGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *nodeGeneratingHandler) isNewResourceVersion(obj *v1.Node) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *nodeGeneratingHandler) storeResourceVersion(obj *v1.Node) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/persistentvolume.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/persistentvolume.go deleted file mode 100644 index 097e450e13..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/persistentvolume.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type PersistentVolumeHandler func(string, *v1.PersistentVolume) (*v1.PersistentVolume, error) - -type PersistentVolumeController interface { - generic.ControllerMeta - PersistentVolumeClient - - OnChange(ctx context.Context, name string, sync PersistentVolumeHandler) - OnRemove(ctx context.Context, name string, sync PersistentVolumeHandler) - Enqueue(name string) - EnqueueAfter(name string, duration time.Duration) - - Cache() PersistentVolumeCache -} - -type PersistentVolumeClient interface { - Create(*v1.PersistentVolume) (*v1.PersistentVolume, error) - Update(*v1.PersistentVolume) (*v1.PersistentVolume, error) - UpdateStatus(*v1.PersistentVolume) (*v1.PersistentVolume, error) - Delete(name string, options *metav1.DeleteOptions) error - Get(name string, options metav1.GetOptions) (*v1.PersistentVolume, error) - List(opts metav1.ListOptions) (*v1.PersistentVolumeList, error) - Watch(opts metav1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.PersistentVolume, err error) -} - -type PersistentVolumeCache interface { - Get(name string) (*v1.PersistentVolume, error) - List(selector labels.Selector) ([]*v1.PersistentVolume, error) - - AddIndexer(indexName string, indexer PersistentVolumeIndexer) - GetByIndex(indexName, key string) ([]*v1.PersistentVolume, error) -} - -type PersistentVolumeIndexer func(obj *v1.PersistentVolume) ([]string, error) - -type persistentVolumeController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewPersistentVolumeController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) PersistentVolumeController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &persistentVolumeController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromPersistentVolumeHandlerToHandler(sync PersistentVolumeHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.PersistentVolume - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.PersistentVolume)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *persistentVolumeController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.PersistentVolume)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdatePersistentVolumeDeepCopyOnChange(client PersistentVolumeClient, obj *v1.PersistentVolume, handler func(obj *v1.PersistentVolume) (*v1.PersistentVolume, error)) (*v1.PersistentVolume, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *persistentVolumeController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *persistentVolumeController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *persistentVolumeController) OnChange(ctx context.Context, name string, sync PersistentVolumeHandler) { - c.AddGenericHandler(ctx, name, FromPersistentVolumeHandlerToHandler(sync)) -} - -func (c *persistentVolumeController) OnRemove(ctx context.Context, name string, sync PersistentVolumeHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromPersistentVolumeHandlerToHandler(sync))) -} - -func (c *persistentVolumeController) Enqueue(name string) { - c.controller.Enqueue("", name) -} - -func (c *persistentVolumeController) EnqueueAfter(name string, duration time.Duration) { - c.controller.EnqueueAfter("", name, duration) -} - -func (c *persistentVolumeController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *persistentVolumeController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *persistentVolumeController) Cache() PersistentVolumeCache { - return &persistentVolumeCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *persistentVolumeController) Create(obj *v1.PersistentVolume) (*v1.PersistentVolume, error) { - result := &v1.PersistentVolume{} - return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{}) -} - -func (c *persistentVolumeController) Update(obj *v1.PersistentVolume) (*v1.PersistentVolume, error) { - result := &v1.PersistentVolume{} - return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *persistentVolumeController) UpdateStatus(obj *v1.PersistentVolume) (*v1.PersistentVolume, error) { - result := &v1.PersistentVolume{} - return result, c.client.UpdateStatus(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *persistentVolumeController) Delete(name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), "", name, *options) -} - -func (c *persistentVolumeController) Get(name string, options metav1.GetOptions) (*v1.PersistentVolume, error) { - result := &v1.PersistentVolume{} - return result, c.client.Get(context.TODO(), "", name, result, options) -} - -func (c *persistentVolumeController) List(opts metav1.ListOptions) (*v1.PersistentVolumeList, error) { - result := &v1.PersistentVolumeList{} - return result, c.client.List(context.TODO(), "", result, opts) -} - -func (c *persistentVolumeController) Watch(opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), "", opts) -} - -func (c *persistentVolumeController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.PersistentVolume, error) { - result := &v1.PersistentVolume{} - return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type persistentVolumeCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *persistentVolumeCache) Get(name string) (*v1.PersistentVolume, error) { - obj, exists, err := c.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.PersistentVolume), nil -} - -func (c *persistentVolumeCache) List(selector labels.Selector) (ret []*v1.PersistentVolume, err error) { - - err = cache.ListAll(c.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.PersistentVolume)) - }) - - return ret, err -} - -func (c *persistentVolumeCache) AddIndexer(indexName string, indexer PersistentVolumeIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.PersistentVolume)) - }, - })) -} - -func (c *persistentVolumeCache) GetByIndex(indexName, key string) (result []*v1.PersistentVolume, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.PersistentVolume, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.PersistentVolume)) - } - return result, nil -} - -// PersistentVolumeStatusHandler is executed for every added or modified PersistentVolume. Should return the new status to be updated -type PersistentVolumeStatusHandler func(obj *v1.PersistentVolume, status v1.PersistentVolumeStatus) (v1.PersistentVolumeStatus, error) - -// PersistentVolumeGeneratingHandler is the top-level handler that is executed for every PersistentVolume event. It extends PersistentVolumeStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type PersistentVolumeGeneratingHandler func(obj *v1.PersistentVolume, status v1.PersistentVolumeStatus) ([]runtime.Object, v1.PersistentVolumeStatus, error) - -// RegisterPersistentVolumeStatusHandler configures a PersistentVolumeController to execute a PersistentVolumeStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterPersistentVolumeStatusHandler(ctx context.Context, controller PersistentVolumeController, condition condition.Cond, name string, handler PersistentVolumeStatusHandler) { - statusHandler := &persistentVolumeStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromPersistentVolumeHandlerToHandler(statusHandler.sync)) -} - -// RegisterPersistentVolumeGeneratingHandler configures a PersistentVolumeController to execute a PersistentVolumeGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterPersistentVolumeGeneratingHandler(ctx context.Context, controller PersistentVolumeController, apply apply.Apply, - condition condition.Cond, name string, handler PersistentVolumeGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &persistentVolumeGeneratingHandler{ - PersistentVolumeGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterPersistentVolumeStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type persistentVolumeStatusHandler struct { - client PersistentVolumeClient - condition condition.Cond - handler PersistentVolumeStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *persistentVolumeStatusHandler) sync(key string, obj *v1.PersistentVolume) (*v1.PersistentVolume, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type persistentVolumeGeneratingHandler struct { - PersistentVolumeGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *persistentVolumeGeneratingHandler) Remove(key string, obj *v1.PersistentVolume) (*v1.PersistentVolume, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.PersistentVolume{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured PersistentVolumeGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *persistentVolumeGeneratingHandler) Handle(obj *v1.PersistentVolume, status v1.PersistentVolumeStatus) (v1.PersistentVolumeStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.PersistentVolumeGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *persistentVolumeGeneratingHandler) isNewResourceVersion(obj *v1.PersistentVolume) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *persistentVolumeGeneratingHandler) storeResourceVersion(obj *v1.PersistentVolume) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/persistentvolumeclaim.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/persistentvolumeclaim.go deleted file mode 100644 index 8b23338f88..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/persistentvolumeclaim.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type PersistentVolumeClaimHandler func(string, *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) - -type PersistentVolumeClaimController interface { - generic.ControllerMeta - PersistentVolumeClaimClient - - OnChange(ctx context.Context, name string, sync PersistentVolumeClaimHandler) - OnRemove(ctx context.Context, name string, sync PersistentVolumeClaimHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() PersistentVolumeClaimCache -} - -type PersistentVolumeClaimClient interface { - Create(*v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) - Update(*v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) - UpdateStatus(*v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.PersistentVolumeClaim, error) - List(namespace string, opts metav1.ListOptions) (*v1.PersistentVolumeClaimList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.PersistentVolumeClaim, err error) -} - -type PersistentVolumeClaimCache interface { - Get(namespace, name string) (*v1.PersistentVolumeClaim, error) - List(namespace string, selector labels.Selector) ([]*v1.PersistentVolumeClaim, error) - - AddIndexer(indexName string, indexer PersistentVolumeClaimIndexer) - GetByIndex(indexName, key string) ([]*v1.PersistentVolumeClaim, error) -} - -type PersistentVolumeClaimIndexer func(obj *v1.PersistentVolumeClaim) ([]string, error) - -type persistentVolumeClaimController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewPersistentVolumeClaimController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) PersistentVolumeClaimController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &persistentVolumeClaimController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromPersistentVolumeClaimHandlerToHandler(sync PersistentVolumeClaimHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.PersistentVolumeClaim - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.PersistentVolumeClaim)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *persistentVolumeClaimController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.PersistentVolumeClaim)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdatePersistentVolumeClaimDeepCopyOnChange(client PersistentVolumeClaimClient, obj *v1.PersistentVolumeClaim, handler func(obj *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error)) (*v1.PersistentVolumeClaim, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *persistentVolumeClaimController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *persistentVolumeClaimController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *persistentVolumeClaimController) OnChange(ctx context.Context, name string, sync PersistentVolumeClaimHandler) { - c.AddGenericHandler(ctx, name, FromPersistentVolumeClaimHandlerToHandler(sync)) -} - -func (c *persistentVolumeClaimController) OnRemove(ctx context.Context, name string, sync PersistentVolumeClaimHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromPersistentVolumeClaimHandlerToHandler(sync))) -} - -func (c *persistentVolumeClaimController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *persistentVolumeClaimController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *persistentVolumeClaimController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *persistentVolumeClaimController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *persistentVolumeClaimController) Cache() PersistentVolumeClaimCache { - return &persistentVolumeClaimCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *persistentVolumeClaimController) Create(obj *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) { - result := &v1.PersistentVolumeClaim{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *persistentVolumeClaimController) Update(obj *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) { - result := &v1.PersistentVolumeClaim{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *persistentVolumeClaimController) UpdateStatus(obj *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) { - result := &v1.PersistentVolumeClaim{} - return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *persistentVolumeClaimController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *persistentVolumeClaimController) Get(namespace, name string, options metav1.GetOptions) (*v1.PersistentVolumeClaim, error) { - result := &v1.PersistentVolumeClaim{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *persistentVolumeClaimController) List(namespace string, opts metav1.ListOptions) (*v1.PersistentVolumeClaimList, error) { - result := &v1.PersistentVolumeClaimList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *persistentVolumeClaimController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *persistentVolumeClaimController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.PersistentVolumeClaim, error) { - result := &v1.PersistentVolumeClaim{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type persistentVolumeClaimCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *persistentVolumeClaimCache) Get(namespace, name string) (*v1.PersistentVolumeClaim, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.PersistentVolumeClaim), nil -} - -func (c *persistentVolumeClaimCache) List(namespace string, selector labels.Selector) (ret []*v1.PersistentVolumeClaim, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.PersistentVolumeClaim)) - }) - - return ret, err -} - -func (c *persistentVolumeClaimCache) AddIndexer(indexName string, indexer PersistentVolumeClaimIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.PersistentVolumeClaim)) - }, - })) -} - -func (c *persistentVolumeClaimCache) GetByIndex(indexName, key string) (result []*v1.PersistentVolumeClaim, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.PersistentVolumeClaim, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.PersistentVolumeClaim)) - } - return result, nil -} - -// PersistentVolumeClaimStatusHandler is executed for every added or modified PersistentVolumeClaim. Should return the new status to be updated -type PersistentVolumeClaimStatusHandler func(obj *v1.PersistentVolumeClaim, status v1.PersistentVolumeClaimStatus) (v1.PersistentVolumeClaimStatus, error) - -// PersistentVolumeClaimGeneratingHandler is the top-level handler that is executed for every PersistentVolumeClaim event. It extends PersistentVolumeClaimStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type PersistentVolumeClaimGeneratingHandler func(obj *v1.PersistentVolumeClaim, status v1.PersistentVolumeClaimStatus) ([]runtime.Object, v1.PersistentVolumeClaimStatus, error) - -// RegisterPersistentVolumeClaimStatusHandler configures a PersistentVolumeClaimController to execute a PersistentVolumeClaimStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterPersistentVolumeClaimStatusHandler(ctx context.Context, controller PersistentVolumeClaimController, condition condition.Cond, name string, handler PersistentVolumeClaimStatusHandler) { - statusHandler := &persistentVolumeClaimStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromPersistentVolumeClaimHandlerToHandler(statusHandler.sync)) -} - -// RegisterPersistentVolumeClaimGeneratingHandler configures a PersistentVolumeClaimController to execute a PersistentVolumeClaimGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterPersistentVolumeClaimGeneratingHandler(ctx context.Context, controller PersistentVolumeClaimController, apply apply.Apply, - condition condition.Cond, name string, handler PersistentVolumeClaimGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &persistentVolumeClaimGeneratingHandler{ - PersistentVolumeClaimGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterPersistentVolumeClaimStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type persistentVolumeClaimStatusHandler struct { - client PersistentVolumeClaimClient - condition condition.Cond - handler PersistentVolumeClaimStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *persistentVolumeClaimStatusHandler) sync(key string, obj *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type persistentVolumeClaimGeneratingHandler struct { - PersistentVolumeClaimGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *persistentVolumeClaimGeneratingHandler) Remove(key string, obj *v1.PersistentVolumeClaim) (*v1.PersistentVolumeClaim, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.PersistentVolumeClaim{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured PersistentVolumeClaimGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *persistentVolumeClaimGeneratingHandler) Handle(obj *v1.PersistentVolumeClaim, status v1.PersistentVolumeClaimStatus) (v1.PersistentVolumeClaimStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.PersistentVolumeClaimGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *persistentVolumeClaimGeneratingHandler) isNewResourceVersion(obj *v1.PersistentVolumeClaim) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *persistentVolumeClaimGeneratingHandler) storeResourceVersion(obj *v1.PersistentVolumeClaim) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/pod.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/pod.go deleted file mode 100644 index b52fe1c404..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/pod.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type PodHandler func(string, *v1.Pod) (*v1.Pod, error) - -type PodController interface { - generic.ControllerMeta - PodClient - - OnChange(ctx context.Context, name string, sync PodHandler) - OnRemove(ctx context.Context, name string, sync PodHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() PodCache -} - -type PodClient interface { - Create(*v1.Pod) (*v1.Pod, error) - Update(*v1.Pod) (*v1.Pod, error) - UpdateStatus(*v1.Pod) (*v1.Pod, error) - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.Pod, error) - List(namespace string, opts metav1.ListOptions) (*v1.PodList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Pod, err error) -} - -type PodCache interface { - Get(namespace, name string) (*v1.Pod, error) - List(namespace string, selector labels.Selector) ([]*v1.Pod, error) - - AddIndexer(indexName string, indexer PodIndexer) - GetByIndex(indexName, key string) ([]*v1.Pod, error) -} - -type PodIndexer func(obj *v1.Pod) ([]string, error) - -type podController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewPodController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) PodController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &podController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromPodHandlerToHandler(sync PodHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.Pod - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.Pod)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *podController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.Pod)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdatePodDeepCopyOnChange(client PodClient, obj *v1.Pod, handler func(obj *v1.Pod) (*v1.Pod, error)) (*v1.Pod, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *podController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *podController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *podController) OnChange(ctx context.Context, name string, sync PodHandler) { - c.AddGenericHandler(ctx, name, FromPodHandlerToHandler(sync)) -} - -func (c *podController) OnRemove(ctx context.Context, name string, sync PodHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromPodHandlerToHandler(sync))) -} - -func (c *podController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *podController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *podController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *podController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *podController) Cache() PodCache { - return &podCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *podController) Create(obj *v1.Pod) (*v1.Pod, error) { - result := &v1.Pod{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *podController) Update(obj *v1.Pod) (*v1.Pod, error) { - result := &v1.Pod{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *podController) UpdateStatus(obj *v1.Pod) (*v1.Pod, error) { - result := &v1.Pod{} - return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *podController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *podController) Get(namespace, name string, options metav1.GetOptions) (*v1.Pod, error) { - result := &v1.Pod{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *podController) List(namespace string, opts metav1.ListOptions) (*v1.PodList, error) { - result := &v1.PodList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *podController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *podController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Pod, error) { - result := &v1.Pod{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type podCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *podCache) Get(namespace, name string) (*v1.Pod, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.Pod), nil -} - -func (c *podCache) List(namespace string, selector labels.Selector) (ret []*v1.Pod, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Pod)) - }) - - return ret, err -} - -func (c *podCache) AddIndexer(indexName string, indexer PodIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.Pod)) - }, - })) -} - -func (c *podCache) GetByIndex(indexName, key string) (result []*v1.Pod, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.Pod, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.Pod)) - } - return result, nil -} - -// PodStatusHandler is executed for every added or modified Pod. Should return the new status to be updated -type PodStatusHandler func(obj *v1.Pod, status v1.PodStatus) (v1.PodStatus, error) - -// PodGeneratingHandler is the top-level handler that is executed for every Pod event. It extends PodStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type PodGeneratingHandler func(obj *v1.Pod, status v1.PodStatus) ([]runtime.Object, v1.PodStatus, error) - -// RegisterPodStatusHandler configures a PodController to execute a PodStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterPodStatusHandler(ctx context.Context, controller PodController, condition condition.Cond, name string, handler PodStatusHandler) { - statusHandler := &podStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromPodHandlerToHandler(statusHandler.sync)) -} - -// RegisterPodGeneratingHandler configures a PodController to execute a PodGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterPodGeneratingHandler(ctx context.Context, controller PodController, apply apply.Apply, - condition condition.Cond, name string, handler PodGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &podGeneratingHandler{ - PodGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterPodStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type podStatusHandler struct { - client PodClient - condition condition.Cond - handler PodStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *podStatusHandler) sync(key string, obj *v1.Pod) (*v1.Pod, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type podGeneratingHandler struct { - PodGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *podGeneratingHandler) Remove(key string, obj *v1.Pod) (*v1.Pod, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.Pod{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured PodGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *podGeneratingHandler) Handle(obj *v1.Pod, status v1.PodStatus) (v1.PodStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.PodGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *podGeneratingHandler) isNewResourceVersion(obj *v1.Pod) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *podGeneratingHandler) storeResourceVersion(obj *v1.Pod) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/secret.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/secret.go deleted file mode 100644 index 55cc637076..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/secret.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type SecretHandler func(string, *v1.Secret) (*v1.Secret, error) - -type SecretController interface { - generic.ControllerMeta - SecretClient - - OnChange(ctx context.Context, name string, sync SecretHandler) - OnRemove(ctx context.Context, name string, sync SecretHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() SecretCache -} - -type SecretClient interface { - Create(*v1.Secret) (*v1.Secret, error) - Update(*v1.Secret) (*v1.Secret, error) - - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.Secret, error) - List(namespace string, opts metav1.ListOptions) (*v1.SecretList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Secret, err error) -} - -type SecretCache interface { - Get(namespace, name string) (*v1.Secret, error) - List(namespace string, selector labels.Selector) ([]*v1.Secret, error) - - AddIndexer(indexName string, indexer SecretIndexer) - GetByIndex(indexName, key string) ([]*v1.Secret, error) -} - -type SecretIndexer func(obj *v1.Secret) ([]string, error) - -type secretController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewSecretController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) SecretController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &secretController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromSecretHandlerToHandler(sync SecretHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.Secret - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.Secret)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *secretController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.Secret)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateSecretDeepCopyOnChange(client SecretClient, obj *v1.Secret, handler func(obj *v1.Secret) (*v1.Secret, error)) (*v1.Secret, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *secretController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *secretController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *secretController) OnChange(ctx context.Context, name string, sync SecretHandler) { - c.AddGenericHandler(ctx, name, FromSecretHandlerToHandler(sync)) -} - -func (c *secretController) OnRemove(ctx context.Context, name string, sync SecretHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromSecretHandlerToHandler(sync))) -} - -func (c *secretController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *secretController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *secretController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *secretController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *secretController) Cache() SecretCache { - return &secretCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *secretController) Create(obj *v1.Secret) (*v1.Secret, error) { - result := &v1.Secret{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *secretController) Update(obj *v1.Secret) (*v1.Secret, error) { - result := &v1.Secret{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *secretController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *secretController) Get(namespace, name string, options metav1.GetOptions) (*v1.Secret, error) { - result := &v1.Secret{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *secretController) List(namespace string, opts metav1.ListOptions) (*v1.SecretList, error) { - result := &v1.SecretList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *secretController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *secretController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Secret, error) { - result := &v1.Secret{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type secretCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *secretCache) Get(namespace, name string) (*v1.Secret, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.Secret), nil -} - -func (c *secretCache) List(namespace string, selector labels.Selector) (ret []*v1.Secret, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Secret)) - }) - - return ret, err -} - -func (c *secretCache) AddIndexer(indexName string, indexer SecretIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.Secret)) - }, - })) -} - -func (c *secretCache) GetByIndex(indexName, key string) (result []*v1.Secret, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.Secret, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.Secret)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/service.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/service.go deleted file mode 100644 index a347887c65..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/service.go +++ /dev/null @@ -1,423 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/apply" - "github.com/rancher/wrangler/pkg/condition" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/kv" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type ServiceHandler func(string, *v1.Service) (*v1.Service, error) - -type ServiceController interface { - generic.ControllerMeta - ServiceClient - - OnChange(ctx context.Context, name string, sync ServiceHandler) - OnRemove(ctx context.Context, name string, sync ServiceHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() ServiceCache -} - -type ServiceClient interface { - Create(*v1.Service) (*v1.Service, error) - Update(*v1.Service) (*v1.Service, error) - UpdateStatus(*v1.Service) (*v1.Service, error) - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.Service, error) - List(namespace string, opts metav1.ListOptions) (*v1.ServiceList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Service, err error) -} - -type ServiceCache interface { - Get(namespace, name string) (*v1.Service, error) - List(namespace string, selector labels.Selector) ([]*v1.Service, error) - - AddIndexer(indexName string, indexer ServiceIndexer) - GetByIndex(indexName, key string) ([]*v1.Service, error) -} - -type ServiceIndexer func(obj *v1.Service) ([]string, error) - -type serviceController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewServiceController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ServiceController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &serviceController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromServiceHandlerToHandler(sync ServiceHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.Service - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.Service)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *serviceController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.Service)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateServiceDeepCopyOnChange(client ServiceClient, obj *v1.Service, handler func(obj *v1.Service) (*v1.Service, error)) (*v1.Service, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *serviceController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *serviceController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *serviceController) OnChange(ctx context.Context, name string, sync ServiceHandler) { - c.AddGenericHandler(ctx, name, FromServiceHandlerToHandler(sync)) -} - -func (c *serviceController) OnRemove(ctx context.Context, name string, sync ServiceHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromServiceHandlerToHandler(sync))) -} - -func (c *serviceController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *serviceController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *serviceController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *serviceController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *serviceController) Cache() ServiceCache { - return &serviceCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *serviceController) Create(obj *v1.Service) (*v1.Service, error) { - result := &v1.Service{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *serviceController) Update(obj *v1.Service) (*v1.Service, error) { - result := &v1.Service{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *serviceController) UpdateStatus(obj *v1.Service) (*v1.Service, error) { - result := &v1.Service{} - return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *serviceController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *serviceController) Get(namespace, name string, options metav1.GetOptions) (*v1.Service, error) { - result := &v1.Service{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *serviceController) List(namespace string, opts metav1.ListOptions) (*v1.ServiceList, error) { - result := &v1.ServiceList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *serviceController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *serviceController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Service, error) { - result := &v1.Service{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type serviceCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *serviceCache) Get(namespace, name string) (*v1.Service, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.Service), nil -} - -func (c *serviceCache) List(namespace string, selector labels.Selector) (ret []*v1.Service, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Service)) - }) - - return ret, err -} - -func (c *serviceCache) AddIndexer(indexName string, indexer ServiceIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.Service)) - }, - })) -} - -func (c *serviceCache) GetByIndex(indexName, key string) (result []*v1.Service, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.Service, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.Service)) - } - return result, nil -} - -// ServiceStatusHandler is executed for every added or modified Service. Should return the new status to be updated -type ServiceStatusHandler func(obj *v1.Service, status v1.ServiceStatus) (v1.ServiceStatus, error) - -// ServiceGeneratingHandler is the top-level handler that is executed for every Service event. It extends ServiceStatusHandler by a returning a slice of child objects to be passed to apply.Apply -type ServiceGeneratingHandler func(obj *v1.Service, status v1.ServiceStatus) ([]runtime.Object, v1.ServiceStatus, error) - -// RegisterServiceStatusHandler configures a ServiceController to execute a ServiceStatusHandler for every events observed. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterServiceStatusHandler(ctx context.Context, controller ServiceController, condition condition.Cond, name string, handler ServiceStatusHandler) { - statusHandler := &serviceStatusHandler{ - client: controller, - condition: condition, - handler: handler, - } - controller.AddGenericHandler(ctx, name, FromServiceHandlerToHandler(statusHandler.sync)) -} - -// RegisterServiceGeneratingHandler configures a ServiceController to execute a ServiceGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. -// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution -func RegisterServiceGeneratingHandler(ctx context.Context, controller ServiceController, apply apply.Apply, - condition condition.Cond, name string, handler ServiceGeneratingHandler, opts *generic.GeneratingHandlerOptions) { - statusHandler := &serviceGeneratingHandler{ - ServiceGeneratingHandler: handler, - apply: apply, - name: name, - gvk: controller.GroupVersionKind(), - } - if opts != nil { - statusHandler.opts = *opts - } - controller.OnChange(ctx, name, statusHandler.Remove) - RegisterServiceStatusHandler(ctx, controller, condition, name, statusHandler.Handle) -} - -type serviceStatusHandler struct { - client ServiceClient - condition condition.Cond - handler ServiceStatusHandler -} - -// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API -func (a *serviceStatusHandler) sync(key string, obj *v1.Service) (*v1.Service, error) { - if obj == nil { - return obj, nil - } - - origStatus := obj.Status.DeepCopy() - obj = obj.DeepCopy() - newStatus, err := a.handler(obj, obj.Status) - if err != nil { - // Revert to old status on error - newStatus = *origStatus.DeepCopy() - } - - if a.condition != "" { - if errors.IsConflict(err) { - a.condition.SetError(&newStatus, "", nil) - } else { - a.condition.SetError(&newStatus, "", err) - } - } - if !equality.Semantic.DeepEqual(origStatus, &newStatus) { - if a.condition != "" { - // Since status has changed, update the lastUpdatedTime - a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) - } - - var newErr error - obj.Status = newStatus - newObj, newErr := a.client.UpdateStatus(obj) - if err == nil { - err = newErr - } - if newErr == nil { - obj = newObj - } - } - return obj, err -} - -type serviceGeneratingHandler struct { - ServiceGeneratingHandler - apply apply.Apply - opts generic.GeneratingHandlerOptions - gvk schema.GroupVersionKind - name string - seen sync.Map -} - -// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied -func (a *serviceGeneratingHandler) Remove(key string, obj *v1.Service) (*v1.Service, error) { - if obj != nil { - return obj, nil - } - - obj = &v1.Service{} - obj.Namespace, obj.Name = kv.RSplit(key, "/") - obj.SetGroupVersionKind(a.gvk) - - if a.opts.UniqueApplyForResourceVersion { - a.seen.Delete(key) - } - - return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects() -} - -// Handle executes the configured ServiceGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource -func (a *serviceGeneratingHandler) Handle(obj *v1.Service, status v1.ServiceStatus) (v1.ServiceStatus, error) { - if !obj.DeletionTimestamp.IsZero() { - return status, nil - } - - objs, newStatus, err := a.ServiceGeneratingHandler(obj, status) - if err != nil { - return newStatus, err - } - if !a.isNewResourceVersion(obj) { - return newStatus, nil - } - - err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). - WithOwner(obj). - WithSetID(a.name). - ApplyObjects(objs...) - if err != nil { - return newStatus, err - } - a.storeResourceVersion(obj) - return newStatus, nil -} - -// isNewResourceVersion detects if a specific resource version was already successfully processed. -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *serviceGeneratingHandler) isNewResourceVersion(obj *v1.Service) bool { - if !a.opts.UniqueApplyForResourceVersion { - return true - } - - // Apply once per resource version - key := obj.Namespace + "/" + obj.Name - previous, ok := a.seen.Load(key) - return !ok || previous != obj.ResourceVersion -} - -// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed -// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions -func (a *serviceGeneratingHandler) storeResourceVersion(obj *v1.Service) { - if !a.opts.UniqueApplyForResourceVersion { - return - } - - key := obj.Namespace + "/" + obj.Name - a.seen.Store(key, obj.ResourceVersion) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/serviceaccount.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/serviceaccount.go deleted file mode 100644 index f9a81cc8fa..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/v1/serviceaccount.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type ServiceAccountHandler func(string, *v1.ServiceAccount) (*v1.ServiceAccount, error) - -type ServiceAccountController interface { - generic.ControllerMeta - ServiceAccountClient - - OnChange(ctx context.Context, name string, sync ServiceAccountHandler) - OnRemove(ctx context.Context, name string, sync ServiceAccountHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() ServiceAccountCache -} - -type ServiceAccountClient interface { - Create(*v1.ServiceAccount) (*v1.ServiceAccount, error) - Update(*v1.ServiceAccount) (*v1.ServiceAccount, error) - - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.ServiceAccount, error) - List(namespace string, opts metav1.ListOptions) (*v1.ServiceAccountList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ServiceAccount, err error) -} - -type ServiceAccountCache interface { - Get(namespace, name string) (*v1.ServiceAccount, error) - List(namespace string, selector labels.Selector) ([]*v1.ServiceAccount, error) - - AddIndexer(indexName string, indexer ServiceAccountIndexer) - GetByIndex(indexName, key string) ([]*v1.ServiceAccount, error) -} - -type ServiceAccountIndexer func(obj *v1.ServiceAccount) ([]string, error) - -type serviceAccountController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewServiceAccountController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ServiceAccountController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &serviceAccountController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromServiceAccountHandlerToHandler(sync ServiceAccountHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.ServiceAccount - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.ServiceAccount)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *serviceAccountController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.ServiceAccount)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateServiceAccountDeepCopyOnChange(client ServiceAccountClient, obj *v1.ServiceAccount, handler func(obj *v1.ServiceAccount) (*v1.ServiceAccount, error)) (*v1.ServiceAccount, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *serviceAccountController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *serviceAccountController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *serviceAccountController) OnChange(ctx context.Context, name string, sync ServiceAccountHandler) { - c.AddGenericHandler(ctx, name, FromServiceAccountHandlerToHandler(sync)) -} - -func (c *serviceAccountController) OnRemove(ctx context.Context, name string, sync ServiceAccountHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromServiceAccountHandlerToHandler(sync))) -} - -func (c *serviceAccountController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *serviceAccountController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *serviceAccountController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *serviceAccountController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *serviceAccountController) Cache() ServiceAccountCache { - return &serviceAccountCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *serviceAccountController) Create(obj *v1.ServiceAccount) (*v1.ServiceAccount, error) { - result := &v1.ServiceAccount{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *serviceAccountController) Update(obj *v1.ServiceAccount) (*v1.ServiceAccount, error) { - result := &v1.ServiceAccount{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *serviceAccountController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *serviceAccountController) Get(namespace, name string, options metav1.GetOptions) (*v1.ServiceAccount, error) { - result := &v1.ServiceAccount{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *serviceAccountController) List(namespace string, opts metav1.ListOptions) (*v1.ServiceAccountList, error) { - result := &v1.ServiceAccountList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *serviceAccountController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *serviceAccountController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.ServiceAccount, error) { - result := &v1.ServiceAccount{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type serviceAccountCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *serviceAccountCache) Get(namespace, name string) (*v1.ServiceAccount, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.ServiceAccount), nil -} - -func (c *serviceAccountCache) List(namespace string, selector labels.Selector) (ret []*v1.ServiceAccount, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ServiceAccount)) - }) - - return ret, err -} - -func (c *serviceAccountCache) AddIndexer(indexName string, indexer ServiceAccountIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.ServiceAccount)) - }, - })) -} - -func (c *serviceAccountCache) GetByIndex(indexName, key string) (result []*v1.ServiceAccount, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.ServiceAccount, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.ServiceAccount)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/clusterrole.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/clusterrole.go deleted file mode 100644 index 1c192736d5..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/clusterrole.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/rbac/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type ClusterRoleHandler func(string, *v1.ClusterRole) (*v1.ClusterRole, error) - -type ClusterRoleController interface { - generic.ControllerMeta - ClusterRoleClient - - OnChange(ctx context.Context, name string, sync ClusterRoleHandler) - OnRemove(ctx context.Context, name string, sync ClusterRoleHandler) - Enqueue(name string) - EnqueueAfter(name string, duration time.Duration) - - Cache() ClusterRoleCache -} - -type ClusterRoleClient interface { - Create(*v1.ClusterRole) (*v1.ClusterRole, error) - Update(*v1.ClusterRole) (*v1.ClusterRole, error) - - Delete(name string, options *metav1.DeleteOptions) error - Get(name string, options metav1.GetOptions) (*v1.ClusterRole, error) - List(opts metav1.ListOptions) (*v1.ClusterRoleList, error) - Watch(opts metav1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ClusterRole, err error) -} - -type ClusterRoleCache interface { - Get(name string) (*v1.ClusterRole, error) - List(selector labels.Selector) ([]*v1.ClusterRole, error) - - AddIndexer(indexName string, indexer ClusterRoleIndexer) - GetByIndex(indexName, key string) ([]*v1.ClusterRole, error) -} - -type ClusterRoleIndexer func(obj *v1.ClusterRole) ([]string, error) - -type clusterRoleController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewClusterRoleController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ClusterRoleController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &clusterRoleController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromClusterRoleHandlerToHandler(sync ClusterRoleHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.ClusterRole - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.ClusterRole)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *clusterRoleController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.ClusterRole)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateClusterRoleDeepCopyOnChange(client ClusterRoleClient, obj *v1.ClusterRole, handler func(obj *v1.ClusterRole) (*v1.ClusterRole, error)) (*v1.ClusterRole, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *clusterRoleController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *clusterRoleController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *clusterRoleController) OnChange(ctx context.Context, name string, sync ClusterRoleHandler) { - c.AddGenericHandler(ctx, name, FromClusterRoleHandlerToHandler(sync)) -} - -func (c *clusterRoleController) OnRemove(ctx context.Context, name string, sync ClusterRoleHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromClusterRoleHandlerToHandler(sync))) -} - -func (c *clusterRoleController) Enqueue(name string) { - c.controller.Enqueue("", name) -} - -func (c *clusterRoleController) EnqueueAfter(name string, duration time.Duration) { - c.controller.EnqueueAfter("", name, duration) -} - -func (c *clusterRoleController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *clusterRoleController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *clusterRoleController) Cache() ClusterRoleCache { - return &clusterRoleCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *clusterRoleController) Create(obj *v1.ClusterRole) (*v1.ClusterRole, error) { - result := &v1.ClusterRole{} - return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{}) -} - -func (c *clusterRoleController) Update(obj *v1.ClusterRole) (*v1.ClusterRole, error) { - result := &v1.ClusterRole{} - return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *clusterRoleController) Delete(name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), "", name, *options) -} - -func (c *clusterRoleController) Get(name string, options metav1.GetOptions) (*v1.ClusterRole, error) { - result := &v1.ClusterRole{} - return result, c.client.Get(context.TODO(), "", name, result, options) -} - -func (c *clusterRoleController) List(opts metav1.ListOptions) (*v1.ClusterRoleList, error) { - result := &v1.ClusterRoleList{} - return result, c.client.List(context.TODO(), "", result, opts) -} - -func (c *clusterRoleController) Watch(opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), "", opts) -} - -func (c *clusterRoleController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.ClusterRole, error) { - result := &v1.ClusterRole{} - return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type clusterRoleCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *clusterRoleCache) Get(name string) (*v1.ClusterRole, error) { - obj, exists, err := c.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.ClusterRole), nil -} - -func (c *clusterRoleCache) List(selector labels.Selector) (ret []*v1.ClusterRole, err error) { - - err = cache.ListAll(c.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ClusterRole)) - }) - - return ret, err -} - -func (c *clusterRoleCache) AddIndexer(indexName string, indexer ClusterRoleIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.ClusterRole)) - }, - })) -} - -func (c *clusterRoleCache) GetByIndex(indexName, key string) (result []*v1.ClusterRole, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.ClusterRole, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.ClusterRole)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/clusterrolebinding.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/clusterrolebinding.go deleted file mode 100644 index 8673b6a201..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/clusterrolebinding.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/rbac/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type ClusterRoleBindingHandler func(string, *v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) - -type ClusterRoleBindingController interface { - generic.ControllerMeta - ClusterRoleBindingClient - - OnChange(ctx context.Context, name string, sync ClusterRoleBindingHandler) - OnRemove(ctx context.Context, name string, sync ClusterRoleBindingHandler) - Enqueue(name string) - EnqueueAfter(name string, duration time.Duration) - - Cache() ClusterRoleBindingCache -} - -type ClusterRoleBindingClient interface { - Create(*v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) - Update(*v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) - - Delete(name string, options *metav1.DeleteOptions) error - Get(name string, options metav1.GetOptions) (*v1.ClusterRoleBinding, error) - List(opts metav1.ListOptions) (*v1.ClusterRoleBindingList, error) - Watch(opts metav1.ListOptions) (watch.Interface, error) - Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ClusterRoleBinding, err error) -} - -type ClusterRoleBindingCache interface { - Get(name string) (*v1.ClusterRoleBinding, error) - List(selector labels.Selector) ([]*v1.ClusterRoleBinding, error) - - AddIndexer(indexName string, indexer ClusterRoleBindingIndexer) - GetByIndex(indexName, key string) ([]*v1.ClusterRoleBinding, error) -} - -type ClusterRoleBindingIndexer func(obj *v1.ClusterRoleBinding) ([]string, error) - -type clusterRoleBindingController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewClusterRoleBindingController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) ClusterRoleBindingController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &clusterRoleBindingController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromClusterRoleBindingHandlerToHandler(sync ClusterRoleBindingHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.ClusterRoleBinding - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.ClusterRoleBinding)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *clusterRoleBindingController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.ClusterRoleBinding)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateClusterRoleBindingDeepCopyOnChange(client ClusterRoleBindingClient, obj *v1.ClusterRoleBinding, handler func(obj *v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error)) (*v1.ClusterRoleBinding, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *clusterRoleBindingController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *clusterRoleBindingController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *clusterRoleBindingController) OnChange(ctx context.Context, name string, sync ClusterRoleBindingHandler) { - c.AddGenericHandler(ctx, name, FromClusterRoleBindingHandlerToHandler(sync)) -} - -func (c *clusterRoleBindingController) OnRemove(ctx context.Context, name string, sync ClusterRoleBindingHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromClusterRoleBindingHandlerToHandler(sync))) -} - -func (c *clusterRoleBindingController) Enqueue(name string) { - c.controller.Enqueue("", name) -} - -func (c *clusterRoleBindingController) EnqueueAfter(name string, duration time.Duration) { - c.controller.EnqueueAfter("", name, duration) -} - -func (c *clusterRoleBindingController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *clusterRoleBindingController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *clusterRoleBindingController) Cache() ClusterRoleBindingCache { - return &clusterRoleBindingCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *clusterRoleBindingController) Create(obj *v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) { - result := &v1.ClusterRoleBinding{} - return result, c.client.Create(context.TODO(), "", obj, result, metav1.CreateOptions{}) -} - -func (c *clusterRoleBindingController) Update(obj *v1.ClusterRoleBinding) (*v1.ClusterRoleBinding, error) { - result := &v1.ClusterRoleBinding{} - return result, c.client.Update(context.TODO(), "", obj, result, metav1.UpdateOptions{}) -} - -func (c *clusterRoleBindingController) Delete(name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), "", name, *options) -} - -func (c *clusterRoleBindingController) Get(name string, options metav1.GetOptions) (*v1.ClusterRoleBinding, error) { - result := &v1.ClusterRoleBinding{} - return result, c.client.Get(context.TODO(), "", name, result, options) -} - -func (c *clusterRoleBindingController) List(opts metav1.ListOptions) (*v1.ClusterRoleBindingList, error) { - result := &v1.ClusterRoleBindingList{} - return result, c.client.List(context.TODO(), "", result, opts) -} - -func (c *clusterRoleBindingController) Watch(opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), "", opts) -} - -func (c *clusterRoleBindingController) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (*v1.ClusterRoleBinding, error) { - result := &v1.ClusterRoleBinding{} - return result, c.client.Patch(context.TODO(), "", name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type clusterRoleBindingCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *clusterRoleBindingCache) Get(name string) (*v1.ClusterRoleBinding, error) { - obj, exists, err := c.indexer.GetByKey(name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.ClusterRoleBinding), nil -} - -func (c *clusterRoleBindingCache) List(selector labels.Selector) (ret []*v1.ClusterRoleBinding, err error) { - - err = cache.ListAll(c.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1.ClusterRoleBinding)) - }) - - return ret, err -} - -func (c *clusterRoleBindingCache) AddIndexer(indexName string, indexer ClusterRoleBindingIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.ClusterRoleBinding)) - }, - })) -} - -func (c *clusterRoleBindingCache) GetByIndex(indexName, key string) (result []*v1.ClusterRoleBinding, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.ClusterRoleBinding, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.ClusterRoleBinding)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/role.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/role.go deleted file mode 100644 index a3b113eae6..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/role.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/rbac/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type RoleHandler func(string, *v1.Role) (*v1.Role, error) - -type RoleController interface { - generic.ControllerMeta - RoleClient - - OnChange(ctx context.Context, name string, sync RoleHandler) - OnRemove(ctx context.Context, name string, sync RoleHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() RoleCache -} - -type RoleClient interface { - Create(*v1.Role) (*v1.Role, error) - Update(*v1.Role) (*v1.Role, error) - - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.Role, error) - List(namespace string, opts metav1.ListOptions) (*v1.RoleList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Role, err error) -} - -type RoleCache interface { - Get(namespace, name string) (*v1.Role, error) - List(namespace string, selector labels.Selector) ([]*v1.Role, error) - - AddIndexer(indexName string, indexer RoleIndexer) - GetByIndex(indexName, key string) ([]*v1.Role, error) -} - -type RoleIndexer func(obj *v1.Role) ([]string, error) - -type roleController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewRoleController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) RoleController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &roleController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromRoleHandlerToHandler(sync RoleHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.Role - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.Role)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *roleController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.Role)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateRoleDeepCopyOnChange(client RoleClient, obj *v1.Role, handler func(obj *v1.Role) (*v1.Role, error)) (*v1.Role, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *roleController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *roleController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *roleController) OnChange(ctx context.Context, name string, sync RoleHandler) { - c.AddGenericHandler(ctx, name, FromRoleHandlerToHandler(sync)) -} - -func (c *roleController) OnRemove(ctx context.Context, name string, sync RoleHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromRoleHandlerToHandler(sync))) -} - -func (c *roleController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *roleController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *roleController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *roleController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *roleController) Cache() RoleCache { - return &roleCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *roleController) Create(obj *v1.Role) (*v1.Role, error) { - result := &v1.Role{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *roleController) Update(obj *v1.Role) (*v1.Role, error) { - result := &v1.Role{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *roleController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *roleController) Get(namespace, name string, options metav1.GetOptions) (*v1.Role, error) { - result := &v1.Role{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *roleController) List(namespace string, opts metav1.ListOptions) (*v1.RoleList, error) { - result := &v1.RoleList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *roleController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *roleController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Role, error) { - result := &v1.Role{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type roleCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *roleCache) Get(namespace, name string) (*v1.Role, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.Role), nil -} - -func (c *roleCache) List(namespace string, selector labels.Selector) (ret []*v1.Role, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.Role)) - }) - - return ret, err -} - -func (c *roleCache) AddIndexer(indexName string, indexer RoleIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.Role)) - }, - })) -} - -func (c *roleCache) GetByIndex(indexName, key string) (result []*v1.Role, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.Role, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.Role)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/rolebinding.go b/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/rolebinding.go deleted file mode 100644 index 383ffa15d8..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/rolebinding.go +++ /dev/null @@ -1,256 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by main. DO NOT EDIT. - -package v1 - -import ( - "context" - "time" - - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" - v1 "k8s.io/api/rbac/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/apimachinery/pkg/watch" - "k8s.io/client-go/tools/cache" -) - -type RoleBindingHandler func(string, *v1.RoleBinding) (*v1.RoleBinding, error) - -type RoleBindingController interface { - generic.ControllerMeta - RoleBindingClient - - OnChange(ctx context.Context, name string, sync RoleBindingHandler) - OnRemove(ctx context.Context, name string, sync RoleBindingHandler) - Enqueue(namespace, name string) - EnqueueAfter(namespace, name string, duration time.Duration) - - Cache() RoleBindingCache -} - -type RoleBindingClient interface { - Create(*v1.RoleBinding) (*v1.RoleBinding, error) - Update(*v1.RoleBinding) (*v1.RoleBinding, error) - - Delete(namespace, name string, options *metav1.DeleteOptions) error - Get(namespace, name string, options metav1.GetOptions) (*v1.RoleBinding, error) - List(namespace string, opts metav1.ListOptions) (*v1.RoleBindingList, error) - Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) - Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.RoleBinding, err error) -} - -type RoleBindingCache interface { - Get(namespace, name string) (*v1.RoleBinding, error) - List(namespace string, selector labels.Selector) ([]*v1.RoleBinding, error) - - AddIndexer(indexName string, indexer RoleBindingIndexer) - GetByIndex(indexName, key string) ([]*v1.RoleBinding, error) -} - -type RoleBindingIndexer func(obj *v1.RoleBinding) ([]string, error) - -type roleBindingController struct { - controller controller.SharedController - client *client.Client - gvk schema.GroupVersionKind - groupResource schema.GroupResource -} - -func NewRoleBindingController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) RoleBindingController { - c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced) - return &roleBindingController{ - controller: c, - client: c.Client(), - gvk: gvk, - groupResource: schema.GroupResource{ - Group: gvk.Group, - Resource: resource, - }, - } -} - -func FromRoleBindingHandlerToHandler(sync RoleBindingHandler) generic.Handler { - return func(key string, obj runtime.Object) (ret runtime.Object, err error) { - var v *v1.RoleBinding - if obj == nil { - v, err = sync(key, nil) - } else { - v, err = sync(key, obj.(*v1.RoleBinding)) - } - if v == nil { - return nil, err - } - return v, err - } -} - -func (c *roleBindingController) Updater() generic.Updater { - return func(obj runtime.Object) (runtime.Object, error) { - newObj, err := c.Update(obj.(*v1.RoleBinding)) - if newObj == nil { - return nil, err - } - return newObj, err - } -} - -func UpdateRoleBindingDeepCopyOnChange(client RoleBindingClient, obj *v1.RoleBinding, handler func(obj *v1.RoleBinding) (*v1.RoleBinding, error)) (*v1.RoleBinding, error) { - if obj == nil { - return obj, nil - } - - copyObj := obj.DeepCopy() - newObj, err := handler(copyObj) - if newObj != nil { - copyObj = newObj - } - if obj.ResourceVersion == copyObj.ResourceVersion && !equality.Semantic.DeepEqual(obj, copyObj) { - return client.Update(copyObj) - } - - return copyObj, err -} - -func (c *roleBindingController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) { - c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler)) -} - -func (c *roleBindingController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler)) -} - -func (c *roleBindingController) OnChange(ctx context.Context, name string, sync RoleBindingHandler) { - c.AddGenericHandler(ctx, name, FromRoleBindingHandlerToHandler(sync)) -} - -func (c *roleBindingController) OnRemove(ctx context.Context, name string, sync RoleBindingHandler) { - c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromRoleBindingHandlerToHandler(sync))) -} - -func (c *roleBindingController) Enqueue(namespace, name string) { - c.controller.Enqueue(namespace, name) -} - -func (c *roleBindingController) EnqueueAfter(namespace, name string, duration time.Duration) { - c.controller.EnqueueAfter(namespace, name, duration) -} - -func (c *roleBindingController) Informer() cache.SharedIndexInformer { - return c.controller.Informer() -} - -func (c *roleBindingController) GroupVersionKind() schema.GroupVersionKind { - return c.gvk -} - -func (c *roleBindingController) Cache() RoleBindingCache { - return &roleBindingCache{ - indexer: c.Informer().GetIndexer(), - resource: c.groupResource, - } -} - -func (c *roleBindingController) Create(obj *v1.RoleBinding) (*v1.RoleBinding, error) { - result := &v1.RoleBinding{} - return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{}) -} - -func (c *roleBindingController) Update(obj *v1.RoleBinding) (*v1.RoleBinding, error) { - result := &v1.RoleBinding{} - return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{}) -} - -func (c *roleBindingController) Delete(namespace, name string, options *metav1.DeleteOptions) error { - if options == nil { - options = &metav1.DeleteOptions{} - } - return c.client.Delete(context.TODO(), namespace, name, *options) -} - -func (c *roleBindingController) Get(namespace, name string, options metav1.GetOptions) (*v1.RoleBinding, error) { - result := &v1.RoleBinding{} - return result, c.client.Get(context.TODO(), namespace, name, result, options) -} - -func (c *roleBindingController) List(namespace string, opts metav1.ListOptions) (*v1.RoleBindingList, error) { - result := &v1.RoleBindingList{} - return result, c.client.List(context.TODO(), namespace, result, opts) -} - -func (c *roleBindingController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) { - return c.client.Watch(context.TODO(), namespace, opts) -} - -func (c *roleBindingController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.RoleBinding, error) { - result := &v1.RoleBinding{} - return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...) -} - -type roleBindingCache struct { - indexer cache.Indexer - resource schema.GroupResource -} - -func (c *roleBindingCache) Get(namespace, name string) (*v1.RoleBinding, error) { - obj, exists, err := c.indexer.GetByKey(namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(c.resource, name) - } - return obj.(*v1.RoleBinding), nil -} - -func (c *roleBindingCache) List(namespace string, selector labels.Selector) (ret []*v1.RoleBinding, err error) { - - err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1.RoleBinding)) - }) - - return ret, err -} - -func (c *roleBindingCache) AddIndexer(indexName string, indexer RoleBindingIndexer) { - utilruntime.Must(c.indexer.AddIndexers(map[string]cache.IndexFunc{ - indexName: func(obj interface{}) (strings []string, e error) { - return indexer(obj.(*v1.RoleBinding)) - }, - })) -} - -func (c *roleBindingCache) GetByIndex(indexName, key string) (result []*v1.RoleBinding, err error) { - objs, err := c.indexer.ByIndex(indexName, key) - if err != nil { - return nil, err - } - result = make([]*v1.RoleBinding, 0, len(objs)) - for _, obj := range objs { - result = append(result, obj.(*v1.RoleBinding)) - } - return result, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generic/controller.go b/vendor/github.com/rancher/wrangler/pkg/generic/controller.go deleted file mode 100644 index d713e0f2be..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generic/controller.go +++ /dev/null @@ -1,24 +0,0 @@ -package generic - -import ( - "context" - - "github.com/rancher/lasso/pkg/controller" - - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/tools/cache" -) - -var ErrSkip = controller.ErrIgnore - -type Handler func(key string, obj runtime.Object) (runtime.Object, error) - -type ControllerMeta interface { - Informer() cache.SharedIndexInformer - GroupVersionKind() schema.GroupVersionKind - - AddGenericHandler(ctx context.Context, name string, handler Handler) - AddGenericRemoveHandler(ctx context.Context, name string, handler Handler) - Updater() Updater -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generic/factory.go b/vendor/github.com/rancher/wrangler/pkg/generic/factory.go deleted file mode 100644 index ce4370d9ce..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generic/factory.go +++ /dev/null @@ -1,122 +0,0 @@ -package generic - -import ( - "context" - "sync" - "time" - - "github.com/rancher/lasso/pkg/log" - "github.com/sirupsen/logrus" - - "github.com/rancher/lasso/pkg/cache" - "github.com/rancher/lasso/pkg/client" - "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/schemes" - "k8s.io/apimachinery/pkg/runtime/schema" - utilruntime "k8s.io/apimachinery/pkg/util/runtime" - "k8s.io/client-go/rest" -) - -func init() { - log.Infof = logrus.Infof - log.Errorf = logrus.Errorf -} - -type Factory struct { - lock sync.Mutex - cacheFactory cache.SharedCacheFactory - controllerFactory controller.SharedControllerFactory - threadiness map[schema.GroupVersionKind]int - config *rest.Config - opts FactoryOptions -} - -type FactoryOptions struct { - Namespace string - Resync time.Duration - SharedCacheFactory cache.SharedCacheFactory - SharedControllerFactory controller.SharedControllerFactory - HealthCallback func(bool) -} - -func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) { - if opts == nil { - opts = &FactoryOptions{} - } - - f := &Factory{ - config: config, - threadiness: map[schema.GroupVersionKind]int{}, - cacheFactory: opts.SharedCacheFactory, - controllerFactory: opts.SharedControllerFactory, - opts: *opts, - } - - if f.cacheFactory == nil && f.controllerFactory != nil { - f.cacheFactory = f.controllerFactory.SharedCacheFactory() - } - - return f, nil -} - -func (c *Factory) SetThreadiness(gvk schema.GroupVersionKind, threadiness int) { - c.threadiness[gvk] = threadiness -} - -func (c *Factory) ControllerFactory() controller.SharedControllerFactory { - err := c.setControllerFactoryWithLock() - utilruntime.Must(err) - return c.controllerFactory -} - -func (c *Factory) setControllerFactoryWithLock() error { - c.lock.Lock() - defer c.lock.Unlock() - - if c.controllerFactory != nil { - return nil - } - - cacheFactory := c.cacheFactory - if cacheFactory == nil { - client, err := client.NewSharedClientFactory(c.config, &client.SharedClientFactoryOptions{ - Scheme: schemes.All, - }) - if err != nil { - return err - } - - cacheFactory = cache.NewSharedCachedFactory(client, &cache.SharedCacheFactoryOptions{ - DefaultNamespace: c.opts.Namespace, - DefaultResync: c.opts.Resync, - HealthCallback: c.opts.HealthCallback, - }) - } - - c.cacheFactory = cacheFactory - c.controllerFactory = controller.NewSharedControllerFactory(cacheFactory, &controller.SharedControllerFactoryOptions{ - KindWorkers: c.threadiness, - }) - - return nil -} - -func (c *Factory) Sync(ctx context.Context) error { - if c.cacheFactory != nil { - _ = c.cacheFactory.Start(ctx) - c.cacheFactory.WaitForCacheSync(ctx) - } - return nil -} - -func (c *Factory) Start(ctx context.Context, defaultThreadiness int) error { - if err := c.Sync(ctx); err != nil { - return err - } - - if c.controllerFactory != nil { - return c.controllerFactory.Start(ctx, defaultThreadiness) - } - - return nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generic/generating.go b/vendor/github.com/rancher/wrangler/pkg/generic/generating.go deleted file mode 100644 index 3063e47f09..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generic/generating.go +++ /dev/null @@ -1,41 +0,0 @@ -package generic - -import ( - "github.com/rancher/wrangler/pkg/apply" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type GeneratingHandlerOptions struct { - AllowCrossNamespace bool - AllowClusterScoped bool - NoOwnerReference bool - DynamicLookup bool - // UniqueApplyForResourceVersion will skip calling apply if the resource version didn't change from the previous execution - UniqueApplyForResourceVersion bool -} - -func ConfigureApplyForObject(apply apply.Apply, obj metav1.Object, opts *GeneratingHandlerOptions) apply.Apply { - if opts == nil { - opts = &GeneratingHandlerOptions{} - } - - if opts.DynamicLookup { - apply = apply.WithDynamicLookup() - } - - if opts.NoOwnerReference { - apply = apply.WithSetOwnerReference(true, false) - } - - if opts.AllowCrossNamespace && !opts.AllowClusterScoped { - apply = apply. - WithDefaultNamespace(obj.GetNamespace()). - WithListerNamespace(obj.GetNamespace()) - } - - if !opts.AllowClusterScoped { - apply = apply.WithRestrictClusterScoped() - } - - return apply -} diff --git a/vendor/github.com/rancher/wrangler/pkg/generic/remove.go b/vendor/github.com/rancher/wrangler/pkg/generic/remove.go deleted file mode 100644 index 4bfd35238d..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/generic/remove.go +++ /dev/null @@ -1,119 +0,0 @@ -package generic - -import ( - "k8s.io/apimachinery/pkg/api/meta" - "k8s.io/apimachinery/pkg/runtime" -) - -var ( - finalizerKey = "wrangler.cattle.io/" -) - -type Updater func(runtime.Object) (runtime.Object, error) - -type objectLifecycleAdapter struct { - name string - handler Handler - updater Updater -} - -func NewRemoveHandler(name string, updater Updater, handler Handler) Handler { - o := objectLifecycleAdapter{ - name: name, - handler: handler, - updater: updater, - } - return o.sync -} - -func (o *objectLifecycleAdapter) sync(key string, obj runtime.Object) (runtime.Object, error) { - if obj == nil { - return nil, nil - } - - metadata, err := meta.Accessor(obj) - if err != nil { - return obj, err - } - - if metadata.GetDeletionTimestamp() == nil { - return o.addFinalizer(obj) - } - - if !o.hasFinalizer(obj) { - return obj, nil - } - - newObj, err := o.handler(key, obj) - if err != nil { - return newObj, err - } - - if newObj != nil { - obj = newObj - } - - return o.removeFinalizer(obj) -} - -func (o *objectLifecycleAdapter) constructFinalizerKey() string { - return finalizerKey + o.name -} - -func (o *objectLifecycleAdapter) hasFinalizer(obj runtime.Object) bool { - metadata, err := meta.Accessor(obj) - if err != nil { - return false - } - - finalizerKey := o.constructFinalizerKey() - finalizers := metadata.GetFinalizers() - for _, finalizer := range finalizers { - if finalizer == finalizerKey { - return true - } - } - - return false -} - -func (o *objectLifecycleAdapter) removeFinalizer(obj runtime.Object) (runtime.Object, error) { - if !o.hasFinalizer(obj) { - return obj, nil - } - - obj = obj.DeepCopyObject() - metadata, err := meta.Accessor(obj) - if err != nil { - return obj, err - } - - finalizerKey := o.constructFinalizerKey() - finalizers := metadata.GetFinalizers() - - var newFinalizers []string - for k, v := range finalizers { - if v != finalizerKey { - continue - } - newFinalizers = append(finalizers[:k], finalizers[k+1:]...) - } - - metadata.SetFinalizers(newFinalizers) - return o.updater(obj) -} - -func (o *objectLifecycleAdapter) addFinalizer(obj runtime.Object) (runtime.Object, error) { - if o.hasFinalizer(obj) { - return obj, nil - } - - obj = obj.DeepCopyObject() - metadata, err := meta.Accessor(obj) - if err != nil { - return nil, err - } - - metadata.SetFinalizers(append(metadata.GetFinalizers(), o.constructFinalizerKey())) - return o.updater(obj) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/gvk/detect.go b/vendor/github.com/rancher/wrangler/pkg/gvk/detect.go deleted file mode 100644 index a8c16b86fd..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/gvk/detect.go +++ /dev/null @@ -1,19 +0,0 @@ -package gvk - -import ( - "encoding/json" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -func Detect(obj []byte) (schema.GroupVersionKind, bool, error) { - partial := v1.PartialObjectMetadata{} - if err := json.Unmarshal(obj, &partial); err != nil { - return schema.GroupVersionKind{}, false, err - } - - result := partial.GetObjectKind().GroupVersionKind() - ok := result.Kind != "" && result.Version != "" - return result, ok, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/gvk/get.go b/vendor/github.com/rancher/wrangler/pkg/gvk/get.go deleted file mode 100644 index 743dc00b1c..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/gvk/get.go +++ /dev/null @@ -1,57 +0,0 @@ -package gvk - -import ( - "fmt" - - "github.com/pkg/errors" - "github.com/rancher/wrangler/pkg/schemes" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -func Get(obj runtime.Object) (schema.GroupVersionKind, error) { - gvk := obj.GetObjectKind().GroupVersionKind() - if gvk.Kind != "" { - return gvk, nil - } - - gvks, _, err := schemes.All.ObjectKinds(obj) - if err != nil { - return schema.GroupVersionKind{}, errors.Wrapf(err, "failed to find gvk for %T, you may need to import the wrangler generated controller package", obj) - } - - if len(gvks) == 0 { - return schema.GroupVersionKind{}, fmt.Errorf("failed to find gvk for %T", obj) - } - - return gvks[0], nil -} - -func Set(objs ...runtime.Object) error { - for _, obj := range objs { - if err := setObject(obj); err != nil { - return err - } - } - return nil -} - -func setObject(obj runtime.Object) error { - gvk := obj.GetObjectKind().GroupVersionKind() - if gvk.Kind != "" { - return nil - } - - gvks, _, err := schemes.All.ObjectKinds(obj) - if err != nil { - return err - } - - if len(gvks) == 0 { - return nil - } - - kind := obj.GetObjectKind() - kind.SetGroupVersionKind(gvks[0]) - return nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/kv/split.go b/vendor/github.com/rancher/wrangler/pkg/kv/split.go deleted file mode 100644 index 7368bde40d..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/kv/split.go +++ /dev/null @@ -1,45 +0,0 @@ -package kv - -import "strings" - -// Like split but if there is only one item return "", item -func RSplit(s, sep string) (string, string) { - parts := strings.SplitN(s, sep, 2) - if len(parts) == 1 { - return "", strings.TrimSpace(parts[0]) - } - return strings.TrimSpace(parts[0]), strings.TrimSpace(safeIndex(parts, 1)) -} - -func Split(s, sep string) (string, string) { - parts := strings.SplitN(s, sep, 2) - return strings.TrimSpace(parts[0]), strings.TrimSpace(safeIndex(parts, 1)) -} - -func SplitLast(s, sep string) (string, string) { - idx := strings.LastIndex(s, sep) - if idx > -1 { - return strings.TrimSpace(s[:idx]), strings.TrimSpace(s[idx+1:]) - } - return s, "" -} - -func SplitMap(s, sep string) map[string]string { - return SplitMapFromSlice(strings.Split(s, sep)) -} - -func SplitMapFromSlice(parts []string) map[string]string { - result := map[string]string{} - for _, part := range parts { - k, v := Split(part, "=") - result[k] = v - } - return result -} - -func safeIndex(parts []string, idx int) string { - if len(parts) <= idx { - return "" - } - return parts[idx] -} diff --git a/vendor/github.com/rancher/wrangler/pkg/merr/error.go b/vendor/github.com/rancher/wrangler/pkg/merr/error.go deleted file mode 100644 index 23b3c2e025..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/merr/error.go +++ /dev/null @@ -1,37 +0,0 @@ -package merr - -import "bytes" - -type Errors []error - -func (e Errors) Err() error { - return NewErrors(e...) -} - -func (e Errors) Error() string { - buf := bytes.NewBuffer(nil) - for _, err := range e { - if buf.Len() > 0 { - buf.WriteString(", ") - } - buf.WriteString(err.Error()) - } - - return buf.String() -} - -func NewErrors(inErrors ...error) error { - var errors []error - for _, err := range inErrors { - if err != nil { - errors = append(errors, err) - } - } - - if len(errors) == 0 { - return nil - } else if len(errors) == 1 { - return errors[0] - } - return Errors(errors) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/name/name.go b/vendor/github.com/rancher/wrangler/pkg/name/name.go deleted file mode 100644 index b9a01beff5..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/name/name.go +++ /dev/null @@ -1,66 +0,0 @@ -package name - -import ( - "crypto/md5" - "crypto/sha256" - "encoding/hex" - "fmt" - "strings" -) - -func GuessPluralName(name string) string { - if name == "" { - return name - } - - if strings.EqualFold(name, "Endpoints") { - return name - } - - if suffix(name, "s") || suffix(name, "ch") || suffix(name, "x") || suffix(name, "sh") { - return name + "es" - } - - if suffix(name, "f") || suffix(name, "fe") { - return name + "ves" - } - - if suffix(name, "y") && len(name) > 2 && !strings.ContainsAny(name[len(name)-2:len(name)-1], "[aeiou]") { - return name[0:len(name)-1] + "ies" - } - - return name + "s" -} - -func suffix(str, end string) bool { - return strings.HasSuffix(str, end) -} - -func Limit(s string, count int) string { - if len(s) < count { - return s - } - return fmt.Sprintf("%s-%s", s[:count-6], Hex(s, 5)) -} - -func Hex(s string, length int) string { - h := md5.Sum([]byte(s)) - d := hex.EncodeToString(h[:]) - return d[:length] -} - -func SafeConcatName(name ...string) string { - fullPath := strings.Join(name, "-") - if len(fullPath) < 64 { - return fullPath - } - digest := sha256.Sum256([]byte(fullPath)) - // since we cut the string in the middle, the last char may not be compatible with what is expected in k8s - // we are checking and if necessary removing the last char - c := fullPath[56] - if 'a' <= c && c <= 'z' || '0' <= c && c <= '9' { - return fullPath[0:57] + "-" + hex.EncodeToString(digest[0:])[0:5] - } - - return fullPath[0:56] + "-" + hex.EncodeToString(digest[0:])[0:6] -} diff --git a/vendor/github.com/rancher/wrangler/pkg/objectset/objectset.go b/vendor/github.com/rancher/wrangler/pkg/objectset/objectset.go deleted file mode 100644 index d6c066f098..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/objectset/objectset.go +++ /dev/null @@ -1,219 +0,0 @@ -package objectset - -import ( - "fmt" - "reflect" - "sort" - - "github.com/pkg/errors" - "github.com/rancher/wrangler/pkg/gvk" - "github.com/rancher/wrangler/pkg/stringset" - - "github.com/rancher/wrangler/pkg/merr" - "k8s.io/apimachinery/pkg/api/meta" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" -) - -type ObjectKey struct { - Name string - Namespace string -} - -func NewObjectKey(obj v1.Object) ObjectKey { - return ObjectKey{ - Namespace: obj.GetNamespace(), - Name: obj.GetName(), - } -} - -func (o ObjectKey) String() string { - if o.Namespace == "" { - return o.Name - } - return fmt.Sprintf("%s/%s", o.Namespace, o.Name) -} - -type ObjectKeyByGVK map[schema.GroupVersionKind][]ObjectKey - -type ObjectByGVK map[schema.GroupVersionKind]map[ObjectKey]runtime.Object - -func (o ObjectByGVK) Add(obj runtime.Object) (schema.GroupVersionKind, error) { - metadata, err := meta.Accessor(obj) - if err != nil { - return schema.GroupVersionKind{}, err - } - - gvk, err := gvk.Get(obj) - if err != nil { - return schema.GroupVersionKind{}, err - } - - objs := o[gvk] - if objs == nil { - objs = ObjectByKey{} - o[gvk] = objs - } - - objs[ObjectKey{ - Namespace: metadata.GetNamespace(), - Name: metadata.GetName(), - }] = obj - - return gvk, nil -} - -type ObjectSet struct { - errs []error - objects ObjectByGVK - objectsByGK ObjectByGK - order []runtime.Object - gvkOrder []schema.GroupVersionKind - gvkSeen map[schema.GroupVersionKind]bool -} - -func NewObjectSet(objs ...runtime.Object) *ObjectSet { - os := &ObjectSet{ - objects: ObjectByGVK{}, - objectsByGK: ObjectByGK{}, - gvkSeen: map[schema.GroupVersionKind]bool{}, - } - os.Add(objs...) - return os -} - -func (o *ObjectSet) ObjectsByGVK() ObjectByGVK { - if o == nil { - return nil - } - return o.objects -} - -func (o *ObjectSet) Contains(gk schema.GroupKind, key ObjectKey) bool { - _, ok := o.objectsByGK[gk][key] - return ok -} - -func (o *ObjectSet) All() []runtime.Object { - return o.order -} - -func (o *ObjectSet) Add(objs ...runtime.Object) *ObjectSet { - for _, obj := range objs { - o.add(obj) - } - return o -} - -func (o *ObjectSet) add(obj runtime.Object) { - if obj == nil || reflect.ValueOf(obj).IsNil() { - return - } - - gvk, err := o.objects.Add(obj) - if err != nil { - o.err(errors.Wrapf(err, "failed to add %T", obj)) - return - } - - _, err = o.objectsByGK.Add(obj) - if err != nil { - o.err(errors.Wrapf(err, "failed to add %T", obj)) - return - } - - o.order = append(o.order, obj) - if !o.gvkSeen[gvk] { - o.gvkSeen[gvk] = true - o.gvkOrder = append(o.gvkOrder, gvk) - } -} - -func (o *ObjectSet) err(err error) error { - o.errs = append(o.errs, err) - return o.Err() -} - -func (o *ObjectSet) AddErr(err error) { - o.errs = append(o.errs, err) -} - -func (o *ObjectSet) Err() error { - return merr.NewErrors(o.errs...) -} - -func (o *ObjectSet) Len() int { - return len(o.objects) -} - -func (o *ObjectSet) GVKs() []schema.GroupVersionKind { - return o.GVKOrder() -} - -func (o *ObjectSet) GVKOrder(known ...schema.GroupVersionKind) []schema.GroupVersionKind { - var rest []schema.GroupVersionKind - - for _, gvk := range known { - if o.gvkSeen[gvk] { - continue - } - rest = append(rest, gvk) - } - - sort.Slice(rest, func(i, j int) bool { - return rest[i].String() < rest[j].String() - }) - - return append(o.gvkOrder, rest...) -} - -// Namespaces all distinct namespaces found on the objects in this set. -func (o *ObjectSet) Namespaces() []string { - namespaces := stringset.Set{} - for _, objsByKey := range o.ObjectsByGVK() { - for objKey := range objsByKey { - namespaces.Add(objKey.Namespace) - } - } - return namespaces.Values() -} - -type ObjectByKey map[ObjectKey]runtime.Object - -func (o ObjectByKey) Namespaces() []string { - namespaces := stringset.Set{} - for objKey := range o { - namespaces.Add(objKey.Namespace) - } - return namespaces.Values() -} - -type ObjectByGK map[schema.GroupKind]map[ObjectKey]runtime.Object - -func (o ObjectByGK) Add(obj runtime.Object) (schema.GroupKind, error) { - metadata, err := meta.Accessor(obj) - if err != nil { - return schema.GroupKind{}, err - } - - gvk, err := gvk.Get(obj) - if err != nil { - return schema.GroupKind{}, err - } - - gk := gvk.GroupKind() - - objs := o[gk] - if objs == nil { - objs = ObjectByKey{} - o[gk] = objs - } - - objs[ObjectKey{ - Namespace: metadata.GetNamespace(), - Name: metadata.GetName(), - }] = obj - - return gk, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/patch/apply.go b/vendor/github.com/rancher/wrangler/pkg/patch/apply.go deleted file mode 100644 index da9a25d33a..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/patch/apply.go +++ /dev/null @@ -1,57 +0,0 @@ -package patch - -import ( - "encoding/json" - "fmt" - - jsonpatch "github.com/evanphx/json-patch" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/strategicpatch" -) - -func Apply(original, patch []byte) ([]byte, error) { - style, metadata, err := GetPatchStyle(original, patch) - if err != nil { - return nil, err - } - - switch style { - case types.JSONPatchType: - return applyJSONPatch(original, patch) - case types.MergePatchType: - return applyMergePatch(original, patch) - case types.StrategicMergePatchType: - return applyStrategicMergePatch(original, patch, metadata) - default: - return nil, fmt.Errorf("invalid patch") - } -} - -func applyStrategicMergePatch(original, patch []byte, lookup strategicpatch.LookupPatchMeta) ([]byte, error) { - originalMap := map[string]interface{}{} - patchMap := map[string]interface{}{} - if err := json.Unmarshal(original, &originalMap); err != nil { - return nil, err - } - if err := json.Unmarshal(patch, &patchMap); err != nil { - return nil, err - } - patchedMap, err := strategicpatch.StrategicMergeMapPatchUsingLookupPatchMeta(originalMap, patchMap, lookup) - if err != nil { - return nil, err - } - return json.Marshal(patchedMap) -} - -func applyMergePatch(original, patch []byte) ([]byte, error) { - return jsonpatch.MergePatch(original, patch) -} - -func applyJSONPatch(original, patch []byte) ([]byte, error) { - jsonPatch, err := jsonpatch.DecodePatch(patch) - if err != nil { - return nil, err - } - - return jsonPatch.Apply(original) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/patch/style.go b/vendor/github.com/rancher/wrangler/pkg/patch/style.go deleted file mode 100644 index 88135c8d54..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/patch/style.go +++ /dev/null @@ -1,79 +0,0 @@ -package patch - -import ( - "sync" - - "github.com/rancher/wrangler/pkg/gvk" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/strategicpatch" - "k8s.io/client-go/kubernetes/scheme" -) - -var ( - patchCache = map[schema.GroupVersionKind]patchCacheEntry{} - patchCacheLock = sync.Mutex{} -) - -type patchCacheEntry struct { - patchType types.PatchType - lookup strategicpatch.LookupPatchMeta -} - -func isJSONPatch(patch []byte) bool { - // a JSON patch is a list - return len(patch) > 0 && patch[0] == '[' -} - -func GetPatchStyle(original, patch []byte) (types.PatchType, strategicpatch.LookupPatchMeta, error) { - if isJSONPatch(patch) { - return types.JSONPatchType, nil, nil - } - gvk, ok, err := gvk.Detect(original) - if err != nil { - return "", nil, err - } - if !ok { - return types.MergePatchType, nil, nil - } - return GetMergeStyle(gvk) -} - -func GetMergeStyle(gvk schema.GroupVersionKind) (types.PatchType, strategicpatch.LookupPatchMeta, error) { - var ( - patchType types.PatchType - lookupPatchMeta strategicpatch.LookupPatchMeta - ) - - patchCacheLock.Lock() - entry, ok := patchCache[gvk] - patchCacheLock.Unlock() - - if ok { - return entry.patchType, entry.lookup, nil - } - - versionedObject, err := scheme.Scheme.New(gvk) - - if runtime.IsNotRegisteredError(err) || gvk.Kind == "CustomResourceDefinition" { - patchType = types.MergePatchType - } else if err != nil { - return patchType, nil, err - } else { - patchType = types.StrategicMergePatchType - lookupPatchMeta, err = strategicpatch.NewPatchMetaFromStruct(versionedObject) - if err != nil { - return patchType, nil, err - } - } - - patchCacheLock.Lock() - patchCache[gvk] = patchCacheEntry{ - patchType: patchType, - lookup: lookupPatchMeta, - } - patchCacheLock.Unlock() - - return patchType, lookupPatchMeta, nil -} diff --git a/vendor/github.com/rancher/wrangler/pkg/schemes/all.go b/vendor/github.com/rancher/wrangler/pkg/schemes/all.go deleted file mode 100644 index 0b87075c3f..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/schemes/all.go +++ /dev/null @@ -1,20 +0,0 @@ -package schemes - -import ( - "github.com/rancher/lasso/pkg/scheme" - "k8s.io/apimachinery/pkg/runtime" -) - -var ( - All = scheme.All - localSchemeBuilder = runtime.NewSchemeBuilder() -) - -func Register(addToScheme func(*runtime.Scheme) error) error { - localSchemeBuilder = append(localSchemeBuilder, addToScheme) - return addToScheme(All) -} - -func AddToScheme(scheme *runtime.Scheme) error { - return localSchemeBuilder.AddToScheme(scheme) -} diff --git a/vendor/github.com/rancher/wrangler/pkg/stringset/stringset.go b/vendor/github.com/rancher/wrangler/pkg/stringset/stringset.go deleted file mode 100644 index f9f7b192ef..0000000000 --- a/vendor/github.com/rancher/wrangler/pkg/stringset/stringset.go +++ /dev/null @@ -1,51 +0,0 @@ -package stringset - -var empty struct{} - -// Set is an exceptionally simple `set` implementation for strings. -// It is not threadsafe, but can be used in place of a simple `map[string]struct{}` -// as long as you don't want to do too much with it. -type Set struct { - m map[string]struct{} -} - -func (s *Set) Add(ss ...string) { - if s.m == nil { - s.m = make(map[string]struct{}, len(ss)) - } - for _, k := range ss { - s.m[k] = empty - } -} - -func (s *Set) Delete(ss ...string) { - if s.m == nil { - return - } - for _, k := range ss { - delete(s.m, k) - } -} - -func (s *Set) Has(ss string) bool { - if s.m == nil { - return false - } - _, ok := s.m[ss] - return ok -} - -func (s *Set) Len() int { - return len(s.m) -} - -func (s *Set) Values() []string { - i := 0 - keys := make([]string, len(s.m)) - for key := range s.m { - keys[i] = key - i++ - } - - return keys -} diff --git a/vendor/github.com/rancher/wrangler/pkg/clients/clients.go b/vendor/github.com/rancher/wrangler/v3/pkg/clients/clients.go similarity index 77% rename from vendor/github.com/rancher/wrangler/pkg/clients/clients.go rename to vendor/github.com/rancher/wrangler/v3/pkg/clients/clients.go index 38a448b4d1..4400070b4c 100644 --- a/vendor/github.com/rancher/wrangler/pkg/clients/clients.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/clients/clients.go @@ -6,23 +6,23 @@ import ( "github.com/rancher/lasso/pkg/controller" "github.com/rancher/lasso/pkg/dynamic" - "github.com/rancher/wrangler/pkg/apply" - admissionreg "github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io" - admissionregcontrollers "github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1" - "github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io" - crdcontrollers "github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1" - "github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io" - apicontrollers "github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/v1" - "github.com/rancher/wrangler/pkg/generated/controllers/apps" - appcontrollers "github.com/rancher/wrangler/pkg/generated/controllers/apps/v1" - "github.com/rancher/wrangler/pkg/generated/controllers/batch" - batchcontrollers "github.com/rancher/wrangler/pkg/generated/controllers/batch/v1" - "github.com/rancher/wrangler/pkg/generated/controllers/core" - corecontrollers "github.com/rancher/wrangler/pkg/generated/controllers/core/v1" - "github.com/rancher/wrangler/pkg/generated/controllers/rbac" - rbaccontrollers "github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1" - "github.com/rancher/wrangler/pkg/generic" - "github.com/rancher/wrangler/pkg/ratelimit" + "github.com/rancher/wrangler/v3/pkg/apply" + admissionreg "github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io" + admissionregcontrollers "github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1" + "github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io" + crdcontrollers "github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/v1" + "github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io" + apicontrollers "github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/v1" + "github.com/rancher/wrangler/v3/pkg/generated/controllers/apps" + appcontrollers "github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1" + "github.com/rancher/wrangler/v3/pkg/generated/controllers/batch" + batchcontrollers "github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/v1" + "github.com/rancher/wrangler/v3/pkg/generated/controllers/core" + corecontrollers "github.com/rancher/wrangler/v3/pkg/generated/controllers/core/v1" + "github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac" + rbaccontrollers "github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/ratelimit" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/client-go/discovery" "k8s.io/client-go/discovery/cached/memory" diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/factory.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/factory.go similarity index 97% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/factory.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/factory.go index ed2b446d01..8eebee5f0b 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/factory.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/factory.go @@ -20,7 +20,7 @@ package admissionregistration import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/generic" "k8s.io/client-go/rest" ) diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/interface.go similarity index 91% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/interface.go index 9f444b8b59..be988cd120 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/interface.go @@ -20,7 +20,7 @@ package admissionregistration import ( "github.com/rancher/lasso/pkg/controller" - v1 "github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1" + v1 "github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1" ) type Interface interface { diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1/interface.go similarity index 61% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1/interface.go index aa9801038f..2c76497d72 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1/interface.go @@ -20,7 +20,8 @@ package v1 import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/schemes" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/schemes" v1 "k8s.io/api/admissionregistration/v1" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -44,9 +45,10 @@ type version struct { controllerFactory controller.SharedControllerFactory } -func (c *version) MutatingWebhookConfiguration() MutatingWebhookConfigurationController { - return NewMutatingWebhookConfigurationController(schema.GroupVersionKind{Group: "admissionregistration.k8s.io", Version: "v1", Kind: "MutatingWebhookConfiguration"}, "mutatingwebhookconfigurations", false, c.controllerFactory) +func (v *version) MutatingWebhookConfiguration() MutatingWebhookConfigurationController { + return generic.NewNonNamespacedController[*v1.MutatingWebhookConfiguration, *v1.MutatingWebhookConfigurationList](schema.GroupVersionKind{Group: "admissionregistration.k8s.io", Version: "v1", Kind: "MutatingWebhookConfiguration"}, "mutatingwebhookconfigurations", v.controllerFactory) } -func (c *version) ValidatingWebhookConfiguration() ValidatingWebhookConfigurationController { - return NewValidatingWebhookConfigurationController(schema.GroupVersionKind{Group: "admissionregistration.k8s.io", Version: "v1", Kind: "ValidatingWebhookConfiguration"}, "validatingwebhookconfigurations", false, c.controllerFactory) + +func (v *version) ValidatingWebhookConfiguration() ValidatingWebhookConfigurationController { + return generic.NewNonNamespacedController[*v1.ValidatingWebhookConfiguration, *v1.ValidatingWebhookConfigurationList](schema.GroupVersionKind{Group: "admissionregistration.k8s.io", Version: "v1", Kind: "ValidatingWebhookConfiguration"}, "validatingwebhookconfigurations", v.controllerFactory) } diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1/mutatingwebhookconfiguration.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1/mutatingwebhookconfiguration.go new file mode 100644 index 0000000000..3dd7e281f4 --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1/mutatingwebhookconfiguration.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "github.com/rancher/wrangler/v3/pkg/generic" + v1 "k8s.io/api/admissionregistration/v1" +) + +// MutatingWebhookConfigurationController interface for managing MutatingWebhookConfiguration resources. +type MutatingWebhookConfigurationController interface { + generic.NonNamespacedControllerInterface[*v1.MutatingWebhookConfiguration, *v1.MutatingWebhookConfigurationList] +} + +// MutatingWebhookConfigurationClient interface for managing MutatingWebhookConfiguration resources in Kubernetes. +type MutatingWebhookConfigurationClient interface { + generic.NonNamespacedClientInterface[*v1.MutatingWebhookConfiguration, *v1.MutatingWebhookConfigurationList] +} + +// MutatingWebhookConfigurationCache interface for retrieving MutatingWebhookConfiguration resources in memory. +type MutatingWebhookConfigurationCache interface { + generic.NonNamespacedCacheInterface[*v1.MutatingWebhookConfiguration] +} diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1/validatingwebhookconfiguration.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1/validatingwebhookconfiguration.go new file mode 100644 index 0000000000..10076c5521 --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1/validatingwebhookconfiguration.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "github.com/rancher/wrangler/v3/pkg/generic" + v1 "k8s.io/api/admissionregistration/v1" +) + +// ValidatingWebhookConfigurationController interface for managing ValidatingWebhookConfiguration resources. +type ValidatingWebhookConfigurationController interface { + generic.NonNamespacedControllerInterface[*v1.ValidatingWebhookConfiguration, *v1.ValidatingWebhookConfigurationList] +} + +// ValidatingWebhookConfigurationClient interface for managing ValidatingWebhookConfiguration resources in Kubernetes. +type ValidatingWebhookConfigurationClient interface { + generic.NonNamespacedClientInterface[*v1.ValidatingWebhookConfiguration, *v1.ValidatingWebhookConfigurationList] +} + +// ValidatingWebhookConfigurationCache interface for retrieving ValidatingWebhookConfiguration resources in memory. +type ValidatingWebhookConfigurationCache interface { + generic.NonNamespacedCacheInterface[*v1.ValidatingWebhookConfiguration] +} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/factory.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/factory.go similarity index 97% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/factory.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/factory.go index d8f0269638..d65ff84abe 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/factory.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/factory.go @@ -20,7 +20,7 @@ package apiextensions import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/generic" "k8s.io/client-go/rest" ) diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/interface.go similarity index 92% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/interface.go index b3e0865566..8c2c5e86e4 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/interface.go @@ -20,7 +20,7 @@ package apiextensions import ( "github.com/rancher/lasso/pkg/controller" - v1 "github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1" + v1 "github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/v1" ) type Interface interface { diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/v1/customresourcedefinition.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/v1/customresourcedefinition.go new file mode 100644 index 0000000000..e378b87289 --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/v1/customresourcedefinition.go @@ -0,0 +1,208 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "context" + "sync" + "time" + + "github.com/rancher/wrangler/v3/pkg/apply" + "github.com/rancher/wrangler/v3/pkg/condition" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/kv" + v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// CustomResourceDefinitionController interface for managing CustomResourceDefinition resources. +type CustomResourceDefinitionController interface { + generic.NonNamespacedControllerInterface[*v1.CustomResourceDefinition, *v1.CustomResourceDefinitionList] +} + +// CustomResourceDefinitionClient interface for managing CustomResourceDefinition resources in Kubernetes. +type CustomResourceDefinitionClient interface { + generic.NonNamespacedClientInterface[*v1.CustomResourceDefinition, *v1.CustomResourceDefinitionList] +} + +// CustomResourceDefinitionCache interface for retrieving CustomResourceDefinition resources in memory. +type CustomResourceDefinitionCache interface { + generic.NonNamespacedCacheInterface[*v1.CustomResourceDefinition] +} + +// CustomResourceDefinitionStatusHandler is executed for every added or modified CustomResourceDefinition. Should return the new status to be updated +type CustomResourceDefinitionStatusHandler func(obj *v1.CustomResourceDefinition, status v1.CustomResourceDefinitionStatus) (v1.CustomResourceDefinitionStatus, error) + +// CustomResourceDefinitionGeneratingHandler is the top-level handler that is executed for every CustomResourceDefinition event. It extends CustomResourceDefinitionStatusHandler by a returning a slice of child objects to be passed to apply.Apply +type CustomResourceDefinitionGeneratingHandler func(obj *v1.CustomResourceDefinition, status v1.CustomResourceDefinitionStatus) ([]runtime.Object, v1.CustomResourceDefinitionStatus, error) + +// RegisterCustomResourceDefinitionStatusHandler configures a CustomResourceDefinitionController to execute a CustomResourceDefinitionStatusHandler for every events observed. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterCustomResourceDefinitionStatusHandler(ctx context.Context, controller CustomResourceDefinitionController, condition condition.Cond, name string, handler CustomResourceDefinitionStatusHandler) { + statusHandler := &customResourceDefinitionStatusHandler{ + client: controller, + condition: condition, + handler: handler, + } + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) +} + +// RegisterCustomResourceDefinitionGeneratingHandler configures a CustomResourceDefinitionController to execute a CustomResourceDefinitionGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterCustomResourceDefinitionGeneratingHandler(ctx context.Context, controller CustomResourceDefinitionController, apply apply.Apply, + condition condition.Cond, name string, handler CustomResourceDefinitionGeneratingHandler, opts *generic.GeneratingHandlerOptions) { + statusHandler := &customResourceDefinitionGeneratingHandler{ + CustomResourceDefinitionGeneratingHandler: handler, + apply: apply, + name: name, + gvk: controller.GroupVersionKind(), + } + if opts != nil { + statusHandler.opts = *opts + } + controller.OnChange(ctx, name, statusHandler.Remove) + RegisterCustomResourceDefinitionStatusHandler(ctx, controller, condition, name, statusHandler.Handle) +} + +type customResourceDefinitionStatusHandler struct { + client CustomResourceDefinitionClient + condition condition.Cond + handler CustomResourceDefinitionStatusHandler +} + +// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API +func (a *customResourceDefinitionStatusHandler) sync(key string, obj *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) { + if obj == nil { + return obj, nil + } + + origStatus := obj.Status.DeepCopy() + obj = obj.DeepCopy() + newStatus, err := a.handler(obj, obj.Status) + if err != nil { + // Revert to old status on error + newStatus = *origStatus.DeepCopy() + } + + if a.condition != "" { + if errors.IsConflict(err) { + a.condition.SetError(&newStatus, "", nil) + } else { + a.condition.SetError(&newStatus, "", err) + } + } + if !equality.Semantic.DeepEqual(origStatus, &newStatus) { + if a.condition != "" { + // Since status has changed, update the lastUpdatedTime + a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) + } + + var newErr error + obj.Status = newStatus + newObj, newErr := a.client.UpdateStatus(obj) + if err == nil { + err = newErr + } + if newErr == nil { + obj = newObj + } + } + return obj, err +} + +type customResourceDefinitionGeneratingHandler struct { + CustomResourceDefinitionGeneratingHandler + apply apply.Apply + opts generic.GeneratingHandlerOptions + gvk schema.GroupVersionKind + name string + seen sync.Map +} + +// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied +func (a *customResourceDefinitionGeneratingHandler) Remove(key string, obj *v1.CustomResourceDefinition) (*v1.CustomResourceDefinition, error) { + if obj != nil { + return obj, nil + } + + obj = &v1.CustomResourceDefinition{} + obj.Namespace, obj.Name = kv.RSplit(key, "/") + obj.SetGroupVersionKind(a.gvk) + + if a.opts.UniqueApplyForResourceVersion { + a.seen.Delete(key) + } + + return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects() +} + +// Handle executes the configured CustomResourceDefinitionGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource +func (a *customResourceDefinitionGeneratingHandler) Handle(obj *v1.CustomResourceDefinition, status v1.CustomResourceDefinitionStatus) (v1.CustomResourceDefinitionStatus, error) { + if !obj.DeletionTimestamp.IsZero() { + return status, nil + } + + objs, newStatus, err := a.CustomResourceDefinitionGeneratingHandler(obj, status) + if err != nil { + return newStatus, err + } + if !a.isNewResourceVersion(obj) { + return newStatus, nil + } + + err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects(objs...) + if err != nil { + return newStatus, err + } + a.storeResourceVersion(obj) + return newStatus, nil +} + +// isNewResourceVersion detects if a specific resource version was already successfully processed. +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *customResourceDefinitionGeneratingHandler) isNewResourceVersion(obj *v1.CustomResourceDefinition) bool { + if !a.opts.UniqueApplyForResourceVersion { + return true + } + + // Apply once per resource version + key := obj.Namespace + "/" + obj.Name + previous, ok := a.seen.Load(key) + return !ok || previous != obj.ResourceVersion +} + +// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *customResourceDefinitionGeneratingHandler) storeResourceVersion(obj *v1.CustomResourceDefinition) { + if !a.opts.UniqueApplyForResourceVersion { + return + } + + key := obj.Namespace + "/" + obj.Name + a.seen.Store(key, obj.ResourceVersion) +} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/v1/interface.go similarity index 73% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/v1/interface.go index ba505b6b73..adca45bd71 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/v1/interface.go @@ -20,7 +20,8 @@ package v1 import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/schemes" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/schemes" v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -43,6 +44,6 @@ type version struct { controllerFactory controller.SharedControllerFactory } -func (c *version) CustomResourceDefinition() CustomResourceDefinitionController { - return NewCustomResourceDefinitionController(schema.GroupVersionKind{Group: "apiextensions.k8s.io", Version: "v1", Kind: "CustomResourceDefinition"}, "customresourcedefinitions", false, c.controllerFactory) +func (v *version) CustomResourceDefinition() CustomResourceDefinitionController { + return generic.NewNonNamespacedController[*v1.CustomResourceDefinition, *v1.CustomResourceDefinitionList](schema.GroupVersionKind{Group: "apiextensions.k8s.io", Version: "v1", Kind: "CustomResourceDefinition"}, "customresourcedefinitions", v.controllerFactory) } diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/factory.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/factory.go similarity index 97% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/factory.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/factory.go index 33ec87566e..33de38d12f 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/factory.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/factory.go @@ -20,7 +20,7 @@ package apiregistration import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/generic" "k8s.io/client-go/rest" ) diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/interface.go similarity index 92% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/interface.go index 147658a4aa..0d05d763ab 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/interface.go @@ -20,7 +20,7 @@ package apiregistration import ( "github.com/rancher/lasso/pkg/controller" - v1 "github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/v1" + v1 "github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/v1" ) type Interface interface { diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/v1/apiservice.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/v1/apiservice.go new file mode 100644 index 0000000000..66703d44c7 --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/v1/apiservice.go @@ -0,0 +1,208 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "context" + "sync" + "time" + + "github.com/rancher/wrangler/v3/pkg/apply" + "github.com/rancher/wrangler/v3/pkg/condition" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/kv" + "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + v1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" +) + +// APIServiceController interface for managing APIService resources. +type APIServiceController interface { + generic.NonNamespacedControllerInterface[*v1.APIService, *v1.APIServiceList] +} + +// APIServiceClient interface for managing APIService resources in Kubernetes. +type APIServiceClient interface { + generic.NonNamespacedClientInterface[*v1.APIService, *v1.APIServiceList] +} + +// APIServiceCache interface for retrieving APIService resources in memory. +type APIServiceCache interface { + generic.NonNamespacedCacheInterface[*v1.APIService] +} + +// APIServiceStatusHandler is executed for every added or modified APIService. Should return the new status to be updated +type APIServiceStatusHandler func(obj *v1.APIService, status v1.APIServiceStatus) (v1.APIServiceStatus, error) + +// APIServiceGeneratingHandler is the top-level handler that is executed for every APIService event. It extends APIServiceStatusHandler by a returning a slice of child objects to be passed to apply.Apply +type APIServiceGeneratingHandler func(obj *v1.APIService, status v1.APIServiceStatus) ([]runtime.Object, v1.APIServiceStatus, error) + +// RegisterAPIServiceStatusHandler configures a APIServiceController to execute a APIServiceStatusHandler for every events observed. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterAPIServiceStatusHandler(ctx context.Context, controller APIServiceController, condition condition.Cond, name string, handler APIServiceStatusHandler) { + statusHandler := &aPIServiceStatusHandler{ + client: controller, + condition: condition, + handler: handler, + } + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) +} + +// RegisterAPIServiceGeneratingHandler configures a APIServiceController to execute a APIServiceGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterAPIServiceGeneratingHandler(ctx context.Context, controller APIServiceController, apply apply.Apply, + condition condition.Cond, name string, handler APIServiceGeneratingHandler, opts *generic.GeneratingHandlerOptions) { + statusHandler := &aPIServiceGeneratingHandler{ + APIServiceGeneratingHandler: handler, + apply: apply, + name: name, + gvk: controller.GroupVersionKind(), + } + if opts != nil { + statusHandler.opts = *opts + } + controller.OnChange(ctx, name, statusHandler.Remove) + RegisterAPIServiceStatusHandler(ctx, controller, condition, name, statusHandler.Handle) +} + +type aPIServiceStatusHandler struct { + client APIServiceClient + condition condition.Cond + handler APIServiceStatusHandler +} + +// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API +func (a *aPIServiceStatusHandler) sync(key string, obj *v1.APIService) (*v1.APIService, error) { + if obj == nil { + return obj, nil + } + + origStatus := obj.Status.DeepCopy() + obj = obj.DeepCopy() + newStatus, err := a.handler(obj, obj.Status) + if err != nil { + // Revert to old status on error + newStatus = *origStatus.DeepCopy() + } + + if a.condition != "" { + if errors.IsConflict(err) { + a.condition.SetError(&newStatus, "", nil) + } else { + a.condition.SetError(&newStatus, "", err) + } + } + if !equality.Semantic.DeepEqual(origStatus, &newStatus) { + if a.condition != "" { + // Since status has changed, update the lastUpdatedTime + a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) + } + + var newErr error + obj.Status = newStatus + newObj, newErr := a.client.UpdateStatus(obj) + if err == nil { + err = newErr + } + if newErr == nil { + obj = newObj + } + } + return obj, err +} + +type aPIServiceGeneratingHandler struct { + APIServiceGeneratingHandler + apply apply.Apply + opts generic.GeneratingHandlerOptions + gvk schema.GroupVersionKind + name string + seen sync.Map +} + +// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied +func (a *aPIServiceGeneratingHandler) Remove(key string, obj *v1.APIService) (*v1.APIService, error) { + if obj != nil { + return obj, nil + } + + obj = &v1.APIService{} + obj.Namespace, obj.Name = kv.RSplit(key, "/") + obj.SetGroupVersionKind(a.gvk) + + if a.opts.UniqueApplyForResourceVersion { + a.seen.Delete(key) + } + + return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects() +} + +// Handle executes the configured APIServiceGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource +func (a *aPIServiceGeneratingHandler) Handle(obj *v1.APIService, status v1.APIServiceStatus) (v1.APIServiceStatus, error) { + if !obj.DeletionTimestamp.IsZero() { + return status, nil + } + + objs, newStatus, err := a.APIServiceGeneratingHandler(obj, status) + if err != nil { + return newStatus, err + } + if !a.isNewResourceVersion(obj) { + return newStatus, nil + } + + err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects(objs...) + if err != nil { + return newStatus, err + } + a.storeResourceVersion(obj) + return newStatus, nil +} + +// isNewResourceVersion detects if a specific resource version was already successfully processed. +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *aPIServiceGeneratingHandler) isNewResourceVersion(obj *v1.APIService) bool { + if !a.opts.UniqueApplyForResourceVersion { + return true + } + + // Apply once per resource version + key := obj.Namespace + "/" + obj.Name + previous, ok := a.seen.Load(key) + return !ok || previous != obj.ResourceVersion +} + +// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *aPIServiceGeneratingHandler) storeResourceVersion(obj *v1.APIService) { + if !a.opts.UniqueApplyForResourceVersion { + return + } + + key := obj.Namespace + "/" + obj.Name + a.seen.Store(key, obj.ResourceVersion) +} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/v1/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/v1/interface.go similarity index 75% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/v1/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/v1/interface.go index cfb2107657..fdbcd73a83 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/v1/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/v1/interface.go @@ -20,7 +20,8 @@ package v1 import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/schemes" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/schemes" "k8s.io/apimachinery/pkg/runtime/schema" v1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" ) @@ -43,6 +44,6 @@ type version struct { controllerFactory controller.SharedControllerFactory } -func (c *version) APIService() APIServiceController { - return NewAPIServiceController(schema.GroupVersionKind{Group: "apiregistration.k8s.io", Version: "v1", Kind: "APIService"}, "apiservices", false, c.controllerFactory) +func (v *version) APIService() APIServiceController { + return generic.NewNonNamespacedController[*v1.APIService, *v1.APIServiceList](schema.GroupVersionKind{Group: "apiregistration.k8s.io", Version: "v1", Kind: "APIService"}, "apiservices", v.controllerFactory) } diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/factory.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/factory.go similarity index 97% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/factory.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/factory.go index bcaae25686..325647b548 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/factory.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/factory.go @@ -20,7 +20,7 @@ package apps import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/generic" "k8s.io/client-go/rest" ) diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/interface.go similarity index 93% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/interface.go index 4f91f157d9..59978efe10 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/interface.go @@ -20,7 +20,7 @@ package apps import ( "github.com/rancher/lasso/pkg/controller" - v1 "github.com/rancher/wrangler/pkg/generated/controllers/apps/v1" + v1 "github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1" ) type Interface interface { diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/daemonset.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/daemonset.go new file mode 100644 index 0000000000..2732d3535d --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/daemonset.go @@ -0,0 +1,208 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "context" + "sync" + "time" + + "github.com/rancher/wrangler/v3/pkg/apply" + "github.com/rancher/wrangler/v3/pkg/condition" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/kv" + v1 "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// DaemonSetController interface for managing DaemonSet resources. +type DaemonSetController interface { + generic.ControllerInterface[*v1.DaemonSet, *v1.DaemonSetList] +} + +// DaemonSetClient interface for managing DaemonSet resources in Kubernetes. +type DaemonSetClient interface { + generic.ClientInterface[*v1.DaemonSet, *v1.DaemonSetList] +} + +// DaemonSetCache interface for retrieving DaemonSet resources in memory. +type DaemonSetCache interface { + generic.CacheInterface[*v1.DaemonSet] +} + +// DaemonSetStatusHandler is executed for every added or modified DaemonSet. Should return the new status to be updated +type DaemonSetStatusHandler func(obj *v1.DaemonSet, status v1.DaemonSetStatus) (v1.DaemonSetStatus, error) + +// DaemonSetGeneratingHandler is the top-level handler that is executed for every DaemonSet event. It extends DaemonSetStatusHandler by a returning a slice of child objects to be passed to apply.Apply +type DaemonSetGeneratingHandler func(obj *v1.DaemonSet, status v1.DaemonSetStatus) ([]runtime.Object, v1.DaemonSetStatus, error) + +// RegisterDaemonSetStatusHandler configures a DaemonSetController to execute a DaemonSetStatusHandler for every events observed. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterDaemonSetStatusHandler(ctx context.Context, controller DaemonSetController, condition condition.Cond, name string, handler DaemonSetStatusHandler) { + statusHandler := &daemonSetStatusHandler{ + client: controller, + condition: condition, + handler: handler, + } + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) +} + +// RegisterDaemonSetGeneratingHandler configures a DaemonSetController to execute a DaemonSetGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterDaemonSetGeneratingHandler(ctx context.Context, controller DaemonSetController, apply apply.Apply, + condition condition.Cond, name string, handler DaemonSetGeneratingHandler, opts *generic.GeneratingHandlerOptions) { + statusHandler := &daemonSetGeneratingHandler{ + DaemonSetGeneratingHandler: handler, + apply: apply, + name: name, + gvk: controller.GroupVersionKind(), + } + if opts != nil { + statusHandler.opts = *opts + } + controller.OnChange(ctx, name, statusHandler.Remove) + RegisterDaemonSetStatusHandler(ctx, controller, condition, name, statusHandler.Handle) +} + +type daemonSetStatusHandler struct { + client DaemonSetClient + condition condition.Cond + handler DaemonSetStatusHandler +} + +// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API +func (a *daemonSetStatusHandler) sync(key string, obj *v1.DaemonSet) (*v1.DaemonSet, error) { + if obj == nil { + return obj, nil + } + + origStatus := obj.Status.DeepCopy() + obj = obj.DeepCopy() + newStatus, err := a.handler(obj, obj.Status) + if err != nil { + // Revert to old status on error + newStatus = *origStatus.DeepCopy() + } + + if a.condition != "" { + if errors.IsConflict(err) { + a.condition.SetError(&newStatus, "", nil) + } else { + a.condition.SetError(&newStatus, "", err) + } + } + if !equality.Semantic.DeepEqual(origStatus, &newStatus) { + if a.condition != "" { + // Since status has changed, update the lastUpdatedTime + a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) + } + + var newErr error + obj.Status = newStatus + newObj, newErr := a.client.UpdateStatus(obj) + if err == nil { + err = newErr + } + if newErr == nil { + obj = newObj + } + } + return obj, err +} + +type daemonSetGeneratingHandler struct { + DaemonSetGeneratingHandler + apply apply.Apply + opts generic.GeneratingHandlerOptions + gvk schema.GroupVersionKind + name string + seen sync.Map +} + +// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied +func (a *daemonSetGeneratingHandler) Remove(key string, obj *v1.DaemonSet) (*v1.DaemonSet, error) { + if obj != nil { + return obj, nil + } + + obj = &v1.DaemonSet{} + obj.Namespace, obj.Name = kv.RSplit(key, "/") + obj.SetGroupVersionKind(a.gvk) + + if a.opts.UniqueApplyForResourceVersion { + a.seen.Delete(key) + } + + return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects() +} + +// Handle executes the configured DaemonSetGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource +func (a *daemonSetGeneratingHandler) Handle(obj *v1.DaemonSet, status v1.DaemonSetStatus) (v1.DaemonSetStatus, error) { + if !obj.DeletionTimestamp.IsZero() { + return status, nil + } + + objs, newStatus, err := a.DaemonSetGeneratingHandler(obj, status) + if err != nil { + return newStatus, err + } + if !a.isNewResourceVersion(obj) { + return newStatus, nil + } + + err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects(objs...) + if err != nil { + return newStatus, err + } + a.storeResourceVersion(obj) + return newStatus, nil +} + +// isNewResourceVersion detects if a specific resource version was already successfully processed. +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *daemonSetGeneratingHandler) isNewResourceVersion(obj *v1.DaemonSet) bool { + if !a.opts.UniqueApplyForResourceVersion { + return true + } + + // Apply once per resource version + key := obj.Namespace + "/" + obj.Name + previous, ok := a.seen.Load(key) + return !ok || previous != obj.ResourceVersion +} + +// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *daemonSetGeneratingHandler) storeResourceVersion(obj *v1.DaemonSet) { + if !a.opts.UniqueApplyForResourceVersion { + return + } + + key := obj.Namespace + "/" + obj.Name + a.seen.Store(key, obj.ResourceVersion) +} diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/deployment.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/deployment.go new file mode 100644 index 0000000000..fbac4c1555 --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/deployment.go @@ -0,0 +1,208 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "context" + "sync" + "time" + + "github.com/rancher/wrangler/v3/pkg/apply" + "github.com/rancher/wrangler/v3/pkg/condition" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/kv" + v1 "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// DeploymentController interface for managing Deployment resources. +type DeploymentController interface { + generic.ControllerInterface[*v1.Deployment, *v1.DeploymentList] +} + +// DeploymentClient interface for managing Deployment resources in Kubernetes. +type DeploymentClient interface { + generic.ClientInterface[*v1.Deployment, *v1.DeploymentList] +} + +// DeploymentCache interface for retrieving Deployment resources in memory. +type DeploymentCache interface { + generic.CacheInterface[*v1.Deployment] +} + +// DeploymentStatusHandler is executed for every added or modified Deployment. Should return the new status to be updated +type DeploymentStatusHandler func(obj *v1.Deployment, status v1.DeploymentStatus) (v1.DeploymentStatus, error) + +// DeploymentGeneratingHandler is the top-level handler that is executed for every Deployment event. It extends DeploymentStatusHandler by a returning a slice of child objects to be passed to apply.Apply +type DeploymentGeneratingHandler func(obj *v1.Deployment, status v1.DeploymentStatus) ([]runtime.Object, v1.DeploymentStatus, error) + +// RegisterDeploymentStatusHandler configures a DeploymentController to execute a DeploymentStatusHandler for every events observed. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterDeploymentStatusHandler(ctx context.Context, controller DeploymentController, condition condition.Cond, name string, handler DeploymentStatusHandler) { + statusHandler := &deploymentStatusHandler{ + client: controller, + condition: condition, + handler: handler, + } + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) +} + +// RegisterDeploymentGeneratingHandler configures a DeploymentController to execute a DeploymentGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterDeploymentGeneratingHandler(ctx context.Context, controller DeploymentController, apply apply.Apply, + condition condition.Cond, name string, handler DeploymentGeneratingHandler, opts *generic.GeneratingHandlerOptions) { + statusHandler := &deploymentGeneratingHandler{ + DeploymentGeneratingHandler: handler, + apply: apply, + name: name, + gvk: controller.GroupVersionKind(), + } + if opts != nil { + statusHandler.opts = *opts + } + controller.OnChange(ctx, name, statusHandler.Remove) + RegisterDeploymentStatusHandler(ctx, controller, condition, name, statusHandler.Handle) +} + +type deploymentStatusHandler struct { + client DeploymentClient + condition condition.Cond + handler DeploymentStatusHandler +} + +// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API +func (a *deploymentStatusHandler) sync(key string, obj *v1.Deployment) (*v1.Deployment, error) { + if obj == nil { + return obj, nil + } + + origStatus := obj.Status.DeepCopy() + obj = obj.DeepCopy() + newStatus, err := a.handler(obj, obj.Status) + if err != nil { + // Revert to old status on error + newStatus = *origStatus.DeepCopy() + } + + if a.condition != "" { + if errors.IsConflict(err) { + a.condition.SetError(&newStatus, "", nil) + } else { + a.condition.SetError(&newStatus, "", err) + } + } + if !equality.Semantic.DeepEqual(origStatus, &newStatus) { + if a.condition != "" { + // Since status has changed, update the lastUpdatedTime + a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) + } + + var newErr error + obj.Status = newStatus + newObj, newErr := a.client.UpdateStatus(obj) + if err == nil { + err = newErr + } + if newErr == nil { + obj = newObj + } + } + return obj, err +} + +type deploymentGeneratingHandler struct { + DeploymentGeneratingHandler + apply apply.Apply + opts generic.GeneratingHandlerOptions + gvk schema.GroupVersionKind + name string + seen sync.Map +} + +// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied +func (a *deploymentGeneratingHandler) Remove(key string, obj *v1.Deployment) (*v1.Deployment, error) { + if obj != nil { + return obj, nil + } + + obj = &v1.Deployment{} + obj.Namespace, obj.Name = kv.RSplit(key, "/") + obj.SetGroupVersionKind(a.gvk) + + if a.opts.UniqueApplyForResourceVersion { + a.seen.Delete(key) + } + + return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects() +} + +// Handle executes the configured DeploymentGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource +func (a *deploymentGeneratingHandler) Handle(obj *v1.Deployment, status v1.DeploymentStatus) (v1.DeploymentStatus, error) { + if !obj.DeletionTimestamp.IsZero() { + return status, nil + } + + objs, newStatus, err := a.DeploymentGeneratingHandler(obj, status) + if err != nil { + return newStatus, err + } + if !a.isNewResourceVersion(obj) { + return newStatus, nil + } + + err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects(objs...) + if err != nil { + return newStatus, err + } + a.storeResourceVersion(obj) + return newStatus, nil +} + +// isNewResourceVersion detects if a specific resource version was already successfully processed. +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *deploymentGeneratingHandler) isNewResourceVersion(obj *v1.Deployment) bool { + if !a.opts.UniqueApplyForResourceVersion { + return true + } + + // Apply once per resource version + key := obj.Namespace + "/" + obj.Name + previous, ok := a.seen.Load(key) + return !ok || previous != obj.ResourceVersion +} + +// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *deploymentGeneratingHandler) storeResourceVersion(obj *v1.Deployment) { + if !a.opts.UniqueApplyForResourceVersion { + return + } + + key := obj.Namespace + "/" + obj.Name + a.seen.Store(key, obj.ResourceVersion) +} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/interface.go similarity index 58% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/interface.go index c08a4c7efc..b2bdfe3df8 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/apps/v1/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/interface.go @@ -20,7 +20,8 @@ package v1 import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/schemes" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/schemes" v1 "k8s.io/api/apps/v1" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -45,12 +46,14 @@ type version struct { controllerFactory controller.SharedControllerFactory } -func (c *version) DaemonSet() DaemonSetController { - return NewDaemonSetController(schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"}, "daemonsets", true, c.controllerFactory) +func (v *version) DaemonSet() DaemonSetController { + return generic.NewController[*v1.DaemonSet, *v1.DaemonSetList](schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"}, "daemonsets", true, v.controllerFactory) } -func (c *version) Deployment() DeploymentController { - return NewDeploymentController(schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}, "deployments", true, c.controllerFactory) + +func (v *version) Deployment() DeploymentController { + return generic.NewController[*v1.Deployment, *v1.DeploymentList](schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}, "deployments", true, v.controllerFactory) } -func (c *version) StatefulSet() StatefulSetController { - return NewStatefulSetController(schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"}, "statefulsets", true, c.controllerFactory) + +func (v *version) StatefulSet() StatefulSetController { + return generic.NewController[*v1.StatefulSet, *v1.StatefulSetList](schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"}, "statefulsets", true, v.controllerFactory) } diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/statefulset.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/statefulset.go new file mode 100644 index 0000000000..fcb0a3cd29 --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1/statefulset.go @@ -0,0 +1,208 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "context" + "sync" + "time" + + "github.com/rancher/wrangler/v3/pkg/apply" + "github.com/rancher/wrangler/v3/pkg/condition" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/kv" + v1 "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// StatefulSetController interface for managing StatefulSet resources. +type StatefulSetController interface { + generic.ControllerInterface[*v1.StatefulSet, *v1.StatefulSetList] +} + +// StatefulSetClient interface for managing StatefulSet resources in Kubernetes. +type StatefulSetClient interface { + generic.ClientInterface[*v1.StatefulSet, *v1.StatefulSetList] +} + +// StatefulSetCache interface for retrieving StatefulSet resources in memory. +type StatefulSetCache interface { + generic.CacheInterface[*v1.StatefulSet] +} + +// StatefulSetStatusHandler is executed for every added or modified StatefulSet. Should return the new status to be updated +type StatefulSetStatusHandler func(obj *v1.StatefulSet, status v1.StatefulSetStatus) (v1.StatefulSetStatus, error) + +// StatefulSetGeneratingHandler is the top-level handler that is executed for every StatefulSet event. It extends StatefulSetStatusHandler by a returning a slice of child objects to be passed to apply.Apply +type StatefulSetGeneratingHandler func(obj *v1.StatefulSet, status v1.StatefulSetStatus) ([]runtime.Object, v1.StatefulSetStatus, error) + +// RegisterStatefulSetStatusHandler configures a StatefulSetController to execute a StatefulSetStatusHandler for every events observed. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterStatefulSetStatusHandler(ctx context.Context, controller StatefulSetController, condition condition.Cond, name string, handler StatefulSetStatusHandler) { + statusHandler := &statefulSetStatusHandler{ + client: controller, + condition: condition, + handler: handler, + } + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) +} + +// RegisterStatefulSetGeneratingHandler configures a StatefulSetController to execute a StatefulSetGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterStatefulSetGeneratingHandler(ctx context.Context, controller StatefulSetController, apply apply.Apply, + condition condition.Cond, name string, handler StatefulSetGeneratingHandler, opts *generic.GeneratingHandlerOptions) { + statusHandler := &statefulSetGeneratingHandler{ + StatefulSetGeneratingHandler: handler, + apply: apply, + name: name, + gvk: controller.GroupVersionKind(), + } + if opts != nil { + statusHandler.opts = *opts + } + controller.OnChange(ctx, name, statusHandler.Remove) + RegisterStatefulSetStatusHandler(ctx, controller, condition, name, statusHandler.Handle) +} + +type statefulSetStatusHandler struct { + client StatefulSetClient + condition condition.Cond + handler StatefulSetStatusHandler +} + +// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API +func (a *statefulSetStatusHandler) sync(key string, obj *v1.StatefulSet) (*v1.StatefulSet, error) { + if obj == nil { + return obj, nil + } + + origStatus := obj.Status.DeepCopy() + obj = obj.DeepCopy() + newStatus, err := a.handler(obj, obj.Status) + if err != nil { + // Revert to old status on error + newStatus = *origStatus.DeepCopy() + } + + if a.condition != "" { + if errors.IsConflict(err) { + a.condition.SetError(&newStatus, "", nil) + } else { + a.condition.SetError(&newStatus, "", err) + } + } + if !equality.Semantic.DeepEqual(origStatus, &newStatus) { + if a.condition != "" { + // Since status has changed, update the lastUpdatedTime + a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) + } + + var newErr error + obj.Status = newStatus + newObj, newErr := a.client.UpdateStatus(obj) + if err == nil { + err = newErr + } + if newErr == nil { + obj = newObj + } + } + return obj, err +} + +type statefulSetGeneratingHandler struct { + StatefulSetGeneratingHandler + apply apply.Apply + opts generic.GeneratingHandlerOptions + gvk schema.GroupVersionKind + name string + seen sync.Map +} + +// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied +func (a *statefulSetGeneratingHandler) Remove(key string, obj *v1.StatefulSet) (*v1.StatefulSet, error) { + if obj != nil { + return obj, nil + } + + obj = &v1.StatefulSet{} + obj.Namespace, obj.Name = kv.RSplit(key, "/") + obj.SetGroupVersionKind(a.gvk) + + if a.opts.UniqueApplyForResourceVersion { + a.seen.Delete(key) + } + + return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects() +} + +// Handle executes the configured StatefulSetGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource +func (a *statefulSetGeneratingHandler) Handle(obj *v1.StatefulSet, status v1.StatefulSetStatus) (v1.StatefulSetStatus, error) { + if !obj.DeletionTimestamp.IsZero() { + return status, nil + } + + objs, newStatus, err := a.StatefulSetGeneratingHandler(obj, status) + if err != nil { + return newStatus, err + } + if !a.isNewResourceVersion(obj) { + return newStatus, nil + } + + err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects(objs...) + if err != nil { + return newStatus, err + } + a.storeResourceVersion(obj) + return newStatus, nil +} + +// isNewResourceVersion detects if a specific resource version was already successfully processed. +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *statefulSetGeneratingHandler) isNewResourceVersion(obj *v1.StatefulSet) bool { + if !a.opts.UniqueApplyForResourceVersion { + return true + } + + // Apply once per resource version + key := obj.Namespace + "/" + obj.Name + previous, ok := a.seen.Load(key) + return !ok || previous != obj.ResourceVersion +} + +// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *statefulSetGeneratingHandler) storeResourceVersion(obj *v1.StatefulSet) { + if !a.opts.UniqueApplyForResourceVersion { + return + } + + key := obj.Namespace + "/" + obj.Name + a.seen.Store(key, obj.ResourceVersion) +} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/factory.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/factory.go similarity index 97% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/factory.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/factory.go index 0a282f1780..ee23a75ae6 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/factory.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/factory.go @@ -20,7 +20,7 @@ package batch import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/generic" "k8s.io/client-go/rest" ) diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/interface.go similarity index 93% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/interface.go index a078bf8e5e..be91154bb8 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/interface.go @@ -20,7 +20,7 @@ package batch import ( "github.com/rancher/lasso/pkg/controller" - v1 "github.com/rancher/wrangler/pkg/generated/controllers/batch/v1" + v1 "github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/v1" ) type Interface interface { diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/v1/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/v1/interface.go similarity index 78% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/v1/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/v1/interface.go index abaf5ad5c8..0965b0fca3 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/batch/v1/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/v1/interface.go @@ -20,7 +20,8 @@ package v1 import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/schemes" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/schemes" v1 "k8s.io/api/batch/v1" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -43,6 +44,6 @@ type version struct { controllerFactory controller.SharedControllerFactory } -func (c *version) Job() JobController { - return NewJobController(schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"}, "jobs", true, c.controllerFactory) +func (v *version) Job() JobController { + return generic.NewController[*v1.Job, *v1.JobList](schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"}, "jobs", true, v.controllerFactory) } diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/v1/job.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/v1/job.go new file mode 100644 index 0000000000..0f54d619e4 --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/v1/job.go @@ -0,0 +1,208 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "context" + "sync" + "time" + + "github.com/rancher/wrangler/v3/pkg/apply" + "github.com/rancher/wrangler/v3/pkg/condition" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/kv" + v1 "k8s.io/api/batch/v1" + "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// JobController interface for managing Job resources. +type JobController interface { + generic.ControllerInterface[*v1.Job, *v1.JobList] +} + +// JobClient interface for managing Job resources in Kubernetes. +type JobClient interface { + generic.ClientInterface[*v1.Job, *v1.JobList] +} + +// JobCache interface for retrieving Job resources in memory. +type JobCache interface { + generic.CacheInterface[*v1.Job] +} + +// JobStatusHandler is executed for every added or modified Job. Should return the new status to be updated +type JobStatusHandler func(obj *v1.Job, status v1.JobStatus) (v1.JobStatus, error) + +// JobGeneratingHandler is the top-level handler that is executed for every Job event. It extends JobStatusHandler by a returning a slice of child objects to be passed to apply.Apply +type JobGeneratingHandler func(obj *v1.Job, status v1.JobStatus) ([]runtime.Object, v1.JobStatus, error) + +// RegisterJobStatusHandler configures a JobController to execute a JobStatusHandler for every events observed. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterJobStatusHandler(ctx context.Context, controller JobController, condition condition.Cond, name string, handler JobStatusHandler) { + statusHandler := &jobStatusHandler{ + client: controller, + condition: condition, + handler: handler, + } + controller.AddGenericHandler(ctx, name, generic.FromObjectHandlerToHandler(statusHandler.sync)) +} + +// RegisterJobGeneratingHandler configures a JobController to execute a JobGeneratingHandler for every events observed, passing the returned objects to the provided apply.Apply. +// If a non-empty condition is provided, it will be updated in the status conditions for every handler execution +func RegisterJobGeneratingHandler(ctx context.Context, controller JobController, apply apply.Apply, + condition condition.Cond, name string, handler JobGeneratingHandler, opts *generic.GeneratingHandlerOptions) { + statusHandler := &jobGeneratingHandler{ + JobGeneratingHandler: handler, + apply: apply, + name: name, + gvk: controller.GroupVersionKind(), + } + if opts != nil { + statusHandler.opts = *opts + } + controller.OnChange(ctx, name, statusHandler.Remove) + RegisterJobStatusHandler(ctx, controller, condition, name, statusHandler.Handle) +} + +type jobStatusHandler struct { + client JobClient + condition condition.Cond + handler JobStatusHandler +} + +// sync is executed on every resource addition or modification. Executes the configured handlers and sends the updated status to the Kubernetes API +func (a *jobStatusHandler) sync(key string, obj *v1.Job) (*v1.Job, error) { + if obj == nil { + return obj, nil + } + + origStatus := obj.Status.DeepCopy() + obj = obj.DeepCopy() + newStatus, err := a.handler(obj, obj.Status) + if err != nil { + // Revert to old status on error + newStatus = *origStatus.DeepCopy() + } + + if a.condition != "" { + if errors.IsConflict(err) { + a.condition.SetError(&newStatus, "", nil) + } else { + a.condition.SetError(&newStatus, "", err) + } + } + if !equality.Semantic.DeepEqual(origStatus, &newStatus) { + if a.condition != "" { + // Since status has changed, update the lastUpdatedTime + a.condition.LastUpdated(&newStatus, time.Now().UTC().Format(time.RFC3339)) + } + + var newErr error + obj.Status = newStatus + newObj, newErr := a.client.UpdateStatus(obj) + if err == nil { + err = newErr + } + if newErr == nil { + obj = newObj + } + } + return obj, err +} + +type jobGeneratingHandler struct { + JobGeneratingHandler + apply apply.Apply + opts generic.GeneratingHandlerOptions + gvk schema.GroupVersionKind + name string + seen sync.Map +} + +// Remove handles the observed deletion of a resource, cascade deleting every associated resource previously applied +func (a *jobGeneratingHandler) Remove(key string, obj *v1.Job) (*v1.Job, error) { + if obj != nil { + return obj, nil + } + + obj = &v1.Job{} + obj.Namespace, obj.Name = kv.RSplit(key, "/") + obj.SetGroupVersionKind(a.gvk) + + if a.opts.UniqueApplyForResourceVersion { + a.seen.Delete(key) + } + + return nil, generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects() +} + +// Handle executes the configured JobGeneratingHandler and pass the resulting objects to apply.Apply, finally returning the new status of the resource +func (a *jobGeneratingHandler) Handle(obj *v1.Job, status v1.JobStatus) (v1.JobStatus, error) { + if !obj.DeletionTimestamp.IsZero() { + return status, nil + } + + objs, newStatus, err := a.JobGeneratingHandler(obj, status) + if err != nil { + return newStatus, err + } + if !a.isNewResourceVersion(obj) { + return newStatus, nil + } + + err = generic.ConfigureApplyForObject(a.apply, obj, &a.opts). + WithOwner(obj). + WithSetID(a.name). + ApplyObjects(objs...) + if err != nil { + return newStatus, err + } + a.storeResourceVersion(obj) + return newStatus, nil +} + +// isNewResourceVersion detects if a specific resource version was already successfully processed. +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *jobGeneratingHandler) isNewResourceVersion(obj *v1.Job) bool { + if !a.opts.UniqueApplyForResourceVersion { + return true + } + + // Apply once per resource version + key := obj.Namespace + "/" + obj.Name + previous, ok := a.seen.Load(key) + return !ok || previous != obj.ResourceVersion +} + +// storeResourceVersion keeps track of the latest resource version of an object for which Apply was executed +// Only used if UniqueApplyForResourceVersion is set in generic.GeneratingHandlerOptions +func (a *jobGeneratingHandler) storeResourceVersion(obj *v1.Job) { + if !a.opts.UniqueApplyForResourceVersion { + return + } + + key := obj.Namespace + "/" + obj.Name + a.seen.Store(key, obj.ResourceVersion) +} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/factory.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/factory.go similarity index 97% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/factory.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/factory.go index 266d290820..1215a28d64 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/factory.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/factory.go @@ -20,7 +20,7 @@ package rbac import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/generic" "k8s.io/client-go/rest" ) diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/interface.go similarity index 93% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/interface.go index f4bb1f982f..35cd1d95f7 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/interface.go @@ -20,7 +20,7 @@ package rbac import ( "github.com/rancher/lasso/pkg/controller" - v1 "github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1" + v1 "github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1" ) type Interface interface { diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/clusterrole.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/clusterrole.go new file mode 100644 index 0000000000..d8940df173 --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/clusterrole.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "github.com/rancher/wrangler/v3/pkg/generic" + v1 "k8s.io/api/rbac/v1" +) + +// ClusterRoleController interface for managing ClusterRole resources. +type ClusterRoleController interface { + generic.NonNamespacedControllerInterface[*v1.ClusterRole, *v1.ClusterRoleList] +} + +// ClusterRoleClient interface for managing ClusterRole resources in Kubernetes. +type ClusterRoleClient interface { + generic.NonNamespacedClientInterface[*v1.ClusterRole, *v1.ClusterRoleList] +} + +// ClusterRoleCache interface for retrieving ClusterRole resources in memory. +type ClusterRoleCache interface { + generic.NonNamespacedCacheInterface[*v1.ClusterRole] +} diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/clusterrolebinding.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/clusterrolebinding.go new file mode 100644 index 0000000000..957d63a086 --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/clusterrolebinding.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "github.com/rancher/wrangler/v3/pkg/generic" + v1 "k8s.io/api/rbac/v1" +) + +// ClusterRoleBindingController interface for managing ClusterRoleBinding resources. +type ClusterRoleBindingController interface { + generic.NonNamespacedControllerInterface[*v1.ClusterRoleBinding, *v1.ClusterRoleBindingList] +} + +// ClusterRoleBindingClient interface for managing ClusterRoleBinding resources in Kubernetes. +type ClusterRoleBindingClient interface { + generic.NonNamespacedClientInterface[*v1.ClusterRoleBinding, *v1.ClusterRoleBindingList] +} + +// ClusterRoleBindingCache interface for retrieving ClusterRoleBinding resources in memory. +type ClusterRoleBindingCache interface { + generic.NonNamespacedCacheInterface[*v1.ClusterRoleBinding] +} diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/interface.go similarity index 50% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/interface.go index 1dbb1045a0..dd12d2f70a 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/interface.go @@ -20,7 +20,8 @@ package v1 import ( "github.com/rancher/lasso/pkg/controller" - "github.com/rancher/wrangler/pkg/schemes" + "github.com/rancher/wrangler/v3/pkg/generic" + "github.com/rancher/wrangler/v3/pkg/schemes" v1 "k8s.io/api/rbac/v1" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -46,15 +47,18 @@ type version struct { controllerFactory controller.SharedControllerFactory } -func (c *version) ClusterRole() ClusterRoleController { - return NewClusterRoleController(schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, "clusterroles", false, c.controllerFactory) +func (v *version) ClusterRole() ClusterRoleController { + return generic.NewNonNamespacedController[*v1.ClusterRole, *v1.ClusterRoleList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, "clusterroles", v.controllerFactory) } -func (c *version) ClusterRoleBinding() ClusterRoleBindingController { - return NewClusterRoleBindingController(schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, "clusterrolebindings", false, c.controllerFactory) + +func (v *version) ClusterRoleBinding() ClusterRoleBindingController { + return generic.NewNonNamespacedController[*v1.ClusterRoleBinding, *v1.ClusterRoleBindingList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, "clusterrolebindings", v.controllerFactory) } -func (c *version) Role() RoleController { - return NewRoleController(schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Role"}, "roles", true, c.controllerFactory) + +func (v *version) Role() RoleController { + return generic.NewController[*v1.Role, *v1.RoleList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "Role"}, "roles", true, v.controllerFactory) } -func (c *version) RoleBinding() RoleBindingController { - return NewRoleBindingController(schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding"}, "rolebindings", true, c.controllerFactory) + +func (v *version) RoleBinding() RoleBindingController { + return generic.NewController[*v1.RoleBinding, *v1.RoleBindingList](schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "RoleBinding"}, "rolebindings", true, v.controllerFactory) } diff --git a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/interface.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/role.go similarity index 56% rename from vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/interface.go rename to vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/role.go index 689915f184..646647c0fa 100644 --- a/vendor/github.com/rancher/wrangler/pkg/generated/controllers/core/interface.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/role.go @@ -16,28 +16,24 @@ limitations under the License. // Code generated by main. DO NOT EDIT. -package core +package v1 import ( - "github.com/rancher/lasso/pkg/controller" - v1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1" + "github.com/rancher/wrangler/v3/pkg/generic" + v1 "k8s.io/api/rbac/v1" ) -type Interface interface { - V1() v1.Interface +// RoleController interface for managing Role resources. +type RoleController interface { + generic.ControllerInterface[*v1.Role, *v1.RoleList] } -type group struct { - controllerFactory controller.SharedControllerFactory +// RoleClient interface for managing Role resources in Kubernetes. +type RoleClient interface { + generic.ClientInterface[*v1.Role, *v1.RoleList] } -// New returns a new Interface. -func New(controllerFactory controller.SharedControllerFactory) Interface { - return &group{ - controllerFactory: controllerFactory, - } -} - -func (g *group) V1() v1.Interface { - return v1.New(g.controllerFactory) +// RoleCache interface for retrieving Role resources in memory. +type RoleCache interface { + generic.CacheInterface[*v1.Role] } diff --git a/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/rolebinding.go b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/rolebinding.go new file mode 100644 index 0000000000..80e2d5325f --- /dev/null +++ b/vendor/github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1/rolebinding.go @@ -0,0 +1,39 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by main. DO NOT EDIT. + +package v1 + +import ( + "github.com/rancher/wrangler/v3/pkg/generic" + v1 "k8s.io/api/rbac/v1" +) + +// RoleBindingController interface for managing RoleBinding resources. +type RoleBindingController interface { + generic.ControllerInterface[*v1.RoleBinding, *v1.RoleBindingList] +} + +// RoleBindingClient interface for managing RoleBinding resources in Kubernetes. +type RoleBindingClient interface { + generic.ClientInterface[*v1.RoleBinding, *v1.RoleBindingList] +} + +// RoleBindingCache interface for retrieving RoleBinding resources in memory. +type RoleBindingCache interface { + generic.CacheInterface[*v1.RoleBinding] +} diff --git a/vendor/github.com/rancher/wrangler/pkg/ratelimit/none.go b/vendor/github.com/rancher/wrangler/v3/pkg/ratelimit/none.go similarity index 100% rename from vendor/github.com/rancher/wrangler/pkg/ratelimit/none.go rename to vendor/github.com/rancher/wrangler/v3/pkg/ratelimit/none.go diff --git a/vendor/github.com/rancher/wrangler/pkg/signals/signal.go b/vendor/github.com/rancher/wrangler/v3/pkg/signals/signal.go similarity index 90% rename from vendor/github.com/rancher/wrangler/pkg/signals/signal.go rename to vendor/github.com/rancher/wrangler/v3/pkg/signals/signal.go index 724b9e1981..24703f7446 100644 --- a/vendor/github.com/rancher/wrangler/pkg/signals/signal.go +++ b/vendor/github.com/rancher/wrangler/v3/pkg/signals/signal.go @@ -17,6 +17,8 @@ import ( "context" "os" "os/signal" + + "github.com/sirupsen/logrus" ) var onlyOneSignalHandler = make(chan struct{}) @@ -42,9 +44,11 @@ func SetupSignalContext() context.Context { ctx, cancel := context.WithCancel(context.Background()) signal.Notify(shutdownHandler, shutdownSignals...) go func() { - <-shutdownHandler + s := <-shutdownHandler + logrus.Warnf("signal received: %q, canceling context...", s) cancel() - <-shutdownHandler + s = <-shutdownHandler + logrus.Warnf("second signal received: %q, exiting...", s) os.Exit(1) // second signal. Exit directly. }() diff --git a/vendor/github.com/rancher/wrangler/pkg/signals/signal_posix.go b/vendor/github.com/rancher/wrangler/v3/pkg/signals/signal_posix.go similarity index 100% rename from vendor/github.com/rancher/wrangler/pkg/signals/signal_posix.go rename to vendor/github.com/rancher/wrangler/v3/pkg/signals/signal_posix.go diff --git a/vendor/github.com/rancher/wrangler/pkg/signals/signal_windows.go b/vendor/github.com/rancher/wrangler/v3/pkg/signals/signal_windows.go similarity index 100% rename from vendor/github.com/rancher/wrangler/pkg/signals/signal_windows.go rename to vendor/github.com/rancher/wrangler/v3/pkg/signals/signal_windows.go diff --git a/vendor/github.com/rancher/wrangler/pkg/webhook/match.go b/vendor/github.com/rancher/wrangler/v3/pkg/webhook/match.go similarity index 100% rename from vendor/github.com/rancher/wrangler/pkg/webhook/match.go rename to vendor/github.com/rancher/wrangler/v3/pkg/webhook/match.go diff --git a/vendor/github.com/rancher/wrangler/pkg/webhook/router.go b/vendor/github.com/rancher/wrangler/v3/pkg/webhook/router.go similarity index 100% rename from vendor/github.com/rancher/wrangler/pkg/webhook/router.go rename to vendor/github.com/rancher/wrangler/v3/pkg/webhook/router.go diff --git a/vendor/modules.txt b/vendor/modules.txt index b7f10ae3c1..bf5cb0e3a0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -400,49 +400,28 @@ github.com/rancher/lasso/pkg/log github.com/rancher/lasso/pkg/mapper github.com/rancher/lasso/pkg/metrics github.com/rancher/lasso/pkg/scheme -# github.com/rancher/wrangler v1.1.2 -## explicit; go 1.19 -github.com/rancher/wrangler/pkg/apply -github.com/rancher/wrangler/pkg/apply/injectors -github.com/rancher/wrangler/pkg/clients -github.com/rancher/wrangler/pkg/condition -github.com/rancher/wrangler/pkg/data -github.com/rancher/wrangler/pkg/data/convert -github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io -github.com/rancher/wrangler/pkg/generated/controllers/admissionregistration.k8s.io/v1 -github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io -github.com/rancher/wrangler/pkg/generated/controllers/apiextensions.k8s.io/v1 -github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io -github.com/rancher/wrangler/pkg/generated/controllers/apiregistration.k8s.io/v1 -github.com/rancher/wrangler/pkg/generated/controllers/apps -github.com/rancher/wrangler/pkg/generated/controllers/apps/v1 -github.com/rancher/wrangler/pkg/generated/controllers/batch -github.com/rancher/wrangler/pkg/generated/controllers/batch/v1 -github.com/rancher/wrangler/pkg/generated/controllers/core -github.com/rancher/wrangler/pkg/generated/controllers/core/v1 -github.com/rancher/wrangler/pkg/generated/controllers/rbac -github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1 -github.com/rancher/wrangler/pkg/generic -github.com/rancher/wrangler/pkg/gvk -github.com/rancher/wrangler/pkg/kv -github.com/rancher/wrangler/pkg/merr -github.com/rancher/wrangler/pkg/name -github.com/rancher/wrangler/pkg/objectset -github.com/rancher/wrangler/pkg/patch -github.com/rancher/wrangler/pkg/ratelimit -github.com/rancher/wrangler/pkg/schemes -github.com/rancher/wrangler/pkg/signals -github.com/rancher/wrangler/pkg/stringset -github.com/rancher/wrangler/pkg/webhook # github.com/rancher/wrangler/v3 v3.0.0 ## explicit; go 1.22.0 github.com/rancher/wrangler/v3/pkg/apply github.com/rancher/wrangler/v3/pkg/apply/injectors +github.com/rancher/wrangler/v3/pkg/clients github.com/rancher/wrangler/v3/pkg/condition github.com/rancher/wrangler/v3/pkg/data github.com/rancher/wrangler/v3/pkg/data/convert +github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io +github.com/rancher/wrangler/v3/pkg/generated/controllers/admissionregistration.k8s.io/v1 +github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io +github.com/rancher/wrangler/v3/pkg/generated/controllers/apiextensions.k8s.io/v1 +github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io +github.com/rancher/wrangler/v3/pkg/generated/controllers/apiregistration.k8s.io/v1 +github.com/rancher/wrangler/v3/pkg/generated/controllers/apps +github.com/rancher/wrangler/v3/pkg/generated/controllers/apps/v1 +github.com/rancher/wrangler/v3/pkg/generated/controllers/batch +github.com/rancher/wrangler/v3/pkg/generated/controllers/batch/v1 github.com/rancher/wrangler/v3/pkg/generated/controllers/core github.com/rancher/wrangler/v3/pkg/generated/controllers/core/v1 +github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac +github.com/rancher/wrangler/v3/pkg/generated/controllers/rbac/v1 github.com/rancher/wrangler/v3/pkg/generic github.com/rancher/wrangler/v3/pkg/gvk github.com/rancher/wrangler/v3/pkg/kv @@ -450,9 +429,12 @@ github.com/rancher/wrangler/v3/pkg/merr github.com/rancher/wrangler/v3/pkg/name github.com/rancher/wrangler/v3/pkg/objectset github.com/rancher/wrangler/v3/pkg/patch +github.com/rancher/wrangler/v3/pkg/ratelimit github.com/rancher/wrangler/v3/pkg/schemes +github.com/rancher/wrangler/v3/pkg/signals github.com/rancher/wrangler/v3/pkg/start github.com/rancher/wrangler/v3/pkg/stringset +github.com/rancher/wrangler/v3/pkg/webhook # github.com/robfig/cron v1.2.0 ## explicit github.com/robfig/cron diff --git a/webhook/admission/admission.go b/webhook/admission/admission.go index 963851fed4..3acd66d12d 100644 --- a/webhook/admission/admission.go +++ b/webhook/admission/admission.go @@ -4,7 +4,7 @@ import ( "fmt" "strings" - "github.com/rancher/wrangler/pkg/webhook" + "github.com/rancher/wrangler/v3/pkg/webhook" "github.com/sirupsen/logrus" "k8s.io/apimachinery/pkg/runtime" diff --git a/webhook/admission/request.go b/webhook/admission/request.go index f2457ea73e..cb91a9c7b1 100644 --- a/webhook/admission/request.go +++ b/webhook/admission/request.go @@ -3,7 +3,7 @@ package admission import ( "fmt" - "github.com/rancher/wrangler/pkg/webhook" + "github.com/rancher/wrangler/v3/pkg/webhook" "k8s.io/apimachinery/pkg/runtime" diff --git a/webhook/server/handler.go b/webhook/server/handler.go index 2dfc1ae1fb..912b626a5c 100644 --- a/webhook/server/handler.go +++ b/webhook/server/handler.go @@ -4,7 +4,7 @@ import ( "net/http" "reflect" - "github.com/rancher/wrangler/pkg/webhook" + "github.com/rancher/wrangler/v3/pkg/webhook" "github.com/sirupsen/logrus" "github.com/longhorn/longhorn-manager/webhook/admission" diff --git a/webhook/server/mutation.go b/webhook/server/mutation.go index fc61db56f3..d242ffdea2 100644 --- a/webhook/server/mutation.go +++ b/webhook/server/mutation.go @@ -3,7 +3,7 @@ package server import ( "net/http" - "github.com/rancher/wrangler/pkg/webhook" + "github.com/rancher/wrangler/v3/pkg/webhook" "github.com/longhorn/longhorn-manager/datastore" "github.com/longhorn/longhorn-manager/webhook/admission" diff --git a/webhook/server/validation.go b/webhook/server/validation.go index 3a4af605c5..a664004eaf 100644 --- a/webhook/server/validation.go +++ b/webhook/server/validation.go @@ -3,7 +3,7 @@ package server import ( "net/http" - "github.com/rancher/wrangler/pkg/webhook" + "github.com/rancher/wrangler/v3/pkg/webhook" "github.com/longhorn/longhorn-manager/datastore" "github.com/longhorn/longhorn-manager/types"