(cfg *config.WorkerNodeConfig)
| 231 | } |
| 232 | |
| 233 | func (w *WorkerNode) sendHeartbeatLoop(cfg *config.WorkerNodeConfig) { |
| 234 | pollContext, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| 235 | defer cancel() |
| 236 | |
| 237 | pollErr := wait.PollUntilContextCancel(pollContext, 2500*time.Millisecond, true, |
| 238 | func(ctx context.Context) (done bool, err error) { |
| 239 | workerStatistics, err := w.getWorkerStatistics() |
| 240 | if err != nil { |
| 241 | return false, err |
| 242 | } |
| 243 | |
| 244 | resp, err := w.cpApi.NodeHeartbeat(ctx, workerStatistics) |
| 245 | |
| 246 | // In case we don't manage to connect, we give up |
| 247 | if err != nil || resp == nil { |
| 248 | return false, err |
| 249 | } |
| 250 | |
| 251 | return resp.Success, nil |
| 252 | }, |
| 253 | ) |
| 254 | if pollErr != nil { |
| 255 | logrus.Warnf("Failed to send a heartbeat to the control plane : %s", pollErr) |
| 256 | logrus.Warnf("Trying to establish connection with some other control plane replica.") |
| 257 | cpApi, err := grpc_helpers.NewControlPlaneConnection(cfg.ControlPlaneAddress) |
| 258 | if err != nil { |
| 259 | logrus.Fatalf("Cannot establish connection with any of the specified control plane(s) (error : %s)", err.Error()) |
| 260 | } else { |
| 261 | w.cpApi = cpApi |
| 262 | logrus.Infof("Control plance changed successfully.") |
| 263 | } |
| 264 | } else { |
| 265 | logrus.Debug("Sent heartbeat to the control plane") |
| 266 | } |
| 267 | } |
no test coverage detected