From bb12c193e53b3c11051bbf32f66bf6401d5758bc Mon Sep 17 00:00:00 2001 From: Scott Phillips Date: Mon, 1 Apr 2024 14:32:55 -0400 Subject: [PATCH 1/2] fix: Listen for pod deletion (cherry picked from commit 9c2a96fa634c38b43bf587deffca6005f8563e94) --- pkg/fwdport/fwdport.go | 14 ++++++++++++-- pkg/fwdsvcregistry/fwdsvcregistry.go | 5 ++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pkg/fwdport/fwdport.go b/pkg/fwdport/fwdport.go index 70b2e8af..c93e3087 100644 --- a/pkg/fwdport/fwdport.go +++ b/pkg/fwdport/fwdport.go @@ -184,7 +184,7 @@ func (pfo *PortForwardOpts) PortForward() error { // Listen for pod is deleted // @TODO need a test for this, does not seem to work as intended - // go pfo.ListenUntilPodDeleted(downstreamStopChannel, pod) + go pfo.ListenUntilPodDeleted(downstreamStopChannel, pod) p := pfo.Out.MakeProducer(localNamedEndPoint) @@ -455,10 +455,20 @@ func (pfo *PortForwardOpts) ListenUntilPodDeleted(stopChannel <-chan struct{}, p break } switch event.Type { + case watch.Modified: + log.Warnf("Pod %s modified, service %s pod new status %v", pod.ObjectMeta.Name, pfo.ServiceFwd, pod) + if (event.Object.(*v1.Pod)).DeletionTimestamp != nil { + log.Warnf("Pod %s marked for deletion, resyncing the %s service pods.", pod.ObjectMeta.Name, pfo.ServiceFwd) + pfo.Stop() + pfo.ServiceFwd.SyncPodForwards(false) + } + //return case watch.Deleted: log.Warnf("Pod %s deleted, resyncing the %s service pods.", pod.ObjectMeta.Name, pfo.ServiceFwd) + // TODO - Disconnect / reconnect on the provided port + log.Warnf("Pod %s deleted, resyncing the %s service pods.", pod.ObjectMeta.Name, pfo.ServiceFwd) + pfo.Stop() pfo.ServiceFwd.SyncPodForwards(false) - return } } } diff --git a/pkg/fwdsvcregistry/fwdsvcregistry.go b/pkg/fwdsvcregistry/fwdsvcregistry.go index ebee98f4..f5eed3a3 100644 --- a/pkg/fwdsvcregistry/fwdsvcregistry.go +++ b/pkg/fwdsvcregistry/fwdsvcregistry.go @@ -1,11 +1,10 @@ package fwdsvcregistry import ( - "sync" - log "github.com/sirupsen/logrus" "github.com/txn2/kubefwd/pkg/fwdservice" _ "k8s.io/client-go/plugin/pkg/client/auth" + "sync" ) // ServicesRegistry is a structure to hold all of the kubernetes @@ -77,7 +76,7 @@ func Add(serviceFwd *fwdservice.ServiceFWD) { //go func() { // for { // select { - // case <-time.After(10 * time.Minute): + // case <-time.After(10 * time.Second): // serviceFwd.SyncPodForwards(false) // case <-serviceFwd.DoneChannel: // return From fade62050e8458ab8a158eed115e17da1321a8bc Mon Sep 17 00:00:00 2001 From: Scott Phillips Date: Tue, 9 Apr 2024 11:21:34 -0400 Subject: [PATCH 2/2] fix: Remove random formatting issues --- pkg/fwdsvcregistry/fwdsvcregistry.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/fwdsvcregistry/fwdsvcregistry.go b/pkg/fwdsvcregistry/fwdsvcregistry.go index f5eed3a3..ebee98f4 100644 --- a/pkg/fwdsvcregistry/fwdsvcregistry.go +++ b/pkg/fwdsvcregistry/fwdsvcregistry.go @@ -1,10 +1,11 @@ package fwdsvcregistry import ( + "sync" + log "github.com/sirupsen/logrus" "github.com/txn2/kubefwd/pkg/fwdservice" _ "k8s.io/client-go/plugin/pkg/client/auth" - "sync" ) // ServicesRegistry is a structure to hold all of the kubernetes @@ -76,7 +77,7 @@ func Add(serviceFwd *fwdservice.ServiceFWD) { //go func() { // for { // select { - // case <-time.After(10 * time.Second): + // case <-time.After(10 * time.Minute): // serviceFwd.SyncPodForwards(false) // case <-serviceFwd.DoneChannel: // return