diff --git a/Gopkg.lock b/Gopkg.lock index 290a807e27..7884d5ab40 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -664,7 +664,10 @@ "pkg/apis/clusterregistry/v1alpha1", "pkg/client/clientset_generated/clientset", "pkg/client/clientset_generated/clientset/scheme", - "pkg/client/clientset_generated/clientset/typed/clusterregistry/v1alpha1" + "pkg/client/clientset_generated/clientset/typed/clusterregistry/v1alpha1", + "pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1", + "pkg/client/informers_generated/externalversions/internalinterfaces", + "pkg/client/listers_generated/clusterregistry/v1alpha1" ] revision = "0309542bf91ca34c577e19769418561f65af5226" @@ -737,6 +740,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "a03a01de13ead5f4d83b0cf943b4592d693a44eae04cad16c729c8e3a1f35243" + inputs-digest = "faef4f2be2707f32d65e2d0da20ad06c910e6402fddd4eee29857e2e970b8e55" solver-name = "gps-cdcl" solver-version = 1 diff --git a/cmd/glbc/main.go b/cmd/glbc/main.go index 46022bf868..ac2d703553 100644 --- a/cmd/glbc/main.go +++ b/cmd/glbc/main.go @@ -26,10 +26,12 @@ import ( crdclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" "k8s.io/client-go/kubernetes" + crclient "k8s.io/cluster-registry/pkg/client/clientset_generated/clientset" "k8s.io/kubernetes/pkg/cloudprovider/providers/gce" "k8s.io/ingress-gce/pkg/context" "k8s.io/ingress-gce/pkg/controller" + "k8s.io/ingress-gce/pkg/mci" neg "k8s.io/ingress-gce/pkg/neg" "k8s.io/ingress-gce/cmd/glbc/app" @@ -82,6 +84,14 @@ func main() { } } + var registryClient crclient.Interface + if flags.F.MultiCluster { + registryClient, err = crclient.NewForConfig(kubeConfig) + if err != nil { + glog.Fatalf("Failed to create Cluster Registry client: %v", err) + } + } + namer, err := app.NewNamer(kubeClient, flags.F.ClusterName, controller.DefaultFirewallName) if err != nil { glog.Fatalf("%v", err) @@ -96,8 +106,8 @@ func main() { enableNEG := cloud.AlphaFeatureGate.Enabled(gce.AlphaFeatureNetworkEndpointGroup) stopCh := make(chan struct{}) - ctx := context.NewControllerContext(kubeClient, flags.F.WatchNamespace, flags.F.ResyncPeriod, enableNEG) - lbc, err := controller.NewLoadBalancerController(kubeClient, stopCh, ctx, clusterManager, enableNEG) + ctx := context.NewControllerContext(kubeClient, registryClient, flags.F.WatchNamespace, flags.F.ResyncPeriod, enableNEG) + lbc, err := controller.NewLoadBalancerController(ctx, clusterManager, enableNEG, stopCh) if err != nil { glog.Fatalf("Error creating load balancer controller: %v", err) } @@ -109,11 +119,17 @@ func main() { glog.V(0).Infof("clusterManager initialized") if enableNEG { - negController, _ := neg.NewController(kubeClient, cloud, ctx, lbc.Translator, namer, flags.F.ResyncPeriod) + negController, _ := neg.NewController(cloud, ctx, lbc.Translator, namer, flags.F.ResyncPeriod) go negController.Run(stopCh) glog.V(0).Infof("negController started") } + if flags.F.MultiCluster { + mciController, _ := mci.NewController(ctx, flags.F.ResyncPeriod) + go mciController.Run(stopCh) + glog.V(0).Infof("Multi-Cluster Ingress Controller started") + } + go app.RunHTTPServer(lbc) go app.RunSIGTERMHandler(lbc, flags.F.DeleteAllOnQuit) diff --git a/pkg/context/context.go b/pkg/context/context.go index 4ed73d4ac7..bbe97fa873 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -30,12 +30,13 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" crclient "k8s.io/cluster-registry/pkg/client/clientset_generated/clientset" + crinformerv1alpha1 "k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1" ) // ControllerContext holds resources necessary for the general // workflow of the controller. type ControllerContext struct { - kubeClient kubernetes.Interface + KubeClient kubernetes.Interface IngressInformer cache.SharedIndexInformer ServiceInformer cache.SharedIndexInformer @@ -46,31 +47,36 @@ type ControllerContext struct { // Map of namespace => record.EventRecorder. recorders map[string]record.EventRecorder - MCContext MultiClusterContext + MC MultiClusterContext } // MultiClusterContext holds resource necessary for MCI mode. type MultiClusterContext struct { - crClient crclient.Interface + RegistryClient crclient.Interface ClusterInformer cache.SharedIndexInformer } // NewControllerContext returns a new shared set of informers. -func NewControllerContext(kubeClient kubernetes.Interface, namespace string, resyncPeriod time.Duration, enableEndpointsInformer bool) *ControllerContext { +func NewControllerContext(kubeClient kubernetes.Interface, registryClient crclient.Interface, namespace string, resyncPeriod time.Duration, enableEndpointsInformer bool) *ControllerContext { newIndexer := func() cache.Indexers { return cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc} } + context := &ControllerContext{ - kubeClient: kubeClient, + KubeClient: kubeClient, IngressInformer: informerv1beta1.NewIngressInformer(kubeClient, namespace, resyncPeriod, newIndexer()), ServiceInformer: informerv1.NewServiceInformer(kubeClient, namespace, resyncPeriod, newIndexer()), PodInformer: informerv1.NewPodInformer(kubeClient, namespace, resyncPeriod, newIndexer()), NodeInformer: informerv1.NewNodeInformer(kubeClient, resyncPeriod, newIndexer()), + MC: MultiClusterContext{RegistryClient: registryClient}, recorders: map[string]record.EventRecorder{}, } if enableEndpointsInformer { context.EndpointInformer = informerv1.NewEndpointsInformer(kubeClient, namespace, resyncPeriod, newIndexer()) } + if context.MC.RegistryClient != nil { + context.MC.ClusterInformer = crinformerv1alpha1.NewClusterInformer(registryClient, resyncPeriod, newIndexer()) + } return context } @@ -86,6 +92,9 @@ func (ctx *ControllerContext) HasSynced() bool { if ctx.EndpointInformer != nil { funcs = append(funcs, ctx.EndpointInformer.HasSynced) } + if ctx.MC.ClusterInformer != nil { + funcs = append(funcs, ctx.MC.ClusterInformer.HasSynced) + } for _, f := range funcs { if !f() { return false @@ -94,6 +103,7 @@ func (ctx *ControllerContext) HasSynced() bool { return true } +// Recorder creates an event recorder for the specified namespace. func (ctx *ControllerContext) Recorder(ns string) record.EventRecorder { if rec, ok := ctx.recorders[ns]; ok { return rec @@ -102,7 +112,7 @@ func (ctx *ControllerContext) Recorder(ns string) record.EventRecorder { broadcaster := record.NewBroadcaster() broadcaster.StartLogging(glog.Infof) broadcaster.StartRecordingToSink(&corev1.EventSinkImpl{ - Interface: ctx.kubeClient.Core().Events(ns), + Interface: ctx.KubeClient.Core().Events(ns), }) rec := broadcaster.NewRecorder(scheme.Scheme, apiv1.EventSource{Component: "loadbalancer-controller"}) ctx.recorders[ns] = rec @@ -119,4 +129,8 @@ func (ctx *ControllerContext) Start(stopCh chan struct{}) { if ctx.EndpointInformer != nil { go ctx.EndpointInformer.Run(stopCh) } + + if ctx.MC.ClusterInformer != nil { + go ctx.MC.ClusterInformer.Run(stopCh) + } } diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index cfe8be3970..a0ecb247e9 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -59,8 +59,7 @@ var ( // LoadBalancerController watches the kubernetes api and adds/removes services // from the loadbalancer, via loadBalancerConfig. type LoadBalancerController struct { - client kubernetes.Interface - ctx *context.ControllerContext + ctx *context.ControllerContext ingLister StoreToIngressLister nodeLister cache.Indexer @@ -88,18 +87,16 @@ type LoadBalancerController struct { } // NewLoadBalancerController creates a controller for gce loadbalancers. -// - kubeClient: A kubernetes REST client. // - clusterManager: A ClusterManager capable of creating all cloud resources // required for L7 loadbalancing. // - resyncPeriod: Watchers relist from the Kubernetes API server this often. -func NewLoadBalancerController(kubeClient kubernetes.Interface, stopCh chan struct{}, ctx *context.ControllerContext, clusterManager *ClusterManager, negEnabled bool) (*LoadBalancerController, error) { +func NewLoadBalancerController(ctx *context.ControllerContext, clusterManager *ClusterManager, negEnabled bool, stopCh chan struct{}) (*LoadBalancerController, error) { broadcaster := record.NewBroadcaster() broadcaster.StartLogging(glog.Infof) broadcaster.StartRecordingToSink(&unversionedcore.EventSinkImpl{ - Interface: kubeClient.Core().Events(""), + Interface: ctx.KubeClient.Core().Events(""), }) lbc := LoadBalancerController{ - client: kubeClient, ctx: ctx, ingLister: StoreToIngressLister{Store: ctx.IngressInformer.GetStore()}, nodeLister: ctx.NodeInformer.GetIndexer(), @@ -174,7 +171,7 @@ func NewLoadBalancerController(kubeClient kubernetes.Interface, stopCh chan stru ctx.PodInformer.GetIndexer(), endpointIndexer, negEnabled) - lbc.tlsLoader = &tls.TLSCertsFromSecretsLoader{Client: lbc.client} + lbc.tlsLoader = &tls.TLSCertsFromSecretsLoader{Client: lbc.ctx.KubeClient} glog.V(3).Infof("Created new loadbalancer controller") @@ -299,7 +296,7 @@ func (lbc *LoadBalancerController) ensureIngress(key string, ing *extensions.Ing if err = setInstanceGroupsAnnotation(ing.Annotations, igs); err != nil { return err } - if err = updateAnnotations(lbc.client, ing.Name, ing.Namespace, ing.Annotations); err != nil { + if err = updateAnnotations(lbc.ctx.KubeClient, ing.Name, ing.Namespace, ing.Annotations); err != nil { return err } return nil @@ -367,7 +364,7 @@ func (lbc *LoadBalancerController) ensureIngress(key string, ing *extensions.Ing // updateIngressStatus updates the IP and annotations of a loadbalancer. // The annotations are parsed by kubectl describe. func (lbc *LoadBalancerController) updateIngressStatus(l7 *loadbalancers.L7, ing *extensions.Ingress) error { - ingClient := lbc.client.Extensions().Ingresses(ing.Namespace) + ingClient := lbc.ctx.KubeClient.Extensions().Ingresses(ing.Namespace) // Update IP through update/status endpoint ip := l7.GetIP() @@ -395,7 +392,7 @@ func (lbc *LoadBalancerController) updateIngressStatus(l7 *loadbalancers.L7, ing } } annotations := loadbalancers.GetLBAnnotations(l7, currIng.Annotations, lbc.CloudClusterManager.backendPool) - if err := updateAnnotations(lbc.client, ing.Name, ing.Namespace, annotations); err != nil { + if err := updateAnnotations(lbc.ctx.KubeClient, ing.Name, ing.Namespace, annotations); err != nil { return err } return nil diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index 1c0adcdd00..373192cce6 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -55,8 +55,8 @@ func defaultBackendName(clusterName string) string { func newLoadBalancerController(t *testing.T, cm *fakeClusterManager) *LoadBalancerController { kubeClient := fake.NewSimpleClientset() stopCh := make(chan struct{}) - ctx := context.NewControllerContext(kubeClient, api_v1.NamespaceAll, 1*time.Second, true) - lb, err := NewLoadBalancerController(kubeClient, stopCh, ctx, cm.ClusterManager, true) + ctx := context.NewControllerContext(kubeClient, nil, api_v1.NamespaceAll, 1*time.Second, true) + lb, err := NewLoadBalancerController(ctx, cm.ClusterManager, true, stopCh) if err != nil { t.Fatalf("%v", err) } @@ -202,7 +202,7 @@ func addIngress(lbc *LoadBalancerController, ing *extensions.Ingress, pm *nodePo lbc.ctx.ServiceInformer.GetIndexer().Add(svc) } } - lbc.client.Extensions().Ingresses(ing.Namespace).Create(ing) + lbc.ctx.KubeClient.Extensions().Ingresses(ing.Namespace).Create(ing) lbc.ctx.IngressInformer.GetIndexer().Add(ing) } diff --git a/pkg/controller/translator/translator_test.go b/pkg/controller/translator/translator_test.go index 73764b6307..8d378c14d7 100644 --- a/pkg/controller/translator/translator_test.go +++ b/pkg/controller/translator/translator_test.go @@ -52,7 +52,7 @@ func gceForTest(negEnabled bool) *GCE { namer := utils.NewNamer("uid1", "fw1") - ctx := context.NewControllerContext(client, apiv1.NamespaceAll, 1*time.Second, negEnabled) + ctx := context.NewControllerContext(client, nil, apiv1.NamespaceAll, 1*time.Second, negEnabled) gce := &GCE{ recorders: ctx, namer: namer, diff --git a/pkg/mci/controller.go b/pkg/mci/controller.go new file mode 100644 index 0000000000..17a47acdb0 --- /dev/null +++ b/pkg/mci/controller.go @@ -0,0 +1,76 @@ +/* +Copyright 2018 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. +*/ + +package mci + +import ( + "time" + + "github.com/golang/glog" + "k8s.io/apimachinery/pkg/util/wait" + "k8s.io/client-go/tools/cache" + crv1alpha1 "k8s.io/cluster-registry/pkg/apis/clusterregistry/v1alpha1" + "k8s.io/ingress-gce/pkg/context" +) + +// Controller is a barebones multi-cluster ingress controller. +// For now, this controller only logs messages when CRUD operations are +// made on a crv1alpha1.Cluster. +type Controller struct { + resyncPeriod time.Duration + + clusterSynced cache.InformerSynced + clusterLister cache.Indexer + + // TODO(rramkumar): Add lister for service extension CRD. +} + +func NewController(ctx *context.ControllerContext, resyncPeriod time.Duration) (*Controller, error) { + mciController := &Controller{ + resyncPeriod: resyncPeriod, + clusterSynced: ctx.MC.ClusterInformer.HasSynced, + clusterLister: ctx.MC.ClusterInformer.GetIndexer(), + } + + ctx.MC.ClusterInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ + AddFunc: func(obj interface{}) { + c := obj.(*crv1alpha1.Cluster) + glog.V(3).Infof("Cluster %v added", c.Name) + }, + DeleteFunc: func(obj interface{}) { + c := obj.(*crv1alpha1.Cluster) + glog.V(3).Infof("Cluster %v deleted", c.Name) + }, + UpdateFunc: func(obj, cur interface{}) { + c := obj.(*crv1alpha1.Cluster) + glog.V(3).Infof("Cluster %v updated", c.Name) + }, + }) + return mciController, nil +} + +func (c *Controller) Run(stopCh <-chan struct{}) { + wait.PollUntil(5*time.Second, func() (bool, error) { + glog.V(2).Infof("Waiting for initial sync") + return c.synced(), nil + }, stopCh) + + glog.V(2).Infof("Starting Multi-Cluster Ingress controller") +} + +func (c *Controller) synced() bool { + return c.clusterSynced() +} diff --git a/pkg/neg/controller.go b/pkg/neg/controller.go index cd23e127d9..47bfad3b7f 100644 --- a/pkg/neg/controller.go +++ b/pkg/neg/controller.go @@ -27,7 +27,6 @@ import ( extensions "k8s.io/api/extensions/v1beta1" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes/scheme" unversionedcore "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/client-go/tools/cache" @@ -62,7 +61,6 @@ type Controller struct { // NewController returns a network endpoint group controller. func NewController( - kubeClient kubernetes.Interface, cloud networkEndpointGroupCloud, ctx *context.ControllerContext, zoneGetter zoneGetter, @@ -74,7 +72,7 @@ func NewController( eventBroadcaster := record.NewBroadcaster() eventBroadcaster.StartLogging(glog.Infof) eventBroadcaster.StartRecordingToSink(&unversionedcore.EventSinkImpl{ - Interface: kubeClient.Core().Events(""), + Interface: ctx.KubeClient.Core().Events(""), }) recorder := eventBroadcaster.NewRecorder(scheme.Scheme, apiv1.EventSource{Component: "neg-controller"}) diff --git a/pkg/neg/controller_test.go b/pkg/neg/controller_test.go index e92bc9f91b..a43ca8d930 100644 --- a/pkg/neg/controller_test.go +++ b/pkg/neg/controller_test.go @@ -33,8 +33,8 @@ import ( ) func newTestController(kubeClient kubernetes.Interface) *Controller { - context := context.NewControllerContext(kubeClient, apiv1.NamespaceAll, 1*time.Second, true) - controller, _ := NewController(kubeClient, + context := context.NewControllerContext(kubeClient, nil, apiv1.NamespaceAll, 1*time.Second, true) + controller, _ := NewController( NewFakeNetworkEndpointGroupCloud("test-subnetwork", "test-network"), context, NewFakeZoneGetter(), diff --git a/pkg/neg/manager_test.go b/pkg/neg/manager_test.go index 671d1542db..97b5096bc6 100644 --- a/pkg/neg/manager_test.go +++ b/pkg/neg/manager_test.go @@ -36,7 +36,7 @@ const ( ) func NewTestSyncerManager(kubeClient kubernetes.Interface) *syncerManager { - context := context.NewControllerContext(kubeClient, apiv1.NamespaceAll, 1*time.Second, true) + context := context.NewControllerContext(kubeClient, nil, apiv1.NamespaceAll, 1*time.Second, true) manager := newSyncerManager( utils.NewNamer(CluseterID, ""), record.NewFakeRecorder(100), diff --git a/pkg/neg/syncer_test.go b/pkg/neg/syncer_test.go index 3982fbb20f..21e26889c9 100644 --- a/pkg/neg/syncer_test.go +++ b/pkg/neg/syncer_test.go @@ -23,7 +23,7 @@ const ( func NewTestSyncer() *syncer { kubeClient := fake.NewSimpleClientset() - context := context.NewControllerContext(kubeClient, apiv1.NamespaceAll, 1*time.Second, true) + context := context.NewControllerContext(kubeClient, nil, apiv1.NamespaceAll, 1*time.Second, true) svcPort := servicePort{ namespace: testServiceNamespace, name: testServiceName, diff --git a/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1/BUILD.bazel b/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1/BUILD.bazel new file mode 100644 index 0000000000..dfbfd54899 --- /dev/null +++ b/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1/BUILD.bazel @@ -0,0 +1,21 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "cluster.go", + "interface.go", + ], + importpath = "k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1", + visibility = ["//visibility:public"], + deps = [ + "//pkg/apis/clusterregistry/v1alpha1:go_default_library", + "//pkg/client/clientset_generated/clientset:go_default_library", + "//pkg/client/informers_generated/externalversions/internalinterfaces:go_default_library", + "//pkg/client/listers_generated/clusterregistry/v1alpha1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/watch:go_default_library", + "//vendor/k8s.io/client-go/tools/cache:go_default_library", + ], +) diff --git a/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1/cluster.go b/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1/cluster.go new file mode 100644 index 0000000000..cbba0df2ab --- /dev/null +++ b/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1/cluster.go @@ -0,0 +1,88 @@ +/* +Copyright 2018 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. +*/ + +// This file was automatically generated by informer-gen + +package v1alpha1 + +import ( + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + clusterregistry_v1alpha1 "k8s.io/cluster-registry/pkg/apis/clusterregistry/v1alpha1" + clientset "k8s.io/cluster-registry/pkg/client/clientset_generated/clientset" + internalinterfaces "k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/internalinterfaces" + v1alpha1 "k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1" +) + +// ClusterInformer provides access to a shared informer and lister for +// Clusters. +type ClusterInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.ClusterLister +} + +type clusterInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// NewClusterInformer constructs a new informer for Cluster type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewClusterInformer(client clientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredClusterInformer(client, resyncPeriod, indexers, nil) +} + +// NewFilteredClusterInformer constructs a new informer for Cluster type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredClusterInformer(client clientset.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ClusterregistryV1alpha1().Clusters().List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.ClusterregistryV1alpha1().Clusters().Watch(options) + }, + }, + &clusterregistry_v1alpha1.Cluster{}, + resyncPeriod, + indexers, + ) +} + +func (f *clusterInformer) defaultInformer(client clientset.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredClusterInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *clusterInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&clusterregistry_v1alpha1.Cluster{}, f.defaultInformer) +} + +func (f *clusterInformer) Lister() v1alpha1.ClusterLister { + return v1alpha1.NewClusterLister(f.Informer().GetIndexer()) +} diff --git a/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1/interface.go b/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1/interface.go new file mode 100644 index 0000000000..edb6d6a3f0 --- /dev/null +++ b/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/clusterregistry/v1alpha1/interface.go @@ -0,0 +1,45 @@ +/* +Copyright 2018 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. +*/ + +// This file was automatically generated by informer-gen + +package v1alpha1 + +import ( + internalinterfaces "k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // Clusters returns a ClusterInformer. + Clusters() ClusterInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// Clusters returns a ClusterInformer. +func (v *version) Clusters() ClusterInformer { + return &clusterInformer{factory: v.factory, tweakListOptions: v.tweakListOptions} +} diff --git a/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/internalinterfaces/BUILD.bazel b/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/internalinterfaces/BUILD.bazel new file mode 100644 index 0000000000..b2cee4c34c --- /dev/null +++ b/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/internalinterfaces/BUILD.bazel @@ -0,0 +1,14 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["factory_interfaces.go"], + importpath = "k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/internalinterfaces", + visibility = ["//visibility:public"], + deps = [ + "//pkg/client/clientset_generated/clientset:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", + "//vendor/k8s.io/client-go/tools/cache:go_default_library", + ], +) diff --git a/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/internalinterfaces/factory_interfaces.go b/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 0000000000..2624454cc3 --- /dev/null +++ b/vendor/k8s.io/cluster-registry/pkg/client/informers_generated/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,38 @@ +/* +Copyright 2018 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. +*/ + +// This file was automatically generated by informer-gen + +package internalinterfaces + +import ( + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" + clientset "k8s.io/cluster-registry/pkg/client/clientset_generated/clientset" +) + +type NewInformerFunc func(clientset.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/vendor/k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1/BUILD.bazel b/vendor/k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1/BUILD.bazel new file mode 100644 index 0000000000..7a41886289 --- /dev/null +++ b/vendor/k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1/BUILD.bazel @@ -0,0 +1,17 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = [ + "cluster.go", + "expansion_generated.go", + ], + importpath = "k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1", + visibility = ["//visibility:public"], + deps = [ + "//pkg/apis/clusterregistry/v1alpha1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library", + "//vendor/k8s.io/client-go/tools/cache:go_default_library", + ], +) diff --git a/vendor/k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1/cluster.go b/vendor/k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1/cluster.go new file mode 100644 index 0000000000..8aedc93f14 --- /dev/null +++ b/vendor/k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1/cluster.go @@ -0,0 +1,65 @@ +/* +Copyright 2018 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. +*/ + +// This file was automatically generated by lister-gen + +package v1alpha1 + +import ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1alpha1 "k8s.io/cluster-registry/pkg/apis/clusterregistry/v1alpha1" +) + +// ClusterLister helps list Clusters. +type ClusterLister interface { + // List lists all Clusters in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.Cluster, err error) + // Get retrieves the Cluster from the index for a given name. + Get(name string) (*v1alpha1.Cluster, error) + ClusterListerExpansion +} + +// clusterLister implements the ClusterLister interface. +type clusterLister struct { + indexer cache.Indexer +} + +// NewClusterLister returns a new ClusterLister. +func NewClusterLister(indexer cache.Indexer) ClusterLister { + return &clusterLister{indexer: indexer} +} + +// List lists all Clusters in the indexer. +func (s *clusterLister) List(selector labels.Selector) (ret []*v1alpha1.Cluster, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.Cluster)) + }) + return ret, err +} + +// Get retrieves the Cluster from the index for a given name. +func (s *clusterLister) Get(name string) (*v1alpha1.Cluster, error) { + obj, exists, err := s.indexer.GetByKey(name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("cluster"), name) + } + return obj.(*v1alpha1.Cluster), nil +} diff --git a/vendor/k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1/expansion_generated.go b/vendor/k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1/expansion_generated.go new file mode 100644 index 0000000000..eb1d7d218d --- /dev/null +++ b/vendor/k8s.io/cluster-registry/pkg/client/listers_generated/clusterregistry/v1alpha1/expansion_generated.go @@ -0,0 +1,23 @@ +/* +Copyright 2018 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. +*/ + +// This file was automatically generated by lister-gen + +package v1alpha1 + +// ClusterListerExpansion allows custom methods to be added to +// ClusterLister. +type ClusterListerExpansion interface{}