mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
update resource quota controller for shared informers
This commit is contained in:
parent
8c4e3af1a3
commit
60fe17d338
@ -263,7 +263,7 @@ func StartControllers(s *options.CMServer, kubeClient *client.Client, kubeconfig
|
|||||||
KubeClient: resourceQuotaControllerClient,
|
KubeClient: resourceQuotaControllerClient,
|
||||||
ResyncPeriod: controller.StaticResyncPeriodFunc(s.ResourceQuotaSyncPeriod.Duration),
|
ResyncPeriod: controller.StaticResyncPeriodFunc(s.ResourceQuotaSyncPeriod.Duration),
|
||||||
Registry: resourceQuotaRegistry,
|
Registry: resourceQuotaRegistry,
|
||||||
ControllerFactory: resourcequotacontroller.NewReplenishmentControllerFactory(resourceQuotaControllerClient),
|
ControllerFactory: resourcequotacontroller.NewReplenishmentControllerFactory(podInformer, resourceQuotaControllerClient),
|
||||||
ReplenishmentResyncPeriod: ResyncPeriod(s),
|
ReplenishmentResyncPeriod: ResyncPeriod(s),
|
||||||
GroupKindsToReplenish: groupKindsToReplenish,
|
GroupKindsToReplenish: groupKindsToReplenish,
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ func (s *CMServer) Run(_ []string) error {
|
|||||||
Registry: resourceQuotaRegistry,
|
Registry: resourceQuotaRegistry,
|
||||||
GroupKindsToReplenish: groupKindsToReplenish,
|
GroupKindsToReplenish: groupKindsToReplenish,
|
||||||
ReplenishmentResyncPeriod: s.resyncPeriod,
|
ReplenishmentResyncPeriod: s.resyncPeriod,
|
||||||
ControllerFactory: resourcequotacontroller.NewReplenishmentControllerFactory(resourceQuotaControllerClient),
|
ControllerFactory: resourcequotacontroller.NewReplenishmentControllerFactoryFromClient(resourceQuotaControllerClient),
|
||||||
}
|
}
|
||||||
go resourcequotacontroller.NewResourceQuotaController(resourceQuotaControllerOptions).Run(s.ConcurrentResourceQuotaSyncs, wait.NeverStop)
|
go resourcequotacontroller.NewResourceQuotaController(resourceQuotaControllerOptions).Run(s.ConcurrentResourceQuotaSyncs, wait.NeverStop)
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
"k8s.io/kubernetes/pkg/controller"
|
||||||
"k8s.io/kubernetes/pkg/controller/framework"
|
"k8s.io/kubernetes/pkg/controller/framework"
|
||||||
|
"k8s.io/kubernetes/pkg/controller/framework/informers"
|
||||||
"k8s.io/kubernetes/pkg/quota/evaluator/core"
|
"k8s.io/kubernetes/pkg/quota/evaluator/core"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
utilruntime "k8s.io/kubernetes/pkg/util/runtime"
|
utilruntime "k8s.io/kubernetes/pkg/util/runtime"
|
||||||
@ -86,43 +87,46 @@ func ObjectReplenishmentDeleteFunc(options *ReplenishmentControllerOptions) func
|
|||||||
|
|
||||||
// ReplenishmentControllerFactory knows how to build replenishment controllers
|
// ReplenishmentControllerFactory knows how to build replenishment controllers
|
||||||
type ReplenishmentControllerFactory interface {
|
type ReplenishmentControllerFactory interface {
|
||||||
// NewController returns a controller configured with the specified options
|
// NewController returns a controller configured with the specified options.
|
||||||
NewController(options *ReplenishmentControllerOptions) (*framework.Controller, error)
|
// This method is NOT thread-safe.
|
||||||
|
NewController(options *ReplenishmentControllerOptions) (framework.ControllerInterface, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// replenishmentControllerFactory implements ReplenishmentControllerFactory
|
// replenishmentControllerFactory implements ReplenishmentControllerFactory
|
||||||
type replenishmentControllerFactory struct {
|
type replenishmentControllerFactory struct {
|
||||||
kubeClient clientset.Interface
|
kubeClient clientset.Interface
|
||||||
|
podInformer framework.SharedInformer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewReplenishmentControllerFactory returns a factory that knows how to build controllers
|
// NewReplenishmentControllerFactory returns a factory that knows how to build controllers
|
||||||
// to replenish resources when updated or deleted
|
// to replenish resources when updated or deleted
|
||||||
func NewReplenishmentControllerFactory(kubeClient clientset.Interface) ReplenishmentControllerFactory {
|
func NewReplenishmentControllerFactory(podInformer framework.SharedInformer, kubeClient clientset.Interface) ReplenishmentControllerFactory {
|
||||||
return &replenishmentControllerFactory{
|
return &replenishmentControllerFactory{
|
||||||
kubeClient: kubeClient,
|
kubeClient: kubeClient,
|
||||||
|
podInformer: podInformer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *replenishmentControllerFactory) NewController(options *ReplenishmentControllerOptions) (*framework.Controller, error) {
|
func NewReplenishmentControllerFactoryFromClient(kubeClient clientset.Interface) ReplenishmentControllerFactory {
|
||||||
var result *framework.Controller
|
return NewReplenishmentControllerFactory(nil, kubeClient)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *replenishmentControllerFactory) NewController(options *ReplenishmentControllerOptions) (framework.ControllerInterface, error) {
|
||||||
|
var result framework.ControllerInterface
|
||||||
switch options.GroupKind {
|
switch options.GroupKind {
|
||||||
case api.Kind("Pod"):
|
case api.Kind("Pod"):
|
||||||
_, result = framework.NewInformer(
|
if r.podInformer != nil {
|
||||||
&cache.ListWatch{
|
r.podInformer.AddEventHandler(framework.ResourceEventHandlerFuncs{
|
||||||
ListFunc: func(options api.ListOptions) (runtime.Object, error) {
|
|
||||||
return r.kubeClient.Core().Pods(api.NamespaceAll).List(options)
|
|
||||||
},
|
|
||||||
WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
|
|
||||||
return r.kubeClient.Core().Pods(api.NamespaceAll).Watch(options)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
&api.Pod{},
|
|
||||||
options.ResyncPeriod(),
|
|
||||||
framework.ResourceEventHandlerFuncs{
|
|
||||||
UpdateFunc: PodReplenishmentUpdateFunc(options),
|
UpdateFunc: PodReplenishmentUpdateFunc(options),
|
||||||
DeleteFunc: ObjectReplenishmentDeleteFunc(options),
|
DeleteFunc: ObjectReplenishmentDeleteFunc(options),
|
||||||
},
|
})
|
||||||
)
|
result = r.podInformer.GetController()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
r.podInformer = informers.CreateSharedPodInformer(r.kubeClient, options.ResyncPeriod())
|
||||||
|
result = r.podInformer
|
||||||
|
|
||||||
case api.Kind("Service"):
|
case api.Kind("Service"):
|
||||||
_, result = framework.NewInformer(
|
_, result = framework.NewInformer(
|
||||||
&cache.ListWatch{
|
&cache.ListWatch{
|
||||||
|
@ -69,7 +69,7 @@ type ResourceQuotaController struct {
|
|||||||
// knows how to calculate usage
|
// knows how to calculate usage
|
||||||
registry quota.Registry
|
registry quota.Registry
|
||||||
// controllers monitoring to notify for replenishment
|
// controllers monitoring to notify for replenishment
|
||||||
replenishmentControllers []*framework.Controller
|
replenishmentControllers []framework.ControllerInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewResourceQuotaController(options *ResourceQuotaControllerOptions) *ResourceQuotaController {
|
func NewResourceQuotaController(options *ResourceQuotaControllerOptions) *ResourceQuotaController {
|
||||||
@ -79,7 +79,7 @@ func NewResourceQuotaController(options *ResourceQuotaControllerOptions) *Resour
|
|||||||
queue: workqueue.New(),
|
queue: workqueue.New(),
|
||||||
resyncPeriod: options.ResyncPeriod,
|
resyncPeriod: options.ResyncPeriod,
|
||||||
registry: options.Registry,
|
registry: options.Registry,
|
||||||
replenishmentControllers: []*framework.Controller{},
|
replenishmentControllers: []framework.ControllerInterface{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the synchronization handler
|
// set the synchronization handler
|
||||||
|
@ -113,7 +113,7 @@ func TestSyncResourceQuota(t *testing.T) {
|
|||||||
api.Kind("ReplicationController"),
|
api.Kind("ReplicationController"),
|
||||||
api.Kind("PersistentVolumeClaim"),
|
api.Kind("PersistentVolumeClaim"),
|
||||||
},
|
},
|
||||||
ControllerFactory: NewReplenishmentControllerFactory(kubeClient),
|
ControllerFactory: NewReplenishmentControllerFactoryFromClient(kubeClient),
|
||||||
ReplenishmentResyncPeriod: controller.NoResyncPeriodFunc,
|
ReplenishmentResyncPeriod: controller.NoResyncPeriodFunc,
|
||||||
}
|
}
|
||||||
quotaController := NewResourceQuotaController(resourceQuotaControllerOptions)
|
quotaController := NewResourceQuotaController(resourceQuotaControllerOptions)
|
||||||
@ -199,7 +199,7 @@ func TestSyncResourceQuotaSpecChange(t *testing.T) {
|
|||||||
api.Kind("ReplicationController"),
|
api.Kind("ReplicationController"),
|
||||||
api.Kind("PersistentVolumeClaim"),
|
api.Kind("PersistentVolumeClaim"),
|
||||||
},
|
},
|
||||||
ControllerFactory: NewReplenishmentControllerFactory(kubeClient),
|
ControllerFactory: NewReplenishmentControllerFactoryFromClient(kubeClient),
|
||||||
ReplenishmentResyncPeriod: controller.NoResyncPeriodFunc,
|
ReplenishmentResyncPeriod: controller.NoResyncPeriodFunc,
|
||||||
}
|
}
|
||||||
quotaController := NewResourceQuotaController(resourceQuotaControllerOptions)
|
quotaController := NewResourceQuotaController(resourceQuotaControllerOptions)
|
||||||
@ -276,7 +276,7 @@ func TestSyncResourceQuotaNoChange(t *testing.T) {
|
|||||||
api.Kind("ReplicationController"),
|
api.Kind("ReplicationController"),
|
||||||
api.Kind("PersistentVolumeClaim"),
|
api.Kind("PersistentVolumeClaim"),
|
||||||
},
|
},
|
||||||
ControllerFactory: NewReplenishmentControllerFactory(kubeClient),
|
ControllerFactory: NewReplenishmentControllerFactoryFromClient(kubeClient),
|
||||||
ReplenishmentResyncPeriod: controller.NoResyncPeriodFunc,
|
ReplenishmentResyncPeriod: controller.NoResyncPeriodFunc,
|
||||||
}
|
}
|
||||||
quotaController := NewResourceQuotaController(resourceQuotaControllerOptions)
|
quotaController := NewResourceQuotaController(resourceQuotaControllerOptions)
|
||||||
|
Loading…
Reference in New Issue
Block a user