Skip to content

Commit 459e5dc

Browse files
committed
Figured out the channel is closing. Adding restart.
1 parent 77684ca commit 459e5dc

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

cmd/root.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,14 @@ func run(cmd *cobra.Command, args []string) {
126126
nodeListeners[i] = m
127127
}
128128

129-
if err := client.NodeWatch(nodeListeners); err != nil {
130-
cobra.CheckErr(err.Error())
129+
// This should never exit.
130+
for restarts := 0; restarts < 5; restarts++ {
131+
if err := client.NodeWatch(nodeListeners); err != nil {
132+
cobra.CheckErr(err.Error())
133+
}
134+
135+
log.WithFields(log.Fields{
136+
"restarts": restarts,
137+
}).Warn("node watch exited, restarting")
131138
}
132139
}

internal/k8s/client.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ func (c *Client) NodeWatch(listeners []NodeListener) error {
7979

8080
eventChannel := nodeWatch.ResultChan()
8181

82-
for {
83-
event := <-eventChannel
82+
for event := range eventChannel {
8483

8584
// This will need to be revisited at a later date.
8685
// TODO: Fix error handling
@@ -92,13 +91,6 @@ func (c *Client) NodeWatch(listeners []NodeListener) error {
9291
continue
9392
}
9493

95-
if event.Object == nil {
96-
log.WithFields(log.Fields{
97-
"type": event.Type,
98-
}).Error("event with nil object, ignoring")
99-
continue
100-
}
101-
10294
node := event.Object.(*v1.Node)
10395
endpoint := NewEndpoint(node.Spec.ProviderID, node.Status.Addresses)
10496

@@ -131,5 +123,7 @@ func (c *Client) NodeWatch(listeners []NodeListener) error {
131123
}
132124
}
133125

126+
log.WithFields(log.Fields{}).Warn("watcher disconnected")
127+
134128
return nil
135129
}

0 commit comments

Comments
 (0)