Ensure the SharedInformerFactory closes eventually (#1585)

Otherwise it will continue to collect events in the background, consuming memory that can't be GC'd.
This commit is contained in:
Stephen Muth 2023-02-15 18:54:33 -05:00 committed by GitHub
parent f71e623b09
commit be4ce2e02d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,7 +17,6 @@ import (
v1 "k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/informers" "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
@ -200,7 +199,9 @@ func (e *kube) Wait(ctx context.Context, step *types.Step) (*types.State, error)
UpdateFunc: podUpdated, UpdateFunc: podUpdated,
}, },
) )
si.Start(wait.NeverStop) stop := make(chan struct{})
si.Start(stop)
defer close(stop)
// TODO Cancel on ctx.Done // TODO Cancel on ctx.Done
<-finished <-finished
@ -246,7 +247,9 @@ func (e *kube) Tail(ctx context.Context, step *types.Step) (io.ReadCloser, error
UpdateFunc: podUpdated, UpdateFunc: podUpdated,
}, },
) )
si.Start(wait.NeverStop) stop := make(chan struct{})
si.Start(stop)
defer close(stop)
<-up <-up
@ -323,7 +326,7 @@ func (e *kube) Destroy(_ context.Context, conf *types.Config) error {
} }
if err := e.client.CoreV1().Services(e.config.Namespace).Delete(noContext, svc.Name, deleteOpts); err != nil { if err := e.client.CoreV1().Services(e.config.Namespace).Delete(noContext, svc.Name, deleteOpts); err != nil {
if errors.IsNotFound(err) { if errors.IsNotFound(err) {
log.Trace().Err(err).Msgf("Unable to service pod %s", svc.Name) log.Trace().Err(err).Msgf("Unable to delete service %s", svc.Name)
} else { } else {
return err return err
} }