Browse code

daemon/cluster/executor/container: make switches exhaustive (exhaustive)

Adding a `default` statement so that disabling the "default-signifies-exhaustive"
linter option will make it show up.

daemon/cluster/executor/container/adapter.go:351:3: missing cases in switch of type api.Mount_MountType: api.MountTypeVolume, api.MountTypeTmpfs, api.MountTypeNamedPipe, api.MountTypeCluster (exhaustive)
switch mount.Type {
^
daemon/cluster/executor/container/adapter.go:540:4: missing cases in switch of type api.LogStream: api.LogStreamUnknown (exhaustive)
switch stream {
^
daemon/cluster/executor/container/container.go:715:3: missing cases in switch of type api.Privileges_SeccompOpts_SeccompMode: api.Privileges_SeccompOpts_DEFAULT (exhaustive)
switch seccomp.Mode {
^
daemon/cluster/executor/container/controller.go:257:4: missing cases in switch of type events.Action: events.ActionCreate, events.ActionStart, events.ActionRestart, events.ActionStop, events.ActionCheckpoint, events.ActionPause, events.ActionUnPause, events.ActionAttach, events.ActionDetach, events.ActionResize, events.ActionUpdate, events.ActionRename, events.ActionKill, events.ActionOOM, events.ActionRemove, events.ActionCommit, events.ActionTop, events.ActionCopy, events.ActionArchivePath, events.ActionExtractToDir, events.ActionExport, events.ActionImport, events.ActionSave, events.ActionLoad, events.ActionTag, events.ActionUnTag, events.ActionPush, events.ActionPull, events.ActionPrune, events.ActionDelete, events.ActionEnable, events.ActionDisable, events.ActionConnect, events.ActionDisconnect, events.ActionReload, events.ActionMount, events.ActionUnmount, events.ActionExecCreate, events.ActionExecStart, events.ActionExecDie, events.ActionExecDetach, events.ActionHealthStatus, events.ActionHealthStatusRunning (exhaustive)
switch event.Action {
^
daemon/cluster/executor/container/controller.go:480:4: missing cases in switch of type events.Action: events.ActionCreate, events.ActionStart, events.ActionRestart, events.ActionStop, events.ActionCheckpoint, events.ActionPause, events.ActionUnPause, events.ActionAttach, events.ActionDetach, events.ActionResize, events.ActionUpdate, events.ActionRename, events.ActionKill, events.ActionDie, events.ActionOOM, events.ActionDestroy, events.ActionRemove, events.ActionCommit, events.ActionTop, events.ActionCopy, events.ActionArchivePath, events.ActionExtractToDir, events.ActionExport, events.ActionImport, events.ActionSave, events.ActionLoad, events.ActionTag, events.ActionUnTag, events.ActionPush, events.ActionPull, events.ActionPrune, events.ActionDelete, events.ActionEnable, events.ActionDisable, events.ActionConnect, events.ActionDisconnect, events.ActionReload, events.ActionMount, events.ActionUnmount, events.ActionExecCreate, events.ActionExecStart, events.ActionExecDie, events.ActionExecDetach, events.ActionHealthStatus, events.ActionHealthStatusRunning, events.ActionHealthStatusHealthy, events.ActionHealthStatusUnhealthy (exhaustive)
switch event.Action {
^
daemon/cluster/executor/container/controller.go:723:4: missing cases in switch of type events.Action: events.ActionCreate, events.ActionStart, events.ActionRestart, events.ActionStop, events.ActionCheckpoint, events.ActionPause, events.ActionUnPause, events.ActionAttach, events.ActionDetach, events.ActionResize, events.ActionUpdate, events.ActionRename, events.ActionKill, events.ActionDie, events.ActionOOM, events.ActionDestroy, events.ActionRemove, events.ActionCommit, events.ActionTop, events.ActionCopy, events.ActionArchivePath, events.ActionExtractToDir, events.ActionExport, events.ActionImport, events.ActionSave, events.ActionLoad, events.ActionTag, events.ActionUnTag, events.ActionPush, events.ActionPull, events.ActionPrune, events.ActionDelete, events.ActionEnable, events.ActionDisable, events.ActionConnect, events.ActionDisconnect, events.ActionReload, events.ActionMount, events.ActionUnmount, events.ActionExecCreate, events.ActionExecStart, events.ActionExecDie, events.ActionExecDetach, events.ActionHealthStatus, events.ActionHealthStatusRunning, events.ActionHealthStatusHealthy (exhaustive)
switch event.Action {
^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/02/09 01:21:50
Showing 3 changed files
... ...
@@ -353,6 +353,8 @@ func (c *containerAdapter) checkMounts() error {
353 353
 			if _, err := os.Stat(mount.Source); os.IsNotExist(err) {
354 354
 				return fmt.Errorf("invalid bind mount source, source path not found: %s", mount.Source)
355 355
 			}
356
+		default:
357
+			// TODO(thaJeztah): make switch exhaustive; add api.MountTypeVolume, api.MountTypeTmpfs, api.MountTypeNamedPipe, api.MountTypeCluster
356 358
 		}
357 359
 	}
358 360
 
... ...
@@ -542,6 +544,8 @@ func (c *containerAdapter) logs(ctx context.Context, options api.LogSubscription
542 542
 				apiOptions.ShowStdout = true
543 543
 			case api.LogStreamStderr:
544 544
 				apiOptions.ShowStderr = true
545
+			default:
546
+				// TODO(thaJeztah): make switch exhaustive; add api.LogStreamUnknown
545 547
 			}
546 548
 		}
547 549
 	}
... ...
@@ -722,6 +722,8 @@ func (c *containerConfig) applyPrivileges(hc *containertypes.HostConfig) {
722 722
 			// Profile is bytes, but those bytes are actually a string. This is
723 723
 			// basically verbatim what happens in the cli after a file is read.
724 724
 			hc.SecurityOpt = append(hc.SecurityOpt, fmt.Sprintf("seccomp=%s", seccomp.Profile))
725
+		default:
726
+			// TODO(thaJeztah): make switch exhaustive; add api.Privileges_SeccompOpts_DEFAULT
725 727
 		}
726 728
 	}
727 729
 
... ...
@@ -281,6 +281,8 @@ func (r *controller) Start(ctx context.Context) error {
281 281
 					return err
282 282
 				}
283 283
 				return nil
284
+			default:
285
+				// TODO(thaJeztah): make switch exhaustive
284 286
 			}
285 287
 		case <-ctx.Done():
286 288
 			return ctx.Err()
... ...
@@ -467,6 +469,8 @@ func (r *controller) waitReady(pctx context.Context) error {
467 467
 		switch ctnr.State.Status {
468 468
 		case "running", "exited", "dead":
469 469
 			return nil
470
+		default:
471
+			// TODO(thaJeztah): make switch exhaustive
470 472
 		}
471 473
 	}
472 474
 
... ...
@@ -480,6 +484,8 @@ func (r *controller) waitReady(pctx context.Context) error {
480 480
 			switch event.Action {
481 481
 			case "start":
482 482
 				return nil
483
+			default:
484
+				// TODO(thaJeztah): make switch exhaustive
483 485
 			}
484 486
 		case <-ctx.Done():
485 487
 			return ctx.Err()
... ...
@@ -719,9 +725,7 @@ func (r *controller) checkHealth(ctx context.Context) error {
719 719
 			if !r.matchevent(event) {
720 720
 				continue
721 721
 			}
722
-
723
-			switch event.Action {
724
-			case events.ActionHealthStatusUnhealthy:
722
+			if event.Action == events.ActionHealthStatusUnhealthy {
725 723
 				return ErrContainerUnhealthy
726 724
 			}
727 725
 		}