diff --git a/Makefile b/Makefile index 2012e06..3bd135e 100644 --- a/Makefile +++ b/Makefile @@ -42,16 +42,36 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases +MODULE_NAME ?= gitbucket.jerxie.com/yangyangxie/AnthosCertManager +INPUT_APIS ?= gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/apis/anthoscertmanager/v1,gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/apis/meta/v1 +LICENSE_PATH ?= hack/boilerplate.go.txt .PHONY: generate -generate: controller-gen client-gen ## Generate code containing DeepCopy, DeepCopyInto, ClientSet and DeepCopyObject method implementations. +generate: controller-gen client-gen informer-gen lister-gen ## Generate code containing DeepCopy, DeepCopyInto, ClientSet, Client Informer and DeepCopyObject method implementations. + $(CONTROLLER_GEN) object:headerFile="$(LICENSE_PATH)" paths="./..." + rm -rf ./pkg/client/clientset - $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." - $(CLIENT_GEN) --go-header-file hack/boilerplate.go.txt \ + $(CLIENT_GEN) --go-header-file $(LICENSE_PATH) \ --clientset-name versioned \ --input-base "" \ - --input "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/apis/anthoscertmanager/v1,gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/apis/meta/v1" \ - --trim-path-prefix="gitbucket.jerxie.com/yangyangxie/AnthosCertManager" \ - --output-package "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/clientset" \ + --input "$(INPUT_APIS)" \ + --trim-path-prefix="$(MODULE_NAME)" \ + --output-package "$(MODULE_NAME)/pkg/client/clientset" \ + --output-base ./ + + rm -rf ./pkg/client/listers + $(LISTER_GEN) --go-header-file $(LICENSE_PATH) \ + --input-dirs $(INPUT_APIS) \ + --trim-path-prefix=$(MODULE_NAME) \ + --output-package $(MODULE_NAME)/pkg/client/listers \ + --output-base ./ + + rm -rf ./pkg/client/informers + $(INFORMER_GEN) --go-header-file $(LICENSE_PATH) \ + --input-dirs $(INPUT_APIS) \ + --versioned-clientset-package $(MODULE_NAME)/pkg/client/clientset/versioned \ + --listers-package $(MODULE_NAME)/pkg/client/listers \ + --trim-path-prefix=$(MODULE_NAME) \ + --output-package $(MODULE_NAME)/pkg/client/informers \ --output-base ./ .PHONY: fmt @@ -138,6 +158,8 @@ KUSTOMIZE ?= $(LOCALBIN)/kustomize CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen CLIENT_GEN ?= $(LOCALBIN)/client-gen +INFORMER_GEN ?= $(LOCALBIN)/informer-gen +LISTER_GEN ?= $(LOCALBIN)/lister-gen ENVTEST ?= $(LOCALBIN)/setup-envtest ## Tool Versions @@ -163,6 +185,17 @@ $(CLIENT_GEN): $(LOCALBIN) test -s $(LOCALBIN)/client-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/client-gen@$(K8S_CODEGEN_VERSION) +.PHONY: informer-gen +informer-gen: $(INFORMER_GEN) +$(INFORMER_GEN): $(LOCALBIN) + test -s $(LOCALBIN)/informer-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/informer-gen@$(K8S_CODEGEN_VERSION) + +.PHONY: lister-gen +lister-gen: $(LISTER_GEN) +$(LISTER_GEN): $(LOCALBIN) + test -s $(LOCALBIN)/lister-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/lister-gen@$(K8S_CODEGEN_VERSION) + + .PHONY: envtest envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. $(ENVTEST): $(LOCALBIN) diff --git a/pkg/client/informers/externalversions/anthoscertmanager/interface.go b/pkg/client/informers/externalversions/anthoscertmanager/interface.go new file mode 100644 index 0000000..f1c7da2 --- /dev/null +++ b/pkg/client/informers/externalversions/anthoscertmanager/interface.go @@ -0,0 +1,45 @@ +/* +Copyright 2022. + +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 informer-gen. DO NOT EDIT. + +package anthoscertmanager + +import ( + v1 "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/informers/externalversions/anthoscertmanager/v1" + internalinterfaces "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type group 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 &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/anthoscertmanager/v1/interface.go b/pkg/client/informers/externalversions/anthoscertmanager/v1/interface.go new file mode 100644 index 0000000..180eb13 --- /dev/null +++ b/pkg/client/informers/externalversions/anthoscertmanager/v1/interface.go @@ -0,0 +1,44 @@ +/* +Copyright 2022. + +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 informer-gen. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // Issuers returns a IssuerInformer. + Issuers() IssuerInformer +} + +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} +} + +// Issuers returns a IssuerInformer. +func (v *version) Issuers() IssuerInformer { + return &issuerInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/anthoscertmanager/v1/issuer.go b/pkg/client/informers/externalversions/anthoscertmanager/v1/issuer.go new file mode 100644 index 0000000..026798b --- /dev/null +++ b/pkg/client/informers/externalversions/anthoscertmanager/v1/issuer.go @@ -0,0 +1,89 @@ +/* +Copyright 2022. + +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 informer-gen. DO NOT EDIT. + +package v1 + +import ( + "context" + time "time" + + anthoscertmanagerv1 "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/apis/anthoscertmanager/v1" + versioned "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/clientset/versioned" + internalinterfaces "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/informers/externalversions/internalinterfaces" + v1 "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/listers/anthoscertmanager/v1" + metav1 "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" +) + +// IssuerInformer provides access to a shared informer and lister for +// Issuers. +type IssuerInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.IssuerLister +} + +type issuerInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewIssuerInformer constructs a new informer for Issuer 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 NewIssuerInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredIssuerInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredIssuerInformer constructs a new informer for Issuer 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 NewFilteredIssuerInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.AnthosCertmanagerV1().Issuers(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.AnthosCertmanagerV1().Issuers(namespace).Watch(context.TODO(), options) + }, + }, + &anthoscertmanagerv1.Issuer{}, + resyncPeriod, + indexers, + ) +} + +func (f *issuerInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredIssuerInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *issuerInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&anthoscertmanagerv1.Issuer{}, f.defaultInformer) +} + +func (f *issuerInformer) Lister() v1.IssuerLister { + return v1.NewIssuerLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go new file mode 100644 index 0000000..ab8588a --- /dev/null +++ b/pkg/client/informers/externalversions/factory.go @@ -0,0 +1,179 @@ +/* +Copyright 2022. + +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 informer-gen. DO NOT EDIT. + +package externalversions + +import ( + reflect "reflect" + sync "sync" + time "time" + + versioned "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/clientset/versioned" + anthoscertmanager "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/informers/externalversions/anthoscertmanager" + internalinterfaces "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/informers/externalversions/internalinterfaces" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory + +type sharedInformerFactory struct { + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + + informers map[reflect.Type]cache.SharedIndexInformer + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[reflect.Type]bool +} + +// WithCustomResyncConfig sets a custom resync period for the specified informer types. +func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + for k, v := range resyncConfig { + factory.customResync[reflect.TypeOf(k)] = v + } + return factory + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.tweakListOptions = tweakListOptions + return factory + } +} + +// WithNamespace limits the SharedInformerFactory to the specified namespace. +func WithNamespace(namespace string) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.namespace = namespace + return factory + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + namespace: v1.NamespaceAll, + defaultResync: defaultResync, + informers: make(map[reflect.Type]cache.SharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + factory = opt(factory) + } + + return factory +} + +// Start initializes all requested informers. +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + go informer.Run(stopCh) + f.startedInformers[informerType] = true + } + } +} + +// WaitForCacheSync waits for all started informers' cache were synced. +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]cache.SharedIndexInformer{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[reflect.Type]bool{} + for informType, informer := range informers { + res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) + } + return res +} + +// InternalInformerFor returns the SharedIndexInformer for obj using an internal +// client. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := reflect.TypeOf(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + + resyncPeriod, exists := f.customResync[informerType] + if !exists { + resyncPeriod = f.defaultResync + } + + informer = newFunc(f.client, resyncPeriod) + f.informers[informerType] = informer + + return informer +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + AnthosCertmanager() anthoscertmanager.Interface +} + +func (f *sharedInformerFactory) AnthosCertmanager() anthoscertmanager.Interface { + return anthoscertmanager.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go new file mode 100644 index 0000000..8e475ba --- /dev/null +++ b/pkg/client/informers/externalversions/generic.go @@ -0,0 +1,61 @@ +/* +Copyright 2022. + +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 informer-gen. DO NOT EDIT. + +package externalversions + +import ( + "fmt" + + v1 "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/apis/anthoscertmanager/v1" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=anthos-cert-manager.io, Version=v1 + case v1.SchemeGroupVersion.WithResource("issuers"): + return &genericInformer{resource: resource.GroupResource(), informer: f.AnthosCertmanager().V1().Issuers().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 0000000..2586cb1 --- /dev/null +++ b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,39 @@ +/* +Copyright 2022. + +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 informer-gen. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + versioned "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/clientset/versioned" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" +) + +// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. +type NewInformerFunc func(versioned.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 +} + +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/client/listers/anthoscertmanager/v1/expansion_generated.go b/pkg/client/listers/anthoscertmanager/v1/expansion_generated.go new file mode 100644 index 0000000..a573a21 --- /dev/null +++ b/pkg/client/listers/anthoscertmanager/v1/expansion_generated.go @@ -0,0 +1,26 @@ +/* +Copyright 2022. + +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 lister-gen. DO NOT EDIT. + +package v1 + +// IssuerListerExpansion allows custom methods to be added to +// IssuerLister. +type IssuerListerExpansion interface{} + +// IssuerNamespaceListerExpansion allows custom methods to be added to +// IssuerNamespaceLister. +type IssuerNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/anthoscertmanager/v1/issuer.go b/pkg/client/listers/anthoscertmanager/v1/issuer.go new file mode 100644 index 0000000..20dddfe --- /dev/null +++ b/pkg/client/listers/anthoscertmanager/v1/issuer.go @@ -0,0 +1,98 @@ +/* +Copyright 2022. + +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 lister-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/apis/anthoscertmanager/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// IssuerLister helps list Issuers. +// All objects returned here must be treated as read-only. +type IssuerLister interface { + // List lists all Issuers in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.Issuer, err error) + // Issuers returns an object that can list and get Issuers. + Issuers(namespace string) IssuerNamespaceLister + IssuerListerExpansion +} + +// issuerLister implements the IssuerLister interface. +type issuerLister struct { + indexer cache.Indexer +} + +// NewIssuerLister returns a new IssuerLister. +func NewIssuerLister(indexer cache.Indexer) IssuerLister { + return &issuerLister{indexer: indexer} +} + +// List lists all Issuers in the indexer. +func (s *issuerLister) List(selector labels.Selector) (ret []*v1.Issuer, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.Issuer)) + }) + return ret, err +} + +// Issuers returns an object that can list and get Issuers. +func (s *issuerLister) Issuers(namespace string) IssuerNamespaceLister { + return issuerNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// IssuerNamespaceLister helps list and get Issuers. +// All objects returned here must be treated as read-only. +type IssuerNamespaceLister interface { + // List lists all Issuers in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1.Issuer, err error) + // Get retrieves the Issuer from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1.Issuer, error) + IssuerNamespaceListerExpansion +} + +// issuerNamespaceLister implements the IssuerNamespaceLister +// interface. +type issuerNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all Issuers in the indexer for a given namespace. +func (s issuerNamespaceLister) List(selector labels.Selector) (ret []*v1.Issuer, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1.Issuer)) + }) + return ret, err +} + +// Get retrieves the Issuer from the indexer for a given namespace and name. +func (s issuerNamespaceLister) Get(name string) (*v1.Issuer, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("issuer"), name) + } + return obj.(*v1.Issuer), nil +} diff --git a/pkg/controller/context.go b/pkg/controller/context.go index bba0a5a..6a5d8e0 100644 --- a/pkg/controller/context.go +++ b/pkg/controller/context.go @@ -14,6 +14,8 @@ "k8s.io/client-go/util/flowcontrol" "k8s.io/utils/clock" + clientset "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/clientset/versioned" + informers "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/client/informers/externalversions" logf "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/logs" "gitbucket.jerxie.com/yangyangxie/AnthosCertManager/pkg/util" "github.com/go-logr/logr" @@ -46,12 +48,19 @@ RESTConfig *rest.Config // Client is a Kubernetes clientset Client kubernetes.Interface + + // ACMClient is a anthos-cert-manager clientset + ACMClient clientset.Interface + // DiscoveryClient is a discovery interface. Usually set to Client.Discovery unless a fake client is in use. DiscoveryClient discovery.DiscoveryInterface // KubeSharedInformerFactory can be used to obtain shared // SharedIndexInformer instances for Kubernetes types KubeSharedInformerFactory kubeinformers.SharedInformerFactory + // SharedInformerFactory can be used to obtain shared SharedIndexInformer + // instances + SharedInformerFactory informers.SharedInformerFactory ContextOptions } @@ -160,6 +169,7 @@ return nil, err } + sharedInformarFactory := informers.NewSharedInformerFactoryWithOptions(clients.acmClient, resyncPeriod, informers.WithNamespace(opts.Namespace)) kubeSharedInformerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(clients.kubeClient, resyncPeriod, kubeinformers.WithNamespace(opts.Namespace)) return &ContextFactory{ @@ -169,6 +179,7 @@ RootContext: ctx, StopCh: ctx.Done(), KubeSharedInformerFactory: kubeSharedInformerFactory, + SharedInformerFactory: sharedInformarFactory, ContextOptions: opts, }, }, nil @@ -196,17 +207,23 @@ // contextClients is a helper struct containing API clients. type contextClients struct { kubeClient kubernetes.Interface + acmClient clientset.Interface } // buildClients builds all required clients for the context using the given // REST config. func buildClients(restConfig *rest.Config) (contextClients, error) { - // Create a Kubernetes api client + // create an anthos cert manager client + acmClient, err := clientset.NewForConfig(restConfig) + if err != nil { + return contextClients{}, fmt.Errorf("error creating internal group client: %w", err) + } + // create a Kubernetes api client kubeClient, err := kubernetes.NewForConfig(restConfig) if err != nil { return contextClients{}, fmt.Errorf("error creating kubernetes client: %w", err) } - return contextClients{kubeClient}, nil + return contextClients{kubeClient, acmClient}, nil }