Commit dc14f370 authored by Brad Davidson's avatar Brad Davidson Committed by Brad Davidson

Update wrangler to v0.8.5

Required to support apiextensions.v1 as v1beta1 has been deleted. Also update helm-controller and dynamiclistener to track wrangler versions. Signed-off-by: 's avatarBrad Davidson <brad.davidson@rancher.com>
parent c434db7c
......@@ -28,6 +28,7 @@ replace (
github.com/opencontainers/runc => github.com/opencontainers/runc v1.0.1
github.com/opencontainers/runtime-spec => github.com/opencontainers/runtime-spec v1.0.3-0.20210316141917-a8c4a9ee0f6b
github.com/rancher/k3s/pkg/data => ./pkg/data
github.com/rancher/wrangler => github.com/rancher/wrangler v0.8.5
go.etcd.io/etcd/api/v3 => github.com/k3s-io/etcd/api/v3 v3.5.0-k3s1
go.etcd.io/etcd/client/v3 => github.com/k3s-io/etcd/client/v3 v3.5.0-k3s1
go.etcd.io/etcd/etcdutl/v3 => github.com/k3s-io/etcd/etcdutl/v3 v3.5.0-k3s1
......@@ -88,7 +89,7 @@ require (
github.com/google/uuid v1.2.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.4.2
github.com/k3s-io/helm-controller v0.10.5
github.com/k3s-io/helm-controller v0.11.3
github.com/k3s-io/kine v0.7.3
github.com/klauspost/compress v1.12.2
github.com/kubernetes-sigs/cri-tools v0.0.0-00010101000000-000000000000
......@@ -103,11 +104,11 @@ require (
github.com/opencontainers/selinux v1.8.2
github.com/pierrec/lz4 v2.6.0+incompatible
github.com/pkg/errors v0.9.1
github.com/rancher/dynamiclistener v0.2.3
github.com/rancher/dynamiclistener v0.2.6
github.com/rancher/lasso v0.0.0-20210616224652-fc3ebd901c08
github.com/rancher/remotedialer v0.2.0
github.com/rancher/wharfie v0.3.4
github.com/rancher/wrangler v0.8.3
github.com/rancher/wrangler-api v0.6.0
github.com/robfig/cron/v3 v3.0.1
github.com/rootless-containers/rootlesskit v0.14.0
github.com/sirupsen/logrus v1.8.1
......
......@@ -9,7 +9,7 @@ import (
"github.com/rancher/k3s/pkg/etcd"
"github.com/rancher/k3s/pkg/util"
"github.com/rancher/k3s/pkg/version"
controllerv1 "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
controllerv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
clientv3 "go.etcd.io/etcd/client/v3"
v1 "k8s.io/api/core/v1"
)
......
......@@ -17,7 +17,7 @@ import (
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/etcd"
"github.com/rancher/k3s/pkg/version"
"github.com/rancher/wrangler-api/pkg/generated/controllers/core"
"github.com/rancher/wrangler/pkg/generated/controllers/core"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
......
......@@ -75,7 +75,8 @@ func main() {
Types: []interface{}{
v1.Addon{},
},
GenerateTypes: true,
GenerateTypes: true,
GenerateClients: true,
},
},
})
......
......@@ -10,7 +10,7 @@ import (
"strings"
"github.com/k3s-io/kine/pkg/endpoint"
"github.com/rancher/wrangler-api/pkg/generated/controllers/core"
"github.com/rancher/wrangler/pkg/generated/controllers/core"
utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apiserver/pkg/authentication/authenticator"
)
......
......@@ -18,7 +18,7 @@ import (
"github.com/rancher/k3s/pkg/daemons/executor"
util2 "github.com/rancher/k3s/pkg/util"
"github.com/rancher/k3s/pkg/version"
"github.com/rancher/wrangler-api/pkg/generated/controllers/rbac"
"github.com/rancher/wrangler/pkg/generated/controllers/rbac"
"github.com/sirupsen/logrus"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
......
......@@ -5,7 +5,7 @@ import (
"os"
"time"
controllerv1 "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
controllerv1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
)
......
......@@ -19,28 +19,12 @@ limitations under the License.
package k3s
import (
"context"
"time"
clientset "github.com/rancher/k3s/pkg/generated/clientset/versioned"
scheme "github.com/rancher/k3s/pkg/generated/clientset/versioned/scheme"
informers "github.com/rancher/k3s/pkg/generated/informers/externalversions"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
)
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct {
synced bool
informerFactory informers.SharedInformerFactory
clientset clientset.Interface
controllerManager *generic.ControllerManager
threadiness map[schema.GroupVersionKind]int
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
......@@ -61,66 +45,23 @@ func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*
})
}
type FactoryOptions struct {
Namespace string
Resync time.Duration
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
if opts == nil {
opts = &FactoryOptions{}
}
cs, err := clientset.NewForConfig(config)
if err != nil {
return nil, err
}
resync := opts.Resync
if resync == 0 {
resync = 2 * time.Hour
}
if opts.Namespace == "" {
informerFactory := informers.NewSharedInformerFactory(cs, resync)
return NewFactory(cs, informerFactory), nil
}
informerFactory := informers.NewSharedInformerFactoryWithOptions(cs, resync, informers.WithNamespace(opts.Namespace))
return NewFactory(cs, informerFactory), nil
}
func NewFactory(clientset clientset.Interface, informerFactory informers.SharedInformerFactory) *Factory {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
threadiness: map[schema.GroupVersionKind]int{},
controllerManager: &generic.ControllerManager{},
clientset: clientset,
informerFactory: informerFactory,
}
}
func (c *Factory) Controllers() map[schema.GroupVersionKind]*generic.Controller {
return c.controllerManager.Controllers()
}
func (c *Factory) SetThreadiness(gvk schema.GroupVersionKind, threadiness int) {
c.threadiness[gvk] = threadiness
Factory: f,
}, err
}
func (c *Factory) Sync(ctx context.Context) error {
c.informerFactory.Start(ctx.Done())
c.informerFactory.WaitForCacheSync(ctx.Done())
return nil
}
func (c *Factory) Start(ctx context.Context, defaultThreadiness int) error {
if err := c.Sync(ctx); err != nil {
return err
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return c.controllerManager.Start(ctx, defaultThreadiness, c.threadiness)
return f
}
func (c *Factory) K3s() Interface {
return New(c.controllerManager, c.informerFactory.K3s(), c.clientset)
return New(c.ControllerFactory())
}
......@@ -19,10 +19,8 @@ limitations under the License.
package k3s
import (
clientset "github.com/rancher/k3s/pkg/generated/clientset/versioned"
v1 "github.com/rancher/k3s/pkg/generated/controllers/k3s.cattle.io/v1"
informers "github.com/rancher/k3s/pkg/generated/informers/externalversions/k3s.cattle.io"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/lasso/pkg/controller"
)
type Interface interface {
......@@ -30,21 +28,16 @@ type Interface interface {
}
type group struct {
controllerManager *generic.ControllerManager
informers informers.Interface
client clientset.Interface
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerManager *generic.ControllerManager, informers informers.Interface,
client clientset.Interface) Interface {
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerManager: controllerManager,
informers: informers,
client: client,
controllerFactory: controllerFactory,
}
}
func (g *group) V1() v1.Interface {
return v1.New(g.controllerManager, g.client.K3sV1(), g.informers.V1())
return v1.New(g.controllerFactory)
}
......@@ -23,9 +23,8 @@ import (
"time"
v1 "github.com/rancher/k3s/pkg/apis/k3s.cattle.io/v1"
clientset "github.com/rancher/k3s/pkg/generated/clientset/versioned/typed/k3s.cattle.io/v1"
informers "github.com/rancher/k3s/pkg/generated/informers/externalversions/k3s.cattle.io/v1"
listers "github.com/rancher/k3s/pkg/generated/listers/k3s.cattle.io/v1"
"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"
......@@ -78,18 +77,22 @@ type AddonCache interface {
type AddonIndexer func(obj *v1.Addon) ([]string, error)
type addonController struct {
controllerManager *generic.ControllerManager
clientGetter clientset.AddonsGetter
informer informers.AddonInformer
gvk schema.GroupVersionKind
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewAddonController(gvk schema.GroupVersionKind, controllerManager *generic.ControllerManager, clientGetter clientset.AddonsGetter, informer informers.AddonInformer) AddonController {
func NewAddonController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) AddonController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &addonController{
controllerManager: controllerManager,
clientGetter: clientGetter,
informer: informer,
gvk: gvk,
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
......@@ -136,12 +139,11 @@ func UpdateAddonDeepCopyOnChange(client AddonClient, obj *v1.Addon, handler func
}
func (c *addonController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, handler)
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *addonController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), handler)
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *addonController) OnChange(ctx context.Context, name string, sync AddonHandler) {
......@@ -149,20 +151,19 @@ func (c *addonController) OnChange(ctx context.Context, name string, sync AddonH
}
func (c *addonController) OnRemove(ctx context.Context, name string, sync AddonHandler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), FromAddonHandlerToHandler(sync))
c.AddGenericHandler(ctx, name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromAddonHandlerToHandler(sync)))
}
func (c *addonController) Enqueue(namespace, name string) {
c.controllerManager.Enqueue(c.gvk, c.informer.Informer(), namespace, name)
c.controller.Enqueue(namespace, name)
}
func (c *addonController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controllerManager.EnqueueAfter(c.gvk, c.informer.Informer(), namespace, name, duration)
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *addonController) Informer() cache.SharedIndexInformer {
return c.informer.Informer()
return c.controller.Informer()
}
func (c *addonController) GroupVersionKind() schema.GroupVersionKind {
......@@ -171,57 +172,75 @@ func (c *addonController) GroupVersionKind() schema.GroupVersionKind {
func (c *addonController) Cache() AddonCache {
return &addonCache{
lister: c.informer.Lister(),
indexer: c.informer.Informer().GetIndexer(),
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *addonController) Create(obj *v1.Addon) (*v1.Addon, error) {
return c.clientGetter.Addons(obj.Namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
result := &v1.Addon{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *addonController) Update(obj *v1.Addon) (*v1.Addon, error) {
return c.clientGetter.Addons(obj.Namespace).Update(context.TODO(), obj, metav1.UpdateOptions{})
result := &v1.Addon{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *addonController) UpdateStatus(obj *v1.Addon) (*v1.Addon, error) {
return c.clientGetter.Addons(obj.Namespace).UpdateStatus(context.TODO(), obj, metav1.UpdateOptions{})
result := &v1.Addon{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *addonController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.clientGetter.Addons(namespace).Delete(context.TODO(), name, *options)
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *addonController) Get(namespace, name string, options metav1.GetOptions) (*v1.Addon, error) {
return c.clientGetter.Addons(namespace).Get(context.TODO(), name, options)
result := &v1.Addon{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *addonController) List(namespace string, opts metav1.ListOptions) (*v1.AddonList, error) {
return c.clientGetter.Addons(namespace).List(context.TODO(), opts)
result := &v1.AddonList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *addonController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.clientGetter.Addons(namespace).Watch(context.TODO(), opts)
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *addonController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Addon, err error) {
return c.clientGetter.Addons(namespace).Patch(context.TODO(), name, pt, data, metav1.PatchOptions{}, subresources...)
func (c *addonController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.Addon, error) {
result := &v1.Addon{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type addonCache struct {
lister listers.AddonLister
indexer cache.Indexer
indexer cache.Indexer
resource schema.GroupResource
}
func (c *addonCache) Get(namespace, name string) (*v1.Addon, error) {
return c.lister.Addons(namespace).Get(name)
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.Addon), nil
}
func (c *addonCache) List(namespace string, selector labels.Selector) ([]*v1.Addon, error) {
return c.lister.Addons(namespace).List(selector)
func (c *addonCache) List(namespace string, selector labels.Selector) (ret []*v1.Addon, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.Addon))
})
return ret, err
}
func (c *addonCache) AddIndexer(indexName string, indexer AddonIndexer) {
......@@ -299,12 +318,20 @@ func (a *addonStatusHandler) sync(key string, obj *v1.Addon) (*v1.Addon, error)
}
}
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
obj, newErr = a.client.UpdateStatus(obj)
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
......@@ -333,6 +360,10 @@ func (a *addonGeneratingHandler) Remove(key string, obj *v1.Addon) (*v1.Addon, e
}
func (a *addonGeneratingHandler) Handle(obj *v1.Addon, status v1.AddonStatus) (v1.AddonStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.AddonGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
......
......@@ -20,30 +20,29 @@ package v1
import (
v1 "github.com/rancher/k3s/pkg/apis/k3s.cattle.io/v1"
clientset "github.com/rancher/k3s/pkg/generated/clientset/versioned/typed/k3s.cattle.io/v1"
informers "github.com/rancher/k3s/pkg/generated/informers/externalversions/k3s.cattle.io/v1"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/lasso/pkg/controller"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v1.AddToScheme)
}
type Interface interface {
Addon() AddonController
}
func New(controllerManager *generic.ControllerManager, client clientset.K3sV1Interface,
informers informers.Interface) Interface {
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerManager: controllerManager,
client: client,
informers: informers,
controllerFactory: controllerFactory,
}
}
type version struct {
controllerManager *generic.ControllerManager
informers informers.Interface
client clientset.K3sV1Interface
controllerFactory controller.SharedControllerFactory
}
func (c *version) Addon() AddonController {
return NewAddonController(v1.SchemeGroupVersion.WithKind("Addon"), c.controllerManager, c.client, c.informers.Addons())
return NewAddonController(schema.GroupVersionKind{Group: "k3s.cattle.io", Version: "v1", Kind: "Addon"}, "addons", true, c.controllerFactory)
}
/*
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 externalversions
import (
reflect "reflect"
sync "sync"
time "time"
versioned "github.com/rancher/k3s/pkg/generated/clientset/versioned"
internalinterfaces "github.com/rancher/k3s/pkg/generated/informers/externalversions/internalinterfaces"
k3scattleio "github.com/rancher/k3s/pkg/generated/informers/externalversions/k3s.cattle.io"
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
K3s() k3scattleio.Interface
}
func (f *sharedInformerFactory) K3s() k3scattleio.Interface {
return k3scattleio.New(f, f.namespace, f.tweakListOptions)
}
/*
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 externalversions
import (
"fmt"
v1 "github.com/rancher/k3s/pkg/apis/k3s.cattle.io/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=k3s.cattle.io, Version=v1
case v1.SchemeGroupVersion.WithResource("addons"):
return &genericInformer{resource: resource.GroupResource(), informer: f.K3s().V1().Addons().Informer()}, nil
}
return nil, fmt.Errorf("no informer found for %v", resource)
}
/*
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 internalinterfaces
import (
time "time"
versioned "github.com/rancher/k3s/pkg/generated/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)
/*
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 k3s
import (
internalinterfaces "github.com/rancher/k3s/pkg/generated/informers/externalversions/internalinterfaces"
v1 "github.com/rancher/k3s/pkg/generated/informers/externalversions/k3s.cattle.io/v1"
)
// 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)
}
/*
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 "time"
k3scattleiov1 "github.com/rancher/k3s/pkg/apis/k3s.cattle.io/v1"
versioned "github.com/rancher/k3s/pkg/generated/clientset/versioned"
internalinterfaces "github.com/rancher/k3s/pkg/generated/informers/externalversions/internalinterfaces"
v1 "github.com/rancher/k3s/pkg/generated/listers/k3s.cattle.io/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"
)
// AddonInformer provides access to a shared informer and lister for
// Addons.
type AddonInformer interface {
Informer() cache.SharedIndexInformer
Lister() v1.AddonLister
}
type addonInformer struct {
factory internalinterfaces.SharedInformerFactory
tweakListOptions internalinterfaces.TweakListOptionsFunc
namespace string
}
// NewAddonInformer constructs a new informer for Addon 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 NewAddonInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredAddonInformer(client, namespace, resyncPeriod, indexers, nil)
}
// NewFilteredAddonInformer constructs a new informer for Addon 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 NewFilteredAddonInformer(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.K3sV1().Addons(namespace).List(context.TODO(), options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.K3sV1().Addons(namespace).Watch(context.TODO(), options)
},
},
&k3scattleiov1.Addon{},
resyncPeriod,
indexers,
)
}
func (f *addonInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewFilteredAddonInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
}
func (f *addonInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&k3scattleiov1.Addon{}, f.defaultInformer)
}
func (f *addonInformer) Lister() v1.AddonLister {
return v1.NewAddonLister(f.Informer().GetIndexer())
}
/*
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 (
internalinterfaces "github.com/rancher/k3s/pkg/generated/informers/externalversions/internalinterfaces"
)
// Interface provides access to all the informers in this group version.
type Interface interface {
// Addons returns a AddonInformer.
Addons() AddonInformer
}
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}
}
// Addons returns a AddonInformer.
func (v *version) Addons() AddonInformer {
return &addonInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}
/*
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 (
v1 "github.com/rancher/k3s/pkg/apis/k3s.cattle.io/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
// AddonLister helps list Addons.
// All objects returned here must be treated as read-only.
type AddonLister interface {
// List lists all Addons in the indexer.
// Objects returned here must be treated as read-only.
List(selector labels.Selector) (ret []*v1.Addon, err error)
// Addons returns an object that can list and get Addons.
Addons(namespace string) AddonNamespaceLister
AddonListerExpansion
}
// addonLister implements the AddonLister interface.
type addonLister struct {
indexer cache.Indexer
}
// NewAddonLister returns a new AddonLister.
func NewAddonLister(indexer cache.Indexer) AddonLister {
return &addonLister{indexer: indexer}
}
// List lists all Addons in the indexer.
func (s *addonLister) List(selector labels.Selector) (ret []*v1.Addon, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1.Addon))
})
return ret, err
}
// Addons returns an object that can list and get Addons.
func (s *addonLister) Addons(namespace string) AddonNamespaceLister {
return addonNamespaceLister{indexer: s.indexer, namespace: namespace}
}
// AddonNamespaceLister helps list and get Addons.
// All objects returned here must be treated as read-only.
type AddonNamespaceLister interface {
// List lists all Addons in the indexer for a given namespace.
// Objects returned here must be treated as read-only.
List(selector labels.Selector) (ret []*v1.Addon, err error)
// Get retrieves the Addon from the indexer for a given namespace and name.
// Objects returned here must be treated as read-only.
Get(name string) (*v1.Addon, error)
AddonNamespaceListerExpansion
}
// addonNamespaceLister implements the AddonNamespaceLister
// interface.
type addonNamespaceLister struct {
indexer cache.Indexer
namespace string
}
// List lists all Addons in the indexer for a given namespace.
func (s addonNamespaceLister) List(selector labels.Selector) (ret []*v1.Addon, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.Addon))
})
return ret, err
}
// Get retrieves the Addon from the indexer for a given namespace and name.
func (s addonNamespaceLister) Get(name string) (*v1.Addon, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v1.Resource("addon"), name)
}
return obj.(*v1.Addon), nil
}
/*
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
// AddonListerExpansion allows custom methods to be added to
// AddonLister.
type AddonListerExpansion interface{}
// AddonNamespaceListerExpansion allows custom methods to be added to
// AddonNamespaceLister.
type AddonNamespaceListerExpansion interface{}
......@@ -6,7 +6,7 @@ import (
"github.com/pkg/errors"
"github.com/rancher/k3s/pkg/nodepassword"
coreclient "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
coreclient "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus"
core "k8s.io/api/core/v1"
)
......
......@@ -10,7 +10,7 @@ import (
"github.com/rancher/k3s/pkg/authenticator/hash"
"github.com/rancher/k3s/pkg/passwd"
"github.com/rancher/k3s/pkg/version"
coreclient "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
coreclient "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
......
......@@ -7,7 +7,7 @@ import (
"time"
"github.com/rancher/k3s/pkg/rootless"
coreClients "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
coreClients "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/rootless-containers/rootlesskit/pkg/api/client"
"github.com/rootless-containers/rootlesskit/pkg/port"
"github.com/sirupsen/logrus"
......
......@@ -3,7 +3,7 @@ package rootlessports
import (
"context"
coreClients "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
coreClients "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
)
func Register(ctx context.Context, serviceController coreClients.ServiceController, enabled bool, httpsPort int) error {
......
......@@ -11,10 +11,10 @@ import (
"github.com/rancher/k3s/pkg/deploy"
"github.com/rancher/k3s/pkg/generated/controllers/k3s.cattle.io"
"github.com/rancher/k3s/pkg/version"
"github.com/rancher/wrangler-api/pkg/generated/controllers/apps"
"github.com/rancher/wrangler-api/pkg/generated/controllers/batch"
"github.com/rancher/wrangler-api/pkg/generated/controllers/core"
"github.com/rancher/wrangler-api/pkg/generated/controllers/rbac"
"github.com/rancher/wrangler/pkg/generated/controllers/apps"
"github.com/rancher/wrangler/pkg/generated/controllers/batch"
"github.com/rancher/wrangler/pkg/generated/controllers/core"
"github.com/rancher/wrangler/pkg/generated/controllers/rbac"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/crd"
"github.com/rancher/wrangler/pkg/start"
......
......@@ -23,7 +23,7 @@ import (
"github.com/rancher/k3s/pkg/daemons/config"
"github.com/rancher/k3s/pkg/nodepassword"
"github.com/rancher/k3s/pkg/version"
coreclient "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
coreclient "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/json"
)
......
......@@ -29,7 +29,7 @@ import (
"github.com/rancher/k3s/pkg/static"
"github.com/rancher/k3s/pkg/util"
"github.com/rancher/k3s/pkg/version"
v1 "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
v1 "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/rancher/wrangler/pkg/leader"
"github.com/rancher/wrangler/pkg/resolvehome"
"github.com/sirupsen/logrus"
......
......@@ -7,8 +7,8 @@ import (
"strconv"
"github.com/rancher/k3s/pkg/version"
appclient "github.com/rancher/wrangler-api/pkg/generated/controllers/apps/v1"
coreclient "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
appclient "github.com/rancher/wrangler/pkg/generated/controllers/apps/v1"
coreclient "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/rancher/wrangler/pkg/apply"
"github.com/rancher/wrangler/pkg/condition"
"github.com/rancher/wrangler/pkg/objectset"
......
/*
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 versioned
import (
"fmt"
helmv1 "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1"
discovery "k8s.io/client-go/discovery"
rest "k8s.io/client-go/rest"
flowcontrol "k8s.io/client-go/util/flowcontrol"
)
type Interface interface {
Discovery() discovery.DiscoveryInterface
HelmV1() helmv1.HelmV1Interface
}
// Clientset contains the clients for groups. Each group has exactly one
// version included in a Clientset.
type Clientset struct {
*discovery.DiscoveryClient
helmV1 *helmv1.HelmV1Client
}
// HelmV1 retrieves the HelmV1Client
func (c *Clientset) HelmV1() helmv1.HelmV1Interface {
return c.helmV1
}
// Discovery retrieves the DiscoveryClient
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
if c == nil {
return nil
}
return c.DiscoveryClient
}
// NewForConfig creates a new Clientset for the given config.
// If config's RateLimiter is not set and QPS and Burst are acceptable,
// NewForConfig will generate a rate-limiter in configShallowCopy.
func NewForConfig(c *rest.Config) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
if configShallowCopy.Burst <= 0 {
return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0")
}
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
var cs Clientset
var err error
cs.helmV1, err = helmv1.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
return &cs, nil
}
// NewForConfigOrDie creates a new Clientset for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *Clientset {
var cs Clientset
cs.helmV1 = helmv1.NewForConfigOrDie(c)
cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c)
return &cs
}
// New creates a new Clientset for the given RESTClient.
func New(c rest.Interface) *Clientset {
var cs Clientset
cs.helmV1 = helmv1.New(c)
cs.DiscoveryClient = discovery.NewDiscoveryClient(c)
return &cs
}
/*
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.
// This package has the automatically generated clientset.
package versioned
/*
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.
// This package contains the scheme of the automatically generated clientset.
package scheme
/*
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 scheme
import (
helmv1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
)
var Scheme = runtime.NewScheme()
var Codecs = serializer.NewCodecFactory(Scheme)
var ParameterCodec = runtime.NewParameterCodec(Scheme)
var localSchemeBuilder = runtime.SchemeBuilder{
helmv1.AddToScheme,
}
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
// of clientsets, like in:
//
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
//
// kclientset, _ := kubernetes.NewForConfig(c)
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
//
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
var AddToScheme = localSchemeBuilder.AddToScheme
func init() {
v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
utilruntime.Must(AddToScheme(Scheme))
}
/*
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.
// This package has the automatically generated typed clients.
package v1
/*
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
type HelmChartExpansion interface{}
type HelmChartConfigExpansion interface{}
/*
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 (
v1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
"github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned/scheme"
rest "k8s.io/client-go/rest"
)
type HelmV1Interface interface {
RESTClient() rest.Interface
HelmChartsGetter
HelmChartConfigsGetter
}
// HelmV1Client is used to interact with features provided by the helm.cattle.io group.
type HelmV1Client struct {
restClient rest.Interface
}
func (c *HelmV1Client) HelmCharts(namespace string) HelmChartInterface {
return newHelmCharts(c, namespace)
}
func (c *HelmV1Client) HelmChartConfigs(namespace string) HelmChartConfigInterface {
return newHelmChartConfigs(c, namespace)
}
// NewForConfig creates a new HelmV1Client for the given config.
func NewForConfig(c *rest.Config) (*HelmV1Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
client, err := rest.RESTClientFor(&config)
if err != nil {
return nil, err
}
return &HelmV1Client{client}, nil
}
// NewForConfigOrDie creates a new HelmV1Client for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *HelmV1Client {
client, err := NewForConfig(c)
if err != nil {
panic(err)
}
return client
}
// New creates a new HelmV1Client for the given RESTClient.
func New(c rest.Interface) *HelmV1Client {
return &HelmV1Client{c}
}
func setConfigDefaults(config *rest.Config) error {
gv := v1.SchemeGroupVersion
config.GroupVersion = &gv
config.APIPath = "/apis"
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
if config.UserAgent == "" {
config.UserAgent = rest.DefaultKubernetesUserAgent()
}
return nil
}
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *HelmV1Client) RESTClient() rest.Interface {
if c == nil {
return nil
}
return c.restClient
}
/*
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"
v1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
scheme "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned/scheme"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
)
// HelmChartsGetter has a method to return a HelmChartInterface.
// A group's client should implement this interface.
type HelmChartsGetter interface {
HelmCharts(namespace string) HelmChartInterface
}
// HelmChartInterface has methods to work with HelmChart resources.
type HelmChartInterface interface {
Create(ctx context.Context, helmChart *v1.HelmChart, opts metav1.CreateOptions) (*v1.HelmChart, error)
Update(ctx context.Context, helmChart *v1.HelmChart, opts metav1.UpdateOptions) (*v1.HelmChart, error)
UpdateStatus(ctx context.Context, helmChart *v1.HelmChart, opts metav1.UpdateOptions) (*v1.HelmChart, error)
Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error
DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error
Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.HelmChart, error)
List(ctx context.Context, opts metav1.ListOptions) (*v1.HelmChartList, error)
Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.HelmChart, err error)
HelmChartExpansion
}
// helmCharts implements HelmChartInterface
type helmCharts struct {
client rest.Interface
ns string
}
// newHelmCharts returns a HelmCharts
func newHelmCharts(c *HelmV1Client, namespace string) *helmCharts {
return &helmCharts{
client: c.RESTClient(),
ns: namespace,
}
}
// Get takes name of the helmChart, and returns the corresponding helmChart object, and an error if there is any.
func (c *helmCharts) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.HelmChart, err error) {
result = &v1.HelmChart{}
err = c.client.Get().
Namespace(c.ns).
Resource("helmcharts").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of HelmCharts that match those selectors.
func (c *helmCharts) List(ctx context.Context, opts metav1.ListOptions) (result *v1.HelmChartList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v1.HelmChartList{}
err = c.client.Get().
Namespace(c.ns).
Resource("helmcharts").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested helmCharts.
func (c *helmCharts) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("helmcharts").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
// Create takes the representation of a helmChart and creates it. Returns the server's representation of the helmChart, and an error, if there is any.
func (c *helmCharts) Create(ctx context.Context, helmChart *v1.HelmChart, opts metav1.CreateOptions) (result *v1.HelmChart, err error) {
result = &v1.HelmChart{}
err = c.client.Post().
Namespace(c.ns).
Resource("helmcharts").
VersionedParams(&opts, scheme.ParameterCodec).
Body(helmChart).
Do(ctx).
Into(result)
return
}
// Update takes the representation of a helmChart and updates it. Returns the server's representation of the helmChart, and an error, if there is any.
func (c *helmCharts) Update(ctx context.Context, helmChart *v1.HelmChart, opts metav1.UpdateOptions) (result *v1.HelmChart, err error) {
result = &v1.HelmChart{}
err = c.client.Put().
Namespace(c.ns).
Resource("helmcharts").
Name(helmChart.Name).
VersionedParams(&opts, scheme.ParameterCodec).
Body(helmChart).
Do(ctx).
Into(result)
return
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *helmCharts) UpdateStatus(ctx context.Context, helmChart *v1.HelmChart, opts metav1.UpdateOptions) (result *v1.HelmChart, err error) {
result = &v1.HelmChart{}
err = c.client.Put().
Namespace(c.ns).
Resource("helmcharts").
Name(helmChart.Name).
SubResource("status").
VersionedParams(&opts, scheme.ParameterCodec).
Body(helmChart).
Do(ctx).
Into(result)
return
}
// Delete takes name of the helmChart and deletes it. Returns an error if one occurs.
func (c *helmCharts) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("helmcharts").
Name(name).
Body(&opts).
Do(ctx).
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *helmCharts) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
var timeout time.Duration
if listOpts.TimeoutSeconds != nil {
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
}
return c.client.Delete().
Namespace(c.ns).
Resource("helmcharts").
VersionedParams(&listOpts, scheme.ParameterCodec).
Timeout(timeout).
Body(&opts).
Do(ctx).
Error()
}
// Patch applies the patch and returns the patched helmChart.
func (c *helmCharts) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.HelmChart, err error) {
result = &v1.HelmChart{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("helmcharts").
Name(name).
SubResource(subresources...).
VersionedParams(&opts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}
/*
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"
v1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
scheme "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned/scheme"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
)
// HelmChartConfigsGetter has a method to return a HelmChartConfigInterface.
// A group's client should implement this interface.
type HelmChartConfigsGetter interface {
HelmChartConfigs(namespace string) HelmChartConfigInterface
}
// HelmChartConfigInterface has methods to work with HelmChartConfig resources.
type HelmChartConfigInterface interface {
Create(ctx context.Context, helmChartConfig *v1.HelmChartConfig, opts metav1.CreateOptions) (*v1.HelmChartConfig, error)
Update(ctx context.Context, helmChartConfig *v1.HelmChartConfig, opts metav1.UpdateOptions) (*v1.HelmChartConfig, error)
Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error
DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error
Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.HelmChartConfig, error)
List(ctx context.Context, opts metav1.ListOptions) (*v1.HelmChartConfigList, error)
Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.HelmChartConfig, err error)
HelmChartConfigExpansion
}
// helmChartConfigs implements HelmChartConfigInterface
type helmChartConfigs struct {
client rest.Interface
ns string
}
// newHelmChartConfigs returns a HelmChartConfigs
func newHelmChartConfigs(c *HelmV1Client, namespace string) *helmChartConfigs {
return &helmChartConfigs{
client: c.RESTClient(),
ns: namespace,
}
}
// Get takes name of the helmChartConfig, and returns the corresponding helmChartConfig object, and an error if there is any.
func (c *helmChartConfigs) Get(ctx context.Context, name string, options metav1.GetOptions) (result *v1.HelmChartConfig, err error) {
result = &v1.HelmChartConfig{}
err = c.client.Get().
Namespace(c.ns).
Resource("helmchartconfigs").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of HelmChartConfigs that match those selectors.
func (c *helmChartConfigs) List(ctx context.Context, opts metav1.ListOptions) (result *v1.HelmChartConfigList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v1.HelmChartConfigList{}
err = c.client.Get().
Namespace(c.ns).
Resource("helmchartconfigs").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested helmChartConfigs.
func (c *helmChartConfigs) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("helmchartconfigs").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
// Create takes the representation of a helmChartConfig and creates it. Returns the server's representation of the helmChartConfig, and an error, if there is any.
func (c *helmChartConfigs) Create(ctx context.Context, helmChartConfig *v1.HelmChartConfig, opts metav1.CreateOptions) (result *v1.HelmChartConfig, err error) {
result = &v1.HelmChartConfig{}
err = c.client.Post().
Namespace(c.ns).
Resource("helmchartconfigs").
VersionedParams(&opts, scheme.ParameterCodec).
Body(helmChartConfig).
Do(ctx).
Into(result)
return
}
// Update takes the representation of a helmChartConfig and updates it. Returns the server's representation of the helmChartConfig, and an error, if there is any.
func (c *helmChartConfigs) Update(ctx context.Context, helmChartConfig *v1.HelmChartConfig, opts metav1.UpdateOptions) (result *v1.HelmChartConfig, err error) {
result = &v1.HelmChartConfig{}
err = c.client.Put().
Namespace(c.ns).
Resource("helmchartconfigs").
Name(helmChartConfig.Name).
VersionedParams(&opts, scheme.ParameterCodec).
Body(helmChartConfig).
Do(ctx).
Into(result)
return
}
// Delete takes name of the helmChartConfig and deletes it. Returns an error if one occurs.
func (c *helmChartConfigs) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("helmchartconfigs").
Name(name).
Body(&opts).
Do(ctx).
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *helmChartConfigs) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
var timeout time.Duration
if listOpts.TimeoutSeconds != nil {
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
}
return c.client.Delete().
Namespace(c.ns).
Resource("helmchartconfigs").
VersionedParams(&listOpts, scheme.ParameterCodec).
Timeout(timeout).
Body(&opts).
Do(ctx).
Error()
}
// Patch applies the patch and returns the patched helmChartConfig.
func (c *helmChartConfigs) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.HelmChartConfig, err error) {
result = &v1.HelmChartConfig{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("helmchartconfigs").
Name(name).
SubResource(subresources...).
VersionedParams(&opts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}
......@@ -19,28 +19,12 @@ limitations under the License.
package helm
import (
"context"
"time"
clientset "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned"
scheme "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned/scheme"
informers "github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
)
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct {
synced bool
informerFactory informers.SharedInformerFactory
clientset clientset.Interface
controllerManager *generic.ControllerManager
threadiness map[schema.GroupVersionKind]int
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
......@@ -61,66 +45,23 @@ func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*
})
}
type FactoryOptions struct {
Namespace string
Resync time.Duration
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
if opts == nil {
opts = &FactoryOptions{}
}
cs, err := clientset.NewForConfig(config)
if err != nil {
return nil, err
}
resync := opts.Resync
if resync == 0 {
resync = 2 * time.Hour
}
if opts.Namespace == "" {
informerFactory := informers.NewSharedInformerFactory(cs, resync)
return NewFactory(cs, informerFactory), nil
}
informerFactory := informers.NewSharedInformerFactoryWithOptions(cs, resync, informers.WithNamespace(opts.Namespace))
return NewFactory(cs, informerFactory), nil
}
func NewFactory(clientset clientset.Interface, informerFactory informers.SharedInformerFactory) *Factory {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
threadiness: map[schema.GroupVersionKind]int{},
controllerManager: &generic.ControllerManager{},
clientset: clientset,
informerFactory: informerFactory,
}
}
func (c *Factory) Controllers() map[schema.GroupVersionKind]*generic.Controller {
return c.controllerManager.Controllers()
}
func (c *Factory) SetThreadiness(gvk schema.GroupVersionKind, threadiness int) {
c.threadiness[gvk] = threadiness
Factory: f,
}, err
}
func (c *Factory) Sync(ctx context.Context) error {
c.informerFactory.Start(ctx.Done())
c.informerFactory.WaitForCacheSync(ctx.Done())
return nil
}
func (c *Factory) Start(ctx context.Context, defaultThreadiness int) error {
if err := c.Sync(ctx); err != nil {
return err
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return c.controllerManager.Start(ctx, defaultThreadiness, c.threadiness)
return f
}
func (c *Factory) Helm() Interface {
return New(c.controllerManager, c.informerFactory.Helm(), c.clientset)
return New(c.ControllerFactory())
}
......@@ -19,10 +19,8 @@ limitations under the License.
package helm
import (
clientset "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned"
v1 "github.com/k3s-io/helm-controller/pkg/generated/controllers/helm.cattle.io/v1"
informers "github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/helm.cattle.io"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/lasso/pkg/controller"
)
type Interface interface {
......@@ -30,21 +28,16 @@ type Interface interface {
}
type group struct {
controllerManager *generic.ControllerManager
informers informers.Interface
client clientset.Interface
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerManager *generic.ControllerManager, informers informers.Interface,
client clientset.Interface) Interface {
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerManager: controllerManager,
informers: informers,
client: client,
controllerFactory: controllerFactory,
}
}
func (g *group) V1() v1.Interface {
return v1.New(g.controllerManager, g.client.HelmV1(), g.informers.V1())
return v1.New(g.controllerFactory)
}
......@@ -23,9 +23,8 @@ import (
"time"
v1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
clientset "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1"
informers "github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/helm.cattle.io/v1"
listers "github.com/k3s-io/helm-controller/pkg/generated/listers/helm.cattle.io/v1"
"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"
......@@ -78,18 +77,22 @@ type HelmChartCache interface {
type HelmChartIndexer func(obj *v1.HelmChart) ([]string, error)
type helmChartController struct {
controllerManager *generic.ControllerManager
clientGetter clientset.HelmChartsGetter
informer informers.HelmChartInformer
gvk schema.GroupVersionKind
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewHelmChartController(gvk schema.GroupVersionKind, controllerManager *generic.ControllerManager, clientGetter clientset.HelmChartsGetter, informer informers.HelmChartInformer) HelmChartController {
func NewHelmChartController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) HelmChartController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &helmChartController{
controllerManager: controllerManager,
clientGetter: clientGetter,
informer: informer,
gvk: gvk,
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
......@@ -136,12 +139,11 @@ func UpdateHelmChartDeepCopyOnChange(client HelmChartClient, obj *v1.HelmChart,
}
func (c *helmChartController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, handler)
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *helmChartController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), handler)
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *helmChartController) OnChange(ctx context.Context, name string, sync HelmChartHandler) {
......@@ -149,20 +151,19 @@ func (c *helmChartController) OnChange(ctx context.Context, name string, sync He
}
func (c *helmChartController) OnRemove(ctx context.Context, name string, sync HelmChartHandler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), FromHelmChartHandlerToHandler(sync))
c.AddGenericHandler(ctx, name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromHelmChartHandlerToHandler(sync)))
}
func (c *helmChartController) Enqueue(namespace, name string) {
c.controllerManager.Enqueue(c.gvk, c.informer.Informer(), namespace, name)
c.controller.Enqueue(namespace, name)
}
func (c *helmChartController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controllerManager.EnqueueAfter(c.gvk, c.informer.Informer(), namespace, name, duration)
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *helmChartController) Informer() cache.SharedIndexInformer {
return c.informer.Informer()
return c.controller.Informer()
}
func (c *helmChartController) GroupVersionKind() schema.GroupVersionKind {
......@@ -171,57 +172,75 @@ func (c *helmChartController) GroupVersionKind() schema.GroupVersionKind {
func (c *helmChartController) Cache() HelmChartCache {
return &helmChartCache{
lister: c.informer.Lister(),
indexer: c.informer.Informer().GetIndexer(),
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *helmChartController) Create(obj *v1.HelmChart) (*v1.HelmChart, error) {
return c.clientGetter.HelmCharts(obj.Namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
result := &v1.HelmChart{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *helmChartController) Update(obj *v1.HelmChart) (*v1.HelmChart, error) {
return c.clientGetter.HelmCharts(obj.Namespace).Update(context.TODO(), obj, metav1.UpdateOptions{})
result := &v1.HelmChart{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *helmChartController) UpdateStatus(obj *v1.HelmChart) (*v1.HelmChart, error) {
return c.clientGetter.HelmCharts(obj.Namespace).UpdateStatus(context.TODO(), obj, metav1.UpdateOptions{})
result := &v1.HelmChart{}
return result, c.client.UpdateStatus(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *helmChartController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.clientGetter.HelmCharts(namespace).Delete(context.TODO(), name, *options)
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *helmChartController) Get(namespace, name string, options metav1.GetOptions) (*v1.HelmChart, error) {
return c.clientGetter.HelmCharts(namespace).Get(context.TODO(), name, options)
result := &v1.HelmChart{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *helmChartController) List(namespace string, opts metav1.ListOptions) (*v1.HelmChartList, error) {
return c.clientGetter.HelmCharts(namespace).List(context.TODO(), opts)
result := &v1.HelmChartList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *helmChartController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.clientGetter.HelmCharts(namespace).Watch(context.TODO(), opts)
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *helmChartController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.HelmChart, err error) {
return c.clientGetter.HelmCharts(namespace).Patch(context.TODO(), name, pt, data, metav1.PatchOptions{}, subresources...)
func (c *helmChartController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.HelmChart, error) {
result := &v1.HelmChart{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type helmChartCache struct {
lister listers.HelmChartLister
indexer cache.Indexer
indexer cache.Indexer
resource schema.GroupResource
}
func (c *helmChartCache) Get(namespace, name string) (*v1.HelmChart, error) {
return c.lister.HelmCharts(namespace).Get(name)
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.HelmChart), nil
}
func (c *helmChartCache) List(namespace string, selector labels.Selector) ([]*v1.HelmChart, error) {
return c.lister.HelmCharts(namespace).List(selector)
func (c *helmChartCache) List(namespace string, selector labels.Selector) (ret []*v1.HelmChart, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.HelmChart))
})
return ret, err
}
func (c *helmChartCache) AddIndexer(indexName string, indexer HelmChartIndexer) {
......@@ -299,12 +318,20 @@ func (a *helmChartStatusHandler) sync(key string, obj *v1.HelmChart) (*v1.HelmCh
}
}
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
obj, newErr = a.client.UpdateStatus(obj)
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
......@@ -333,6 +360,10 @@ func (a *helmChartGeneratingHandler) Remove(key string, obj *v1.HelmChart) (*v1.
}
func (a *helmChartGeneratingHandler) Handle(obj *v1.HelmChart, status v1.HelmChartStatus) (v1.HelmChartStatus, error) {
if !obj.DeletionTimestamp.IsZero() {
return status, nil
}
objs, newStatus, err := a.HelmChartGeneratingHandler(obj, status)
if err != nil {
return newStatus, err
......
......@@ -23,11 +23,11 @@ import (
"time"
v1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
clientset "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1"
informers "github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/helm.cattle.io/v1"
listers "github.com/k3s-io/helm-controller/pkg/generated/listers/helm.cattle.io/v1"
"github.com/rancher/lasso/pkg/client"
"github.com/rancher/lasso/pkg/controller"
"github.com/rancher/wrangler/pkg/generic"
"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"
......@@ -74,18 +74,22 @@ type HelmChartConfigCache interface {
type HelmChartConfigIndexer func(obj *v1.HelmChartConfig) ([]string, error)
type helmChartConfigController struct {
controllerManager *generic.ControllerManager
clientGetter clientset.HelmChartConfigsGetter
informer informers.HelmChartConfigInformer
gvk schema.GroupVersionKind
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewHelmChartConfigController(gvk schema.GroupVersionKind, controllerManager *generic.ControllerManager, clientGetter clientset.HelmChartConfigsGetter, informer informers.HelmChartConfigInformer) HelmChartConfigController {
func NewHelmChartConfigController(gvk schema.GroupVersionKind, resource string, namespaced bool, controller controller.SharedControllerFactory) HelmChartConfigController {
c := controller.ForResourceKind(gvk.GroupVersion().WithResource(resource), gvk.Kind, namespaced)
return &helmChartConfigController{
controllerManager: controllerManager,
clientGetter: clientGetter,
informer: informer,
gvk: gvk,
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
......@@ -132,12 +136,11 @@ func UpdateHelmChartConfigDeepCopyOnChange(client HelmChartConfigClient, obj *v1
}
func (c *helmChartConfigController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, handler)
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *helmChartConfigController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), handler)
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *helmChartConfigController) OnChange(ctx context.Context, name string, sync HelmChartConfigHandler) {
......@@ -145,20 +148,19 @@ func (c *helmChartConfigController) OnChange(ctx context.Context, name string, s
}
func (c *helmChartConfigController) OnRemove(ctx context.Context, name string, sync HelmChartConfigHandler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), FromHelmChartConfigHandlerToHandler(sync))
c.AddGenericHandler(ctx, name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromHelmChartConfigHandlerToHandler(sync)))
}
func (c *helmChartConfigController) Enqueue(namespace, name string) {
c.controllerManager.Enqueue(c.gvk, c.informer.Informer(), namespace, name)
c.controller.Enqueue(namespace, name)
}
func (c *helmChartConfigController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controllerManager.EnqueueAfter(c.gvk, c.informer.Informer(), namespace, name, duration)
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *helmChartConfigController) Informer() cache.SharedIndexInformer {
return c.informer.Informer()
return c.controller.Informer()
}
func (c *helmChartConfigController) GroupVersionKind() schema.GroupVersionKind {
......@@ -167,53 +169,70 @@ func (c *helmChartConfigController) GroupVersionKind() schema.GroupVersionKind {
func (c *helmChartConfigController) Cache() HelmChartConfigCache {
return &helmChartConfigCache{
lister: c.informer.Lister(),
indexer: c.informer.Informer().GetIndexer(),
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *helmChartConfigController) Create(obj *v1.HelmChartConfig) (*v1.HelmChartConfig, error) {
return c.clientGetter.HelmChartConfigs(obj.Namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
result := &v1.HelmChartConfig{}
return result, c.client.Create(context.TODO(), obj.Namespace, obj, result, metav1.CreateOptions{})
}
func (c *helmChartConfigController) Update(obj *v1.HelmChartConfig) (*v1.HelmChartConfig, error) {
return c.clientGetter.HelmChartConfigs(obj.Namespace).Update(context.TODO(), obj, metav1.UpdateOptions{})
result := &v1.HelmChartConfig{}
return result, c.client.Update(context.TODO(), obj.Namespace, obj, result, metav1.UpdateOptions{})
}
func (c *helmChartConfigController) Delete(namespace, name string, options *metav1.DeleteOptions) error {
if options == nil {
options = &metav1.DeleteOptions{}
}
return c.clientGetter.HelmChartConfigs(namespace).Delete(context.TODO(), name, *options)
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *helmChartConfigController) Get(namespace, name string, options metav1.GetOptions) (*v1.HelmChartConfig, error) {
return c.clientGetter.HelmChartConfigs(namespace).Get(context.TODO(), name, options)
result := &v1.HelmChartConfig{}
return result, c.client.Get(context.TODO(), namespace, name, result, options)
}
func (c *helmChartConfigController) List(namespace string, opts metav1.ListOptions) (*v1.HelmChartConfigList, error) {
return c.clientGetter.HelmChartConfigs(namespace).List(context.TODO(), opts)
result := &v1.HelmChartConfigList{}
return result, c.client.List(context.TODO(), namespace, result, opts)
}
func (c *helmChartConfigController) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
return c.clientGetter.HelmChartConfigs(namespace).Watch(context.TODO(), opts)
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *helmChartConfigController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.HelmChartConfig, err error) {
return c.clientGetter.HelmChartConfigs(namespace).Patch(context.TODO(), name, pt, data, metav1.PatchOptions{}, subresources...)
func (c *helmChartConfigController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (*v1.HelmChartConfig, error) {
result := &v1.HelmChartConfig{}
return result, c.client.Patch(context.TODO(), namespace, name, pt, data, result, metav1.PatchOptions{}, subresources...)
}
type helmChartConfigCache struct {
lister listers.HelmChartConfigLister
indexer cache.Indexer
indexer cache.Indexer
resource schema.GroupResource
}
func (c *helmChartConfigCache) Get(namespace, name string) (*v1.HelmChartConfig, error) {
return c.lister.HelmChartConfigs(namespace).Get(name)
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.HelmChartConfig), nil
}
func (c *helmChartConfigCache) List(namespace string, selector labels.Selector) ([]*v1.HelmChartConfig, error) {
return c.lister.HelmChartConfigs(namespace).List(selector)
func (c *helmChartConfigCache) List(namespace string, selector labels.Selector) (ret []*v1.HelmChartConfig, err error) {
err = cache.ListAllByNamespace(c.indexer, namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.HelmChartConfig))
})
return ret, err
}
func (c *helmChartConfigCache) AddIndexer(indexName string, indexer HelmChartConfigIndexer) {
......
......@@ -20,34 +20,33 @@ package v1
import (
v1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
clientset "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned/typed/helm.cattle.io/v1"
informers "github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/helm.cattle.io/v1"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/lasso/pkg/controller"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v1.AddToScheme)
}
type Interface interface {
HelmChart() HelmChartController
HelmChartConfig() HelmChartConfigController
}
func New(controllerManager *generic.ControllerManager, client clientset.HelmV1Interface,
informers informers.Interface) Interface {
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerManager: controllerManager,
client: client,
informers: informers,
controllerFactory: controllerFactory,
}
}
type version struct {
controllerManager *generic.ControllerManager
informers informers.Interface
client clientset.HelmV1Interface
controllerFactory controller.SharedControllerFactory
}
func (c *version) HelmChart() HelmChartController {
return NewHelmChartController(v1.SchemeGroupVersion.WithKind("HelmChart"), c.controllerManager, c.client, c.informers.HelmCharts())
return NewHelmChartController(schema.GroupVersionKind{Group: "helm.cattle.io", Version: "v1", Kind: "HelmChart"}, "helmcharts", true, c.controllerFactory)
}
func (c *version) HelmChartConfig() HelmChartConfigController {
return NewHelmChartConfigController(v1.SchemeGroupVersion.WithKind("HelmChartConfig"), c.controllerManager, c.client, c.informers.HelmChartConfigs())
return NewHelmChartConfigController(schema.GroupVersionKind{Group: "helm.cattle.io", Version: "v1", Kind: "HelmChartConfig"}, "helmchartconfigs", true, c.controllerFactory)
}
/*
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 externalversions
import (
reflect "reflect"
sync "sync"
time "time"
versioned "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned"
helmcattleio "github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/helm.cattle.io"
internalinterfaces "github.com/k3s-io/helm-controller/pkg/generated/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
Helm() helmcattleio.Interface
}
func (f *sharedInformerFactory) Helm() helmcattleio.Interface {
return helmcattleio.New(f, f.namespace, f.tweakListOptions)
}
/*
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 externalversions
import (
"fmt"
v1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/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=helm.cattle.io, Version=v1
case v1.SchemeGroupVersion.WithResource("helmcharts"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Helm().V1().HelmCharts().Informer()}, nil
case v1.SchemeGroupVersion.WithResource("helmchartconfigs"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Helm().V1().HelmChartConfigs().Informer()}, nil
}
return nil, fmt.Errorf("no informer found for %v", resource)
}
/*
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 helm
import (
v1 "github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/helm.cattle.io/v1"
internalinterfaces "github.com/k3s-io/helm-controller/pkg/generated/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)
}
/*
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 "time"
helmcattleiov1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
versioned "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned"
internalinterfaces "github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/internalinterfaces"
v1 "github.com/k3s-io/helm-controller/pkg/generated/listers/helm.cattle.io/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"
)
// HelmChartInformer provides access to a shared informer and lister for
// HelmCharts.
type HelmChartInformer interface {
Informer() cache.SharedIndexInformer
Lister() v1.HelmChartLister
}
type helmChartInformer struct {
factory internalinterfaces.SharedInformerFactory
tweakListOptions internalinterfaces.TweakListOptionsFunc
namespace string
}
// NewHelmChartInformer constructs a new informer for HelmChart 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 NewHelmChartInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredHelmChartInformer(client, namespace, resyncPeriod, indexers, nil)
}
// NewFilteredHelmChartInformer constructs a new informer for HelmChart 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 NewFilteredHelmChartInformer(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.HelmV1().HelmCharts(namespace).List(context.TODO(), options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.HelmV1().HelmCharts(namespace).Watch(context.TODO(), options)
},
},
&helmcattleiov1.HelmChart{},
resyncPeriod,
indexers,
)
}
func (f *helmChartInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewFilteredHelmChartInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
}
func (f *helmChartInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&helmcattleiov1.HelmChart{}, f.defaultInformer)
}
func (f *helmChartInformer) Lister() v1.HelmChartLister {
return v1.NewHelmChartLister(f.Informer().GetIndexer())
}
/*
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 "time"
helmcattleiov1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
versioned "github.com/k3s-io/helm-controller/pkg/generated/clientset/versioned"
internalinterfaces "github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/internalinterfaces"
v1 "github.com/k3s-io/helm-controller/pkg/generated/listers/helm.cattle.io/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"
)
// HelmChartConfigInformer provides access to a shared informer and lister for
// HelmChartConfigs.
type HelmChartConfigInformer interface {
Informer() cache.SharedIndexInformer
Lister() v1.HelmChartConfigLister
}
type helmChartConfigInformer struct {
factory internalinterfaces.SharedInformerFactory
tweakListOptions internalinterfaces.TweakListOptionsFunc
namespace string
}
// NewHelmChartConfigInformer constructs a new informer for HelmChartConfig 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 NewHelmChartConfigInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredHelmChartConfigInformer(client, namespace, resyncPeriod, indexers, nil)
}
// NewFilteredHelmChartConfigInformer constructs a new informer for HelmChartConfig 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 NewFilteredHelmChartConfigInformer(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.HelmV1().HelmChartConfigs(namespace).List(context.TODO(), options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.HelmV1().HelmChartConfigs(namespace).Watch(context.TODO(), options)
},
},
&helmcattleiov1.HelmChartConfig{},
resyncPeriod,
indexers,
)
}
func (f *helmChartConfigInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewFilteredHelmChartConfigInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
}
func (f *helmChartConfigInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&helmcattleiov1.HelmChartConfig{}, f.defaultInformer)
}
func (f *helmChartConfigInformer) Lister() v1.HelmChartConfigLister {
return v1.NewHelmChartConfigLister(f.Informer().GetIndexer())
}
/*
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 (
internalinterfaces "github.com/k3s-io/helm-controller/pkg/generated/informers/externalversions/internalinterfaces"
)
// Interface provides access to all the informers in this group version.
type Interface interface {
// HelmCharts returns a HelmChartInformer.
HelmCharts() HelmChartInformer
// HelmChartConfigs returns a HelmChartConfigInformer.
HelmChartConfigs() HelmChartConfigInformer
}
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}
}
// HelmCharts returns a HelmChartInformer.
func (v *version) HelmCharts() HelmChartInformer {
return &helmChartInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}
// HelmChartConfigs returns a HelmChartConfigInformer.
func (v *version) HelmChartConfigs() HelmChartConfigInformer {
return &helmChartConfigInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}
/*
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 internalinterfaces
import (
time "time"
versioned "github.com/k3s-io/helm-controller/pkg/generated/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)
/*
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
// HelmChartListerExpansion allows custom methods to be added to
// HelmChartLister.
type HelmChartListerExpansion interface{}
// HelmChartNamespaceListerExpansion allows custom methods to be added to
// HelmChartNamespaceLister.
type HelmChartNamespaceListerExpansion interface{}
// HelmChartConfigListerExpansion allows custom methods to be added to
// HelmChartConfigLister.
type HelmChartConfigListerExpansion interface{}
// HelmChartConfigNamespaceListerExpansion allows custom methods to be added to
// HelmChartConfigNamespaceLister.
type HelmChartConfigNamespaceListerExpansion interface{}
/*
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 (
v1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
// HelmChartLister helps list HelmCharts.
type HelmChartLister interface {
// List lists all HelmCharts in the indexer.
List(selector labels.Selector) (ret []*v1.HelmChart, err error)
// HelmCharts returns an object that can list and get HelmCharts.
HelmCharts(namespace string) HelmChartNamespaceLister
HelmChartListerExpansion
}
// helmChartLister implements the HelmChartLister interface.
type helmChartLister struct {
indexer cache.Indexer
}
// NewHelmChartLister returns a new HelmChartLister.
func NewHelmChartLister(indexer cache.Indexer) HelmChartLister {
return &helmChartLister{indexer: indexer}
}
// List lists all HelmCharts in the indexer.
func (s *helmChartLister) List(selector labels.Selector) (ret []*v1.HelmChart, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1.HelmChart))
})
return ret, err
}
// HelmCharts returns an object that can list and get HelmCharts.
func (s *helmChartLister) HelmCharts(namespace string) HelmChartNamespaceLister {
return helmChartNamespaceLister{indexer: s.indexer, namespace: namespace}
}
// HelmChartNamespaceLister helps list and get HelmCharts.
type HelmChartNamespaceLister interface {
// List lists all HelmCharts in the indexer for a given namespace.
List(selector labels.Selector) (ret []*v1.HelmChart, err error)
// Get retrieves the HelmChart from the indexer for a given namespace and name.
Get(name string) (*v1.HelmChart, error)
HelmChartNamespaceListerExpansion
}
// helmChartNamespaceLister implements the HelmChartNamespaceLister
// interface.
type helmChartNamespaceLister struct {
indexer cache.Indexer
namespace string
}
// List lists all HelmCharts in the indexer for a given namespace.
func (s helmChartNamespaceLister) List(selector labels.Selector) (ret []*v1.HelmChart, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.HelmChart))
})
return ret, err
}
// Get retrieves the HelmChart from the indexer for a given namespace and name.
func (s helmChartNamespaceLister) Get(name string) (*v1.HelmChart, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v1.Resource("helmchart"), name)
}
return obj.(*v1.HelmChart), nil
}
/*
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 (
v1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
)
// HelmChartConfigLister helps list HelmChartConfigs.
type HelmChartConfigLister interface {
// List lists all HelmChartConfigs in the indexer.
List(selector labels.Selector) (ret []*v1.HelmChartConfig, err error)
// HelmChartConfigs returns an object that can list and get HelmChartConfigs.
HelmChartConfigs(namespace string) HelmChartConfigNamespaceLister
HelmChartConfigListerExpansion
}
// helmChartConfigLister implements the HelmChartConfigLister interface.
type helmChartConfigLister struct {
indexer cache.Indexer
}
// NewHelmChartConfigLister returns a new HelmChartConfigLister.
func NewHelmChartConfigLister(indexer cache.Indexer) HelmChartConfigLister {
return &helmChartConfigLister{indexer: indexer}
}
// List lists all HelmChartConfigs in the indexer.
func (s *helmChartConfigLister) List(selector labels.Selector) (ret []*v1.HelmChartConfig, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1.HelmChartConfig))
})
return ret, err
}
// HelmChartConfigs returns an object that can list and get HelmChartConfigs.
func (s *helmChartConfigLister) HelmChartConfigs(namespace string) HelmChartConfigNamespaceLister {
return helmChartConfigNamespaceLister{indexer: s.indexer, namespace: namespace}
}
// HelmChartConfigNamespaceLister helps list and get HelmChartConfigs.
type HelmChartConfigNamespaceLister interface {
// List lists all HelmChartConfigs in the indexer for a given namespace.
List(selector labels.Selector) (ret []*v1.HelmChartConfig, err error)
// Get retrieves the HelmChartConfig from the indexer for a given namespace and name.
Get(name string) (*v1.HelmChartConfig, error)
HelmChartConfigNamespaceListerExpansion
}
// helmChartConfigNamespaceLister implements the HelmChartConfigNamespaceLister
// interface.
type helmChartConfigNamespaceLister struct {
indexer cache.Indexer
namespace string
}
// List lists all HelmChartConfigs in the indexer for a given namespace.
func (s helmChartConfigNamespaceLister) List(selector labels.Selector) (ret []*v1.HelmChartConfig, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1.HelmChartConfig))
})
return ret, err
}
// Get retrieves the HelmChartConfig from the indexer for a given namespace and name.
func (s helmChartConfigNamespaceLister) Get(name string) (*v1.HelmChartConfig, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v1.Resource("helmchartconfig"), name)
}
return obj.(*v1.HelmChartConfig), nil
}
......@@ -11,10 +11,10 @@ import (
helmv1 "github.com/k3s-io/helm-controller/pkg/apis/helm.cattle.io/v1"
helmcontroller "github.com/k3s-io/helm-controller/pkg/generated/controllers/helm.cattle.io/v1"
batchcontroller "github.com/rancher/wrangler-api/pkg/generated/controllers/batch/v1"
corecontroller "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
rbaccontroller "github.com/rancher/wrangler-api/pkg/generated/controllers/rbac/v1"
"github.com/rancher/wrangler/pkg/apply"
batchcontroller "github.com/rancher/wrangler/pkg/generated/controllers/batch/v1"
corecontroller "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
rbaccontroller "github.com/rancher/wrangler/pkg/generated/controllers/rbac/v1"
"github.com/rancher/wrangler/pkg/objectset"
"github.com/rancher/wrangler/pkg/relatedresource"
batch "k8s.io/api/batch/v1"
......
......@@ -26,7 +26,7 @@ const (
)
var (
cnRegexp = regexp.MustCompile("^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$")
cnRegexp = regexp.MustCompile("^([A-Za-z0-9:][-A-Za-z0-9_.:]*)?[A-Za-z0-9:]$")
)
type TLS struct {
......
module github.com/rancher/dynamiclistener
go 1.12
go 1.16
require (
github.com/rancher/wrangler v0.1.4
github.com/rancher/wrangler-api v0.2.0
github.com/sirupsen/logrus v1.4.1
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
github.com/rancher/wrangler v0.8.3
github.com/sirupsen/logrus v1.4.2
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
k8s.io/api v0.18.8
k8s.io/apimachinery v0.18.8
)
......@@ -5,7 +5,7 @@ import (
"crypto/x509"
"github.com/rancher/dynamiclistener/factory"
v1controller "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
v1controller "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
......
......@@ -6,8 +6,8 @@ import (
"time"
"github.com/rancher/dynamiclistener"
"github.com/rancher/wrangler-api/pkg/generated/controllers/core"
v1controller "github.com/rancher/wrangler-api/pkg/generated/controllers/core/v1"
"github.com/rancher/wrangler/pkg/generated/controllers/core"
v1controller "github.com/rancher/wrangler/pkg/generated/controllers/core/v1"
"github.com/rancher/wrangler/pkg/start"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
......
......@@ -77,6 +77,7 @@ type Apply interface {
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
......@@ -279,6 +280,10 @@ 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)
}
......
......@@ -36,6 +36,7 @@ type desiredSet struct {
informerFactory InformerFactory
remove bool
noDelete bool
noDeleteGVK map[schema.GroupVersionKind]struct{}
setID string
objs *objectset.ObjectSet
codeVersion string
......@@ -225,6 +226,16 @@ func (o desiredSet) WithNoDelete() Apply {
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
......
......@@ -177,6 +177,17 @@ func (o *desiredSet) runInjectors(objList []runtime.Object) ([]runtime.Object, e
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 {
......
......@@ -6,6 +6,7 @@ import (
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"
)
......@@ -51,9 +52,14 @@ func (o *desiredSet) get(nsed bool, namespace, name string, client dynamic.Names
return client.Get(o.ctx, name, v1.GetOptions{})
}
func (o *desiredSet) delete(nsed bool, namespace, name string, client dynamic.NamespaceableResourceInterface, force bool) error {
if o.noDelete && !force {
return nil
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,
......
......@@ -304,7 +304,7 @@ func (o *desiredSet) process(debugID string, set labels.Selector, gvk schema.Gro
}
deleteF := func(k objectset.ObjectKey, force bool) {
if err := o.delete(nsed, k.Namespace, k.Name, client, force); err != nil {
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
}
......
......@@ -19,28 +19,12 @@ limitations under the License.
package apps
import (
"context"
"time"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
informers "k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes"
scheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
)
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct {
synced bool
informerFactory informers.SharedInformerFactory
clientset clientset.Interface
controllerManager *generic.ControllerManager
threadiness map[schema.GroupVersionKind]int
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
......@@ -61,66 +45,23 @@ func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*
})
}
type FactoryOptions struct {
Namespace string
Resync time.Duration
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
if opts == nil {
opts = &FactoryOptions{}
}
cs, err := clientset.NewForConfig(config)
if err != nil {
return nil, err
}
resync := opts.Resync
if resync == 0 {
resync = 2 * time.Hour
}
if opts.Namespace == "" {
informerFactory := informers.NewSharedInformerFactory(cs, resync)
return NewFactory(cs, informerFactory), nil
}
informerFactory := informers.NewSharedInformerFactoryWithOptions(cs, resync, informers.WithNamespace(opts.Namespace))
return NewFactory(cs, informerFactory), nil
}
func NewFactory(clientset clientset.Interface, informerFactory informers.SharedInformerFactory) *Factory {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
threadiness: map[schema.GroupVersionKind]int{},
controllerManager: &generic.ControllerManager{},
clientset: clientset,
informerFactory: informerFactory,
}
}
func (c *Factory) Controllers() map[schema.GroupVersionKind]*generic.Controller {
return c.controllerManager.Controllers()
}
func (c *Factory) SetThreadiness(gvk schema.GroupVersionKind, threadiness int) {
c.threadiness[gvk] = threadiness
Factory: f,
}, err
}
func (c *Factory) Sync(ctx context.Context) error {
c.informerFactory.Start(ctx.Done())
c.informerFactory.WaitForCacheSync(ctx.Done())
return nil
}
func (c *Factory) Start(ctx context.Context, defaultThreadiness int) error {
if err := c.Sync(ctx); err != nil {
return err
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return c.controllerManager.Start(ctx, defaultThreadiness, c.threadiness)
return f
}
func (c *Factory) Apps() Interface {
return New(c.controllerManager, c.informerFactory.Apps(), c.clientset)
return New(c.ControllerFactory())
}
......@@ -19,10 +19,8 @@ limitations under the License.
package apps
import (
v1 "github.com/rancher/wrangler-api/pkg/generated/controllers/apps/v1"
"github.com/rancher/wrangler/pkg/generic"
informers "k8s.io/client-go/informers/apps"
clientset "k8s.io/client-go/kubernetes"
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/wrangler/pkg/generated/controllers/apps/v1"
)
type Interface interface {
......@@ -30,21 +28,16 @@ type Interface interface {
}
type group struct {
controllerManager *generic.ControllerManager
informers informers.Interface
client clientset.Interface
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerManager *generic.ControllerManager, informers informers.Interface,
client clientset.Interface) Interface {
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerManager: controllerManager,
informers: informers,
client: client,
controllerFactory: controllerFactory,
}
}
func (g *group) V1() v1.Interface {
return v1.New(g.controllerManager, g.client.AppsV1(), g.informers.V1())
return v1.New(g.controllerFactory)
}
......@@ -22,6 +22,8 @@ import (
"context"
"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"
......@@ -36,9 +38,6 @@ import (
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
informers "k8s.io/client-go/informers/apps/v1"
clientset "k8s.io/client-go/kubernetes/typed/apps/v1"
listers "k8s.io/client-go/listers/apps/v1"
"k8s.io/client-go/tools/cache"
)
......@@ -78,18 +77,22 @@ type DaemonSetCache interface {
type DaemonSetIndexer func(obj *v1.DaemonSet) ([]string, error)
type daemonSetController struct {
controllerManager *generic.ControllerManager
clientGetter clientset.DaemonSetsGetter
informer informers.DaemonSetInformer
gvk schema.GroupVersionKind
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewDaemonSetController(gvk schema.GroupVersionKind, controllerManager *generic.ControllerManager, clientGetter clientset.DaemonSetsGetter, informer informers.DaemonSetInformer) DaemonSetController {
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{
controllerManager: controllerManager,
clientGetter: clientGetter,
informer: informer,
gvk: gvk,
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
......@@ -136,12 +139,11 @@ func UpdateDaemonSetDeepCopyOnChange(client DaemonSetClient, obj *v1.DaemonSet,
}
func (c *daemonSetController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, handler)
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *daemonSetController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), handler)
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *daemonSetController) OnChange(ctx context.Context, name string, sync DaemonSetHandler) {
......@@ -149,20 +151,19 @@ func (c *daemonSetController) OnChange(ctx context.Context, name string, sync Da
}
func (c *daemonSetController) OnRemove(ctx context.Context, name string, sync DaemonSetHandler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), FromDaemonSetHandlerToHandler(sync))
c.AddGenericHandler(ctx, name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromDaemonSetHandlerToHandler(sync)))
}
func (c *daemonSetController) Enqueue(namespace, name string) {
c.controllerManager.Enqueue(c.gvk, c.informer.Informer(), namespace, name)
c.controller.Enqueue(namespace, name)
}
func (c *daemonSetController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controllerManager.EnqueueAfter(c.gvk, c.informer.Informer(), namespace, name, duration)
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *daemonSetController) Informer() cache.SharedIndexInformer {
return c.informer.Informer()
return c.controller.Informer()
}
func (c *daemonSetController) GroupVersionKind() schema.GroupVersionKind {
......@@ -171,57 +172,75 @@ func (c *daemonSetController) GroupVersionKind() schema.GroupVersionKind {
func (c *daemonSetController) Cache() DaemonSetCache {
return &daemonSetCache{
lister: c.informer.Lister(),
indexer: c.informer.Informer().GetIndexer(),
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *daemonSetController) Create(obj *v1.DaemonSet) (*v1.DaemonSet, error) {
return c.clientGetter.DaemonSets(obj.Namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
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) {
return c.clientGetter.DaemonSets(obj.Namespace).Update(context.TODO(), obj, metav1.UpdateOptions{})
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) {
return c.clientGetter.DaemonSets(obj.Namespace).UpdateStatus(context.TODO(), obj, metav1.UpdateOptions{})
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.clientGetter.DaemonSets(namespace).Delete(context.TODO(), name, *options)
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *daemonSetController) Get(namespace, name string, options metav1.GetOptions) (*v1.DaemonSet, error) {
return c.clientGetter.DaemonSets(namespace).Get(context.TODO(), name, options)
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) {
return c.clientGetter.DaemonSets(namespace).List(context.TODO(), opts)
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.clientGetter.DaemonSets(namespace).Watch(context.TODO(), opts)
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *daemonSetController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.DaemonSet, err error) {
return c.clientGetter.DaemonSets(namespace).Patch(context.TODO(), name, pt, data, metav1.PatchOptions{}, subresources...)
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 {
lister listers.DaemonSetLister
indexer cache.Indexer
indexer cache.Indexer
resource schema.GroupResource
}
func (c *daemonSetCache) Get(namespace, name string) (*v1.DaemonSet, error) {
return c.lister.DaemonSets(namespace).Get(name)
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) ([]*v1.DaemonSet, error) {
return c.lister.DaemonSets(namespace).List(selector)
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) {
......@@ -299,12 +318,20 @@ func (a *daemonSetStatusHandler) sync(key string, obj *v1.DaemonSet) (*v1.Daemon
}
}
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
obj, newErr = a.client.UpdateStatus(obj)
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
......@@ -333,6 +360,10 @@ func (a *daemonSetGeneratingHandler) Remove(key string, obj *v1.DaemonSet) (*v1.
}
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
......
......@@ -22,6 +22,8 @@ import (
"context"
"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"
......@@ -36,9 +38,6 @@ import (
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
informers "k8s.io/client-go/informers/apps/v1"
clientset "k8s.io/client-go/kubernetes/typed/apps/v1"
listers "k8s.io/client-go/listers/apps/v1"
"k8s.io/client-go/tools/cache"
)
......@@ -78,18 +77,22 @@ type DeploymentCache interface {
type DeploymentIndexer func(obj *v1.Deployment) ([]string, error)
type deploymentController struct {
controllerManager *generic.ControllerManager
clientGetter clientset.DeploymentsGetter
informer informers.DeploymentInformer
gvk schema.GroupVersionKind
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewDeploymentController(gvk schema.GroupVersionKind, controllerManager *generic.ControllerManager, clientGetter clientset.DeploymentsGetter, informer informers.DeploymentInformer) DeploymentController {
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{
controllerManager: controllerManager,
clientGetter: clientGetter,
informer: informer,
gvk: gvk,
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
......@@ -136,12 +139,11 @@ func UpdateDeploymentDeepCopyOnChange(client DeploymentClient, obj *v1.Deploymen
}
func (c *deploymentController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, handler)
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *deploymentController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), handler)
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *deploymentController) OnChange(ctx context.Context, name string, sync DeploymentHandler) {
......@@ -149,20 +151,19 @@ func (c *deploymentController) OnChange(ctx context.Context, name string, sync D
}
func (c *deploymentController) OnRemove(ctx context.Context, name string, sync DeploymentHandler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), FromDeploymentHandlerToHandler(sync))
c.AddGenericHandler(ctx, name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromDeploymentHandlerToHandler(sync)))
}
func (c *deploymentController) Enqueue(namespace, name string) {
c.controllerManager.Enqueue(c.gvk, c.informer.Informer(), namespace, name)
c.controller.Enqueue(namespace, name)
}
func (c *deploymentController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controllerManager.EnqueueAfter(c.gvk, c.informer.Informer(), namespace, name, duration)
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *deploymentController) Informer() cache.SharedIndexInformer {
return c.informer.Informer()
return c.controller.Informer()
}
func (c *deploymentController) GroupVersionKind() schema.GroupVersionKind {
......@@ -171,57 +172,75 @@ func (c *deploymentController) GroupVersionKind() schema.GroupVersionKind {
func (c *deploymentController) Cache() DeploymentCache {
return &deploymentCache{
lister: c.informer.Lister(),
indexer: c.informer.Informer().GetIndexer(),
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *deploymentController) Create(obj *v1.Deployment) (*v1.Deployment, error) {
return c.clientGetter.Deployments(obj.Namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
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) {
return c.clientGetter.Deployments(obj.Namespace).Update(context.TODO(), obj, metav1.UpdateOptions{})
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) {
return c.clientGetter.Deployments(obj.Namespace).UpdateStatus(context.TODO(), obj, metav1.UpdateOptions{})
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.clientGetter.Deployments(namespace).Delete(context.TODO(), name, *options)
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *deploymentController) Get(namespace, name string, options metav1.GetOptions) (*v1.Deployment, error) {
return c.clientGetter.Deployments(namespace).Get(context.TODO(), name, options)
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) {
return c.clientGetter.Deployments(namespace).List(context.TODO(), opts)
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.clientGetter.Deployments(namespace).Watch(context.TODO(), opts)
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *deploymentController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.Deployment, err error) {
return c.clientGetter.Deployments(namespace).Patch(context.TODO(), name, pt, data, metav1.PatchOptions{}, subresources...)
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 {
lister listers.DeploymentLister
indexer cache.Indexer
indexer cache.Indexer
resource schema.GroupResource
}
func (c *deploymentCache) Get(namespace, name string) (*v1.Deployment, error) {
return c.lister.Deployments(namespace).Get(name)
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) ([]*v1.Deployment, error) {
return c.lister.Deployments(namespace).List(selector)
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) {
......@@ -299,12 +318,20 @@ func (a *deploymentStatusHandler) sync(key string, obj *v1.Deployment) (*v1.Depl
}
}
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
obj, newErr = a.client.UpdateStatus(obj)
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
......@@ -333,6 +360,10 @@ func (a *deploymentGeneratingHandler) Remove(key string, obj *v1.Deployment) (*v
}
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
......
......@@ -19,39 +19,38 @@ limitations under the License.
package v1
import (
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/lasso/pkg/controller"
"github.com/rancher/wrangler/pkg/schemes"
v1 "k8s.io/api/apps/v1"
informers "k8s.io/client-go/informers/apps/v1"
clientset "k8s.io/client-go/kubernetes/typed/apps/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func init() {
schemes.Register(v1.AddToScheme)
}
type Interface interface {
DaemonSet() DaemonSetController
Deployment() DeploymentController
StatefulSet() StatefulSetController
}
func New(controllerManager *generic.ControllerManager, client clientset.AppsV1Interface,
informers informers.Interface) Interface {
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &version{
controllerManager: controllerManager,
client: client,
informers: informers,
controllerFactory: controllerFactory,
}
}
type version struct {
controllerManager *generic.ControllerManager
informers informers.Interface
client clientset.AppsV1Interface
controllerFactory controller.SharedControllerFactory
}
func (c *version) DaemonSet() DaemonSetController {
return NewDaemonSetController(v1.SchemeGroupVersion.WithKind("DaemonSet"), c.controllerManager, c.client, c.informers.DaemonSets())
return NewDaemonSetController(schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "DaemonSet"}, "daemonsets", true, c.controllerFactory)
}
func (c *version) Deployment() DeploymentController {
return NewDeploymentController(v1.SchemeGroupVersion.WithKind("Deployment"), c.controllerManager, c.client, c.informers.Deployments())
return NewDeploymentController(schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}, "deployments", true, c.controllerFactory)
}
func (c *version) StatefulSet() StatefulSetController {
return NewStatefulSetController(v1.SchemeGroupVersion.WithKind("StatefulSet"), c.controllerManager, c.client, c.informers.StatefulSets())
return NewStatefulSetController(schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"}, "statefulsets", true, c.controllerFactory)
}
......@@ -22,6 +22,8 @@ import (
"context"
"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"
......@@ -36,9 +38,6 @@ import (
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
informers "k8s.io/client-go/informers/apps/v1"
clientset "k8s.io/client-go/kubernetes/typed/apps/v1"
listers "k8s.io/client-go/listers/apps/v1"
"k8s.io/client-go/tools/cache"
)
......@@ -78,18 +77,22 @@ type StatefulSetCache interface {
type StatefulSetIndexer func(obj *v1.StatefulSet) ([]string, error)
type statefulSetController struct {
controllerManager *generic.ControllerManager
clientGetter clientset.StatefulSetsGetter
informer informers.StatefulSetInformer
gvk schema.GroupVersionKind
controller controller.SharedController
client *client.Client
gvk schema.GroupVersionKind
groupResource schema.GroupResource
}
func NewStatefulSetController(gvk schema.GroupVersionKind, controllerManager *generic.ControllerManager, clientGetter clientset.StatefulSetsGetter, informer informers.StatefulSetInformer) StatefulSetController {
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{
controllerManager: controllerManager,
clientGetter: clientGetter,
informer: informer,
gvk: gvk,
controller: c,
client: c.Client(),
gvk: gvk,
groupResource: schema.GroupResource{
Group: gvk.Group,
Resource: resource,
},
}
}
......@@ -136,12 +139,11 @@ func UpdateStatefulSetDeepCopyOnChange(client StatefulSetClient, obj *v1.Statefu
}
func (c *statefulSetController) AddGenericHandler(ctx context.Context, name string, handler generic.Handler) {
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, handler)
c.controller.RegisterHandler(ctx, name, controller.SharedControllerHandlerFunc(handler))
}
func (c *statefulSetController) AddGenericRemoveHandler(ctx context.Context, name string, handler generic.Handler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), handler)
c.controllerManager.AddHandler(ctx, c.gvk, c.informer.Informer(), name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), handler))
}
func (c *statefulSetController) OnChange(ctx context.Context, name string, sync StatefulSetHandler) {
......@@ -149,20 +151,19 @@ func (c *statefulSetController) OnChange(ctx context.Context, name string, sync
}
func (c *statefulSetController) OnRemove(ctx context.Context, name string, sync StatefulSetHandler) {
removeHandler := generic.NewRemoveHandler(name, c.Updater(), FromStatefulSetHandlerToHandler(sync))
c.AddGenericHandler(ctx, name, removeHandler)
c.AddGenericHandler(ctx, name, generic.NewRemoveHandler(name, c.Updater(), FromStatefulSetHandlerToHandler(sync)))
}
func (c *statefulSetController) Enqueue(namespace, name string) {
c.controllerManager.Enqueue(c.gvk, c.informer.Informer(), namespace, name)
c.controller.Enqueue(namespace, name)
}
func (c *statefulSetController) EnqueueAfter(namespace, name string, duration time.Duration) {
c.controllerManager.EnqueueAfter(c.gvk, c.informer.Informer(), namespace, name, duration)
c.controller.EnqueueAfter(namespace, name, duration)
}
func (c *statefulSetController) Informer() cache.SharedIndexInformer {
return c.informer.Informer()
return c.controller.Informer()
}
func (c *statefulSetController) GroupVersionKind() schema.GroupVersionKind {
......@@ -171,57 +172,75 @@ func (c *statefulSetController) GroupVersionKind() schema.GroupVersionKind {
func (c *statefulSetController) Cache() StatefulSetCache {
return &statefulSetCache{
lister: c.informer.Lister(),
indexer: c.informer.Informer().GetIndexer(),
indexer: c.Informer().GetIndexer(),
resource: c.groupResource,
}
}
func (c *statefulSetController) Create(obj *v1.StatefulSet) (*v1.StatefulSet, error) {
return c.clientGetter.StatefulSets(obj.Namespace).Create(context.TODO(), obj, metav1.CreateOptions{})
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) {
return c.clientGetter.StatefulSets(obj.Namespace).Update(context.TODO(), obj, metav1.UpdateOptions{})
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) {
return c.clientGetter.StatefulSets(obj.Namespace).UpdateStatus(context.TODO(), obj, metav1.UpdateOptions{})
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.clientGetter.StatefulSets(namespace).Delete(context.TODO(), name, *options)
return c.client.Delete(context.TODO(), namespace, name, *options)
}
func (c *statefulSetController) Get(namespace, name string, options metav1.GetOptions) (*v1.StatefulSet, error) {
return c.clientGetter.StatefulSets(namespace).Get(context.TODO(), name, options)
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) {
return c.clientGetter.StatefulSets(namespace).List(context.TODO(), opts)
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.clientGetter.StatefulSets(namespace).Watch(context.TODO(), opts)
return c.client.Watch(context.TODO(), namespace, opts)
}
func (c *statefulSetController) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.StatefulSet, err error) {
return c.clientGetter.StatefulSets(namespace).Patch(context.TODO(), name, pt, data, metav1.PatchOptions{}, subresources...)
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 {
lister listers.StatefulSetLister
indexer cache.Indexer
indexer cache.Indexer
resource schema.GroupResource
}
func (c *statefulSetCache) Get(namespace, name string) (*v1.StatefulSet, error) {
return c.lister.StatefulSets(namespace).Get(name)
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) ([]*v1.StatefulSet, error) {
return c.lister.StatefulSets(namespace).List(selector)
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) {
......@@ -299,12 +318,20 @@ func (a *statefulSetStatusHandler) sync(key string, obj *v1.StatefulSet) (*v1.St
}
}
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
obj, newErr = a.client.UpdateStatus(obj)
newObj, newErr := a.client.UpdateStatus(obj)
if err == nil {
err = newErr
}
if newErr == nil {
obj = newObj
}
}
return obj, err
}
......@@ -333,6 +360,10 @@ func (a *statefulSetGeneratingHandler) Remove(key string, obj *v1.StatefulSet) (
}
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
......
......@@ -19,28 +19,12 @@ limitations under the License.
package batch
import (
"context"
"time"
"github.com/rancher/wrangler/pkg/generic"
"github.com/rancher/wrangler/pkg/schemes"
"k8s.io/apimachinery/pkg/runtime/schema"
informers "k8s.io/client-go/informers"
clientset "k8s.io/client-go/kubernetes"
scheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
)
func init() {
scheme.AddToScheme(schemes.All)
}
type Factory struct {
synced bool
informerFactory informers.SharedInformerFactory
clientset clientset.Interface
controllerManager *generic.ControllerManager
threadiness map[schema.GroupVersionKind]int
*generic.Factory
}
func NewFactoryFromConfigOrDie(config *rest.Config) *Factory {
......@@ -61,66 +45,23 @@ func NewFactoryFromConfigWithNamespace(config *rest.Config, namespace string) (*
})
}
type FactoryOptions struct {
Namespace string
Resync time.Duration
}
type FactoryOptions = generic.FactoryOptions
func NewFactoryFromConfigWithOptions(config *rest.Config, opts *FactoryOptions) (*Factory, error) {
if opts == nil {
opts = &FactoryOptions{}
}
cs, err := clientset.NewForConfig(config)
if err != nil {
return nil, err
}
resync := opts.Resync
if resync == 0 {
resync = 2 * time.Hour
}
if opts.Namespace == "" {
informerFactory := informers.NewSharedInformerFactory(cs, resync)
return NewFactory(cs, informerFactory), nil
}
informerFactory := informers.NewSharedInformerFactoryWithOptions(cs, resync, informers.WithNamespace(opts.Namespace))
return NewFactory(cs, informerFactory), nil
}
func NewFactory(clientset clientset.Interface, informerFactory informers.SharedInformerFactory) *Factory {
f, err := generic.NewFactoryFromConfigWithOptions(config, opts)
return &Factory{
threadiness: map[schema.GroupVersionKind]int{},
controllerManager: &generic.ControllerManager{},
clientset: clientset,
informerFactory: informerFactory,
}
}
func (c *Factory) Controllers() map[schema.GroupVersionKind]*generic.Controller {
return c.controllerManager.Controllers()
}
func (c *Factory) SetThreadiness(gvk schema.GroupVersionKind, threadiness int) {
c.threadiness[gvk] = threadiness
Factory: f,
}, err
}
func (c *Factory) Sync(ctx context.Context) error {
c.informerFactory.Start(ctx.Done())
c.informerFactory.WaitForCacheSync(ctx.Done())
return nil
}
func (c *Factory) Start(ctx context.Context, defaultThreadiness int) error {
if err := c.Sync(ctx); err != nil {
return err
func NewFactoryFromConfigWithOptionsOrDie(config *rest.Config, opts *FactoryOptions) *Factory {
f, err := NewFactoryFromConfigWithOptions(config, opts)
if err != nil {
panic(err)
}
return c.controllerManager.Start(ctx, defaultThreadiness, c.threadiness)
return f
}
func (c *Factory) Batch() Interface {
return New(c.controllerManager, c.informerFactory.Batch(), c.clientset)
return New(c.ControllerFactory())
}
......@@ -19,10 +19,8 @@ limitations under the License.
package batch
import (
v1 "github.com/rancher/wrangler-api/pkg/generated/controllers/batch/v1"
"github.com/rancher/wrangler/pkg/generic"
informers "k8s.io/client-go/informers/batch"
clientset "k8s.io/client-go/kubernetes"
"github.com/rancher/lasso/pkg/controller"
v1 "github.com/rancher/wrangler/pkg/generated/controllers/batch/v1"
)
type Interface interface {
......@@ -30,21 +28,16 @@ type Interface interface {
}
type group struct {
controllerManager *generic.ControllerManager
informers informers.Interface
client clientset.Interface
controllerFactory controller.SharedControllerFactory
}
// New returns a new Interface.
func New(controllerManager *generic.ControllerManager, informers informers.Interface,
client clientset.Interface) Interface {
func New(controllerFactory controller.SharedControllerFactory) Interface {
return &group{
controllerManager: controllerManager,
informers: informers,
client: client,
controllerFactory: controllerFactory,
}
}
func (g *group) V1() v1.Interface {
return v1.New(g.controllerManager, g.client.BatchV1(), g.informers.V1())
return v1.New(g.controllerFactory)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment