MCPcopy Create free account
hub / github.com/flant/shell-operator / doShutdown

Method doShutdown

pkg/shell-operator/operator.go:260–337  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

258}
259
260func (op *ShellOperator) doShutdown(ctx context.Context) error {
261 if _, ok := ctx.Deadline(); !ok {
262 var cancel context.CancelFunc
263 ctx, cancel = context.WithTimeout(ctx, DefaultShutdownTimeout)
264 defer cancel()
265 }
266
267 op.logger.Info("shutdown begin", slog.String(pkg.LogKeyPhase, "shutdown"))
268
269 // Cancel the operator-scoped context first. This signals every
270 // ctx-aware goroutine (event handler loop, queue workers, schedule
271 // helper) to start unwinding.
272 if op.cancel != nil {
273 op.cancel()
274 }
275
276 var errs []error
277
278 if op.ScheduleManager != nil {
279 op.ScheduleManager.Stop()
280 op.logger.Info("schedule manager stopped", slog.String(pkg.LogKeyPhase, "shutdown"))
281 }
282
283 if op.ManagerEventsHandler != nil {
284 op.ManagerEventsHandler.Stop()
285 if err := op.ManagerEventsHandler.Wait(ctx); err != nil {
286 errs = append(errs, fmt.Errorf("manager events handler: %w", err))
287 }
288 op.logger.Info("manager events handler stopped", slog.String(pkg.LogKeyPhase, "shutdown"))
289 }
290
291 if op.KubeEventsManager != nil {
292 op.KubeEventsManager.Stop()
293 op.logger.Info("waiting informers", slog.String(pkg.LogKeyPhase, "shutdown"))
294 op.KubeEventsManager.Wait()
295 op.logger.Info("informers stopped", slog.String(pkg.LogKeyPhase, "shutdown"))
296 }
297
298 if op.TaskQueues != nil {
299 if err := op.TaskQueues.Shutdown(ctx); err != nil {
300 errs = append(errs, fmt.Errorf("task queues: %w", err))
301 } else {
302 op.logger.Info("task queues stopped", slog.String(pkg.LogKeyPhase, "shutdown"))
303 }
304 }
305
306 if op.AdmissionWebhookManager != nil {
307 if err := op.AdmissionWebhookManager.Shutdown(ctx); err != nil {
308 errs = append(errs, fmt.Errorf("admission webhook: %w", err))
309 }
310 }
311
312 if op.ConversionWebhookManager != nil {
313 if err := op.ConversionWebhookManager.Shutdown(ctx); err != nil {
314 errs = append(errs, fmt.Errorf("conversion webhook: %w", err))
315 }
316 }
317

Callers 1

ShutdownMethod · 0.95

Calls 5

waitWGFunction · 0.85
StopMethod · 0.65
WaitMethod · 0.65
ShutdownMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected