Skip to content

Commit

Permalink
pkg/k8s: do not enable k8s heartbeat if timeout is set to 0
Browse files Browse the repository at this point in the history
Signed-off-by: André Martins <andre@cilium.io>
  • Loading branch information
aanm committed Mar 24, 2020
1 parent 683ebb3 commit d03d08e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
7 changes: 5 additions & 2 deletions pkg/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,14 @@ func CreateConfig() (*rest.Config, error) {
}

func setDialer(config *rest.Config) func() {
context := (&net.Dialer{
if option.Config.K8sHeartbeatTimeout == 0 {
return func() {}
}
ctx := (&net.Dialer{
Timeout: option.Config.K8sHeartbeatTimeout,
KeepAlive: option.Config.K8sHeartbeatTimeout,
}).DialContext
dialer := connrotation.NewDialer(context)
dialer := connrotation.NewDialer(ctx)
config.Dial = dialer.DialContext
return dialer.CloseAll
}
Expand Down
28 changes: 15 additions & 13 deletions pkg/k8s/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,22 @@ func Init() error {
return res.Error()
}

controller.NewManager().UpdateController("k8s-heartbeat",
controller.ControllerParams{
DoFunc: func(context.Context) error {
runHeartbeat(
heartBeat,
option.Config.K8sHeartbeatTimeout,
closeAllDefaultClientConns,
closeAllCiliumClientConns,
)
return nil
if option.Config.K8sHeartbeatTimeout != 0 {
controller.NewManager().UpdateController("k8s-heartbeat",
controller.ControllerParams{
DoFunc: func(context.Context) error {
runHeartbeat(
heartBeat,
option.Config.K8sHeartbeatTimeout,
closeAllDefaultClientConns,
closeAllCiliumClientConns,
)
return nil
},
RunInterval: option.Config.K8sHeartbeatTimeout,
},
RunInterval: option.Config.K8sHeartbeatTimeout,
},
)
)
}

if err := k8sversion.Update(Client()); err != nil {
return err
Expand Down

0 comments on commit d03d08e

Please sign in to comment.