chore(codebase): remove pointer to an interface (#5625)

* chore(codebase): remove pointer to an interface

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

* chore(codebase): simplify logic

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>

---------

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
This commit is contained in:
Ivan Ka 2025-07-09 08:43:35 +01:00 committed by GitHub
parent 1eccb64bcb
commit 5d8d424bcb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 12 deletions

View File

@ -51,7 +51,7 @@ type crdSource struct {
codec runtime.ParameterCodec
annotationFilter string
labelSelector labels.Selector
informer *cache.SharedInformer
informer cache.SharedInformer
}
func addKnownTypes(scheme *runtime.Scheme, groupVersion schema.GroupVersion) error {
@ -123,7 +123,7 @@ func NewCRDSource(crdClient rest.Interface, namespace, kind string, annotationFi
if startInformer {
// external-dns already runs its sync-handler periodically (controlled by `--interval` flag) to ensure any
// missed or dropped events are handled. specify resync period 0 to avoid unnecessary sync handler invocations.
informer := cache.NewSharedInformer(
sourceCrd.informer = cache.NewSharedInformer(
&cache.ListWatch{
ListWithContextFunc: func(ctx context.Context, lo metav1.ListOptions) (runtime.Object, error) {
return sourceCrd.List(ctx, &lo)
@ -134,8 +134,7 @@ func NewCRDSource(crdClient rest.Interface, namespace, kind string, annotationFi
},
&apiv1alpha1.DNSEndpoint{},
0)
sourceCrd.informer = &informer
go informer.Run(wait.NeverStop)
go sourceCrd.informer.Run(wait.NeverStop)
}
return &sourceCrd, nil
}
@ -145,8 +144,7 @@ func (cs *crdSource) AddEventHandler(_ context.Context, handler func()) {
log.Debug("Adding event handler for CRD")
// Right now there is no way to remove event handler from informer, see:
// https://github.com/kubernetes/kubernetes/issues/79610
informer := *cs.informer
_, _ = informer.AddEventHandler(
_, _ = cs.informer.AddEventHandler(
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
handler()
@ -190,11 +188,9 @@ func (cs *crdSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
illegalTarget := false
for _, target := range ep.Targets {
if ep.RecordType != endpoint.RecordTypeNAPTR && strings.HasSuffix(target, ".") {
illegalTarget = true
break
}
if ep.RecordType == endpoint.RecordTypeNAPTR && !strings.HasSuffix(target, ".") {
isNAPTR := ep.RecordType == endpoint.RecordTypeNAPTR
hasDot := strings.HasSuffix(target, ".")
if (isNAPTR && !hasDot) || (!isNAPTR && hasDot) {
illegalTarget = true
break
}

View File

@ -736,7 +736,7 @@ func helperCreateWatcherWithInformer(t *testing.T) (*cachetesting.FakeController
}, time.Second, 10*time.Millisecond)
cs := &crdSource{
informer: &informer,
informer: informer,
}
return watcher, *cs