Skip to content

Commit

Permalink
Merge pull request #273 from trinsic-id/feat/autoreconnect
Browse files Browse the repository at this point in the history
fix: Listen for pod deletion and properly reconnect
  • Loading branch information
cjimti authored Oct 22, 2024
2 parents be56db9 + fade620 commit b353431
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/fwdport/fwdport.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,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)

Expand Down Expand Up @@ -456,10 +456,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
}
}
}
Expand Down

0 comments on commit b353431

Please sign in to comment.