Skip to content

Commit

Permalink
chore(operator/inventory): cancel inventory context when using port f… (
Browse files Browse the repository at this point in the history
#196)

chore(operator/inventory): cancel inventory context when using port forwarding

Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian authored Feb 16, 2024
1 parent ba69d67 commit a9888ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cluster/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ func (is *inventoryService) run(ctx context.Context, reservationsArg []*reservat
t.Stop()
runch = is.runCheck(rctx, state)
}
} else if reserveChLocal == nil {
} else if reserveChLocal == nil && state.inventory != nil {
reserveChLocal = is.reservech
}
}
Expand Down
11 changes: 11 additions & 0 deletions cluster/kube/operators/clients/inventory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ func (cl *client) subscriber(in <-chan inventoryV1.Cluster, out chan<- ctypes.In
}

func newInventoryConnector(ctx context.Context, svc *corev1.Service, invch chan<- inventoryState) (<-chan struct{}, error) {
ctx, cancel := context.WithCancel(ctx)
group, ctx := errgroup.WithContext(ctx)

var svcPort int32
Expand Down Expand Up @@ -320,6 +321,7 @@ func newInventoryConnector(ctx context.Context, svc *corev1.Service, invch chan<

group.Go(func() error {
err := pf.ForwardPorts()
cancel()
errch <- err
return err
})
Expand Down Expand Up @@ -353,6 +355,7 @@ func newInventoryConnector(ctx context.Context, svc *corev1.Service, invch chan<

group.Go(func() error {
<-ctx.Done()
cancel()

sigdone <- struct{}{}

Expand All @@ -373,6 +376,14 @@ func inventoryRun(ctx context.Context, endpoint string, invch chan<- inventorySt

defer func() {
_ = conn.Close()

select {
case invch <- inventoryState{
evt: inventoryEventDeleted,
}:
default:
}

}()

log.Info(fmt.Sprintf("dialing inventory operator at %s", endpoint))
Expand Down

0 comments on commit a9888ba

Please sign in to comment.