mirror of
https://github.com/traefik/traefik.git
synced 2025-10-10 07:01:14 +02:00
Use k8s.ResourceEventHandler for Gateway API provider
This commit is contained in:
parent
c5ed376d5f
commit
c61fb89d3f
@ -10,6 +10,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
"github.com/traefik/traefik/v3/pkg/provider/kubernetes/k8s"
|
||||||
"github.com/traefik/traefik/v3/pkg/types"
|
"github.com/traefik/traefik/v3/pkg/types"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
discoveryv1 "k8s.io/api/discovery/v1"
|
discoveryv1 "k8s.io/api/discovery/v1"
|
||||||
@ -33,22 +34,6 @@ import (
|
|||||||
|
|
||||||
const resyncPeriod = 10 * time.Minute
|
const resyncPeriod = 10 * time.Minute
|
||||||
|
|
||||||
type resourceEventHandler struct {
|
|
||||||
ev chan<- interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reh *resourceEventHandler) OnAdd(obj interface{}, _ bool) {
|
|
||||||
eventHandlerFunc(reh.ev, obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reh *resourceEventHandler) OnUpdate(_, newObj interface{}) {
|
|
||||||
eventHandlerFunc(reh.ev, newObj)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (reh *resourceEventHandler) OnDelete(obj interface{}) {
|
|
||||||
eventHandlerFunc(reh.ev, obj)
|
|
||||||
}
|
|
||||||
|
|
||||||
type clientWrapper struct {
|
type clientWrapper struct {
|
||||||
csGateway gateclientset.Interface
|
csGateway gateclientset.Interface
|
||||||
csKube kclientset.Interface
|
csKube kclientset.Interface
|
||||||
@ -145,7 +130,7 @@ func newExternalClusterClient(endpoint, caFilePath string, token types.FileOrCon
|
|||||||
// WatchAll starts namespace-specific controllers for all relevant kinds.
|
// WatchAll starts namespace-specific controllers for all relevant kinds.
|
||||||
func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error) {
|
func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<-chan interface{}, error) {
|
||||||
eventCh := make(chan interface{}, 1)
|
eventCh := make(chan interface{}, 1)
|
||||||
eventHandler := &resourceEventHandler{ev: eventCh}
|
eventHandler := &k8s.ResourceEventHandler{Ev: eventCh}
|
||||||
|
|
||||||
if len(namespaces) == 0 {
|
if len(namespaces) == 0 {
|
||||||
namespaces = []string{metav1.NamespaceAll}
|
namespaces = []string{metav1.NamespaceAll}
|
||||||
@ -815,16 +800,6 @@ func (c *clientWrapper) isWatchedNamespace(namespace string) bool {
|
|||||||
return slices.Contains(c.watchedNamespaces, namespace)
|
return slices.Contains(c.watchedNamespaces, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
// eventHandlerFunc will pass the obj on to the events channel or drop it.
|
|
||||||
// This is so passing the events along won't block in the case of high volume.
|
|
||||||
// The events are only used for signaling anyway so dropping a few is ok.
|
|
||||||
func eventHandlerFunc(events chan<- interface{}, obj interface{}) {
|
|
||||||
select {
|
|
||||||
case events <- obj:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// translateNotFoundError will translate a "not found" error to a boolean return
|
// translateNotFoundError will translate a "not found" error to a boolean return
|
||||||
// value which indicates if the resource exists and a nil error.
|
// value which indicates if the resource exists and a nil error.
|
||||||
func translateNotFoundError(err error) (bool, error) {
|
func translateNotFoundError(err error) (bool, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user