mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #77582 from mrkm4ntr/clean-proxy-config
Clean up code in proxy/config
This commit is contained in:
commit
4d7e9052ea
@ -18,7 +18,6 @@ go_library(
|
|||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",
|
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
|
|
||||||
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
|
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
],
|
],
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
coreinformers "k8s.io/client-go/informers/core/v1"
|
coreinformers "k8s.io/client-go/informers/core/v1"
|
||||||
listers "k8s.io/client-go/listers/core/v1"
|
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
"k8s.io/kubernetes/pkg/controller"
|
"k8s.io/kubernetes/pkg/controller"
|
||||||
@ -64,9 +63,7 @@ type EndpointsHandler interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// EndpointsConfig tracks a set of endpoints configurations.
|
// EndpointsConfig tracks a set of endpoints configurations.
|
||||||
// It accepts "set", "add" and "remove" operations of endpoints via channels, and invokes registered handlers on change.
|
|
||||||
type EndpointsConfig struct {
|
type EndpointsConfig struct {
|
||||||
lister listers.EndpointsLister
|
|
||||||
listerSynced cache.InformerSynced
|
listerSynced cache.InformerSynced
|
||||||
eventHandlers []EndpointsHandler
|
eventHandlers []EndpointsHandler
|
||||||
}
|
}
|
||||||
@ -74,7 +71,6 @@ type EndpointsConfig struct {
|
|||||||
// NewEndpointsConfig creates a new EndpointsConfig.
|
// NewEndpointsConfig creates a new EndpointsConfig.
|
||||||
func NewEndpointsConfig(endpointsInformer coreinformers.EndpointsInformer, resyncPeriod time.Duration) *EndpointsConfig {
|
func NewEndpointsConfig(endpointsInformer coreinformers.EndpointsInformer, resyncPeriod time.Duration) *EndpointsConfig {
|
||||||
result := &EndpointsConfig{
|
result := &EndpointsConfig{
|
||||||
lister: endpointsInformer.Lister(),
|
|
||||||
listerSynced: endpointsInformer.Informer().HasSynced,
|
listerSynced: endpointsInformer.Informer().HasSynced,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,12 +91,9 @@ func (c *EndpointsConfig) RegisterEventHandler(handler EndpointsHandler) {
|
|||||||
c.eventHandlers = append(c.eventHandlers, handler)
|
c.eventHandlers = append(c.eventHandlers, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the goroutine responsible for calling registered handlers.
|
// Run waits for cache synced and invokes handlers after syncing.
|
||||||
func (c *EndpointsConfig) Run(stopCh <-chan struct{}) {
|
func (c *EndpointsConfig) Run(stopCh <-chan struct{}) {
|
||||||
defer utilruntime.HandleCrash()
|
|
||||||
|
|
||||||
klog.Info("Starting endpoints config controller")
|
klog.Info("Starting endpoints config controller")
|
||||||
defer klog.Info("Shutting down endpoints config controller")
|
|
||||||
|
|
||||||
if !controller.WaitForCacheSync("endpoints config", stopCh, c.listerSynced) {
|
if !controller.WaitForCacheSync("endpoints config", stopCh, c.listerSynced) {
|
||||||
return
|
return
|
||||||
@ -110,8 +103,6 @@ func (c *EndpointsConfig) Run(stopCh <-chan struct{}) {
|
|||||||
klog.V(3).Infof("Calling handler.OnEndpointsSynced()")
|
klog.V(3).Infof("Calling handler.OnEndpointsSynced()")
|
||||||
c.eventHandlers[i].OnEndpointsSynced()
|
c.eventHandlers[i].OnEndpointsSynced()
|
||||||
}
|
}
|
||||||
|
|
||||||
<-stopCh
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *EndpointsConfig) handleAddEndpoints(obj interface{}) {
|
func (c *EndpointsConfig) handleAddEndpoints(obj interface{}) {
|
||||||
@ -163,9 +154,7 @@ func (c *EndpointsConfig) handleDeleteEndpoints(obj interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ServiceConfig tracks a set of service configurations.
|
// ServiceConfig tracks a set of service configurations.
|
||||||
// It accepts "set", "add" and "remove" operations of services via channels, and invokes registered handlers on change.
|
|
||||||
type ServiceConfig struct {
|
type ServiceConfig struct {
|
||||||
lister listers.ServiceLister
|
|
||||||
listerSynced cache.InformerSynced
|
listerSynced cache.InformerSynced
|
||||||
eventHandlers []ServiceHandler
|
eventHandlers []ServiceHandler
|
||||||
}
|
}
|
||||||
@ -173,7 +162,6 @@ type ServiceConfig struct {
|
|||||||
// NewServiceConfig creates a new ServiceConfig.
|
// NewServiceConfig creates a new ServiceConfig.
|
||||||
func NewServiceConfig(serviceInformer coreinformers.ServiceInformer, resyncPeriod time.Duration) *ServiceConfig {
|
func NewServiceConfig(serviceInformer coreinformers.ServiceInformer, resyncPeriod time.Duration) *ServiceConfig {
|
||||||
result := &ServiceConfig{
|
result := &ServiceConfig{
|
||||||
lister: serviceInformer.Lister(),
|
|
||||||
listerSynced: serviceInformer.Informer().HasSynced,
|
listerSynced: serviceInformer.Informer().HasSynced,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,13 +182,9 @@ func (c *ServiceConfig) RegisterEventHandler(handler ServiceHandler) {
|
|||||||
c.eventHandlers = append(c.eventHandlers, handler)
|
c.eventHandlers = append(c.eventHandlers, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the goroutine responsible for calling
|
// Run waits for cache synced and invokes handlers after syncing.
|
||||||
// registered handlers.
|
|
||||||
func (c *ServiceConfig) Run(stopCh <-chan struct{}) {
|
func (c *ServiceConfig) Run(stopCh <-chan struct{}) {
|
||||||
defer utilruntime.HandleCrash()
|
|
||||||
|
|
||||||
klog.Info("Starting service config controller")
|
klog.Info("Starting service config controller")
|
||||||
defer klog.Info("Shutting down service config controller")
|
|
||||||
|
|
||||||
if !controller.WaitForCacheSync("service config", stopCh, c.listerSynced) {
|
if !controller.WaitForCacheSync("service config", stopCh, c.listerSynced) {
|
||||||
return
|
return
|
||||||
@ -210,8 +194,6 @@ func (c *ServiceConfig) Run(stopCh <-chan struct{}) {
|
|||||||
klog.V(3).Info("Calling handler.OnServiceSynced()")
|
klog.V(3).Info("Calling handler.OnServiceSynced()")
|
||||||
c.eventHandlers[i].OnServiceSynced()
|
c.eventHandlers[i].OnServiceSynced()
|
||||||
}
|
}
|
||||||
|
|
||||||
<-stopCh
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ServiceConfig) handleAddService(obj interface{}) {
|
func (c *ServiceConfig) handleAddService(obj interface{}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user