Skip to content

Commit

Permalink
Remove loop var
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Mar 26, 2024
1 parent 728816f commit 650607f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions pkg/compute/management_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ManagementClientParams struct {
// it will periodically send an update to the requester node with
// the latest node info for this node.
type ManagementClient struct {
closeChannel chan struct{}
done chan struct{}
labelsProvider models.LabelsProvider
managementProxy ManagementEndpoint
nodeID string
Expand All @@ -47,7 +47,7 @@ type ManagementClient struct {

func NewManagementClient(params *ManagementClientParams) *ManagementClient {
return &ManagementClient{
closeChannel: make(chan struct{}, 1),
done: make(chan struct{}, 1),
labelsProvider: params.LabelsProvider,
managementProxy: params.ManagementProxy,
nodeID: params.NodeID,
Expand Down Expand Up @@ -148,15 +148,20 @@ func (m *ManagementClient) Start(ctx context.Context) {
// frequency we are at risk of the node's liveness flapping between good and bad.
heartbeatTicker := time.NewTicker((heartbeatFrequencySeconds / 2) * time.Second)

defer func() {
heartbeatTicker.Stop()
resourceTicker.Stop()
infoTicker.Stop()
}()

var heartbeatSequence uint64 = 0

loop := true
for loop {
for {
select {
case <-ctx.Done():
loop = false
case <-m.closeChannel:
loop = false
return
case <-m.done:
return
case <-infoTicker.C:
// Send the latest node info to the requester node
m.deliverInfo(ctx)
Expand All @@ -169,14 +174,10 @@ func (m *ManagementClient) Start(ctx context.Context) {
m.heartbeat(ctx, heartbeatSequence)
}
}

heartbeatTicker.Stop()
resourceTicker.Stop()
infoTicker.Stop()
}

func (m *ManagementClient) Stop() {
if m.closeChannel != nil {
m.closeChannel <- struct{}{}
if m.done != nil {
m.done <- struct{}{}
}
}

0 comments on commit 650607f

Please sign in to comment.