Avoid panics when stopping a not-quite-started debug manager
@@ -48,6 +48,7 @@ func NewContainerManager(podSelector kubernetes.PodSelector) *ContainerManager {
podWatcher: kubernetes.NewPodWatcher(podSelector),
active: map[string]string{},
events: make(chan kubernetes.PodEvent),
+ stopWatcher: func() {},
}
}
@@ -65,6 +66,8 @@ func (d *ContainerManager) Start(ctx context.Context, namespaces []string) error
d.stopWatcher = stopWatcher
go func() {
+ defer stopWatcher()
+
for {
select {
case <-ctx.Done():
@@ -84,9 +87,10 @@ func (d *ContainerManager) Start(ctx context.Context, namespaces []string) error
func (d *ContainerManager) Stop() {
// if nil then debug mode probably not enabled
- if d != nil {
- d.stopWatcher()
+ if d == nil {
+ return
}
+ d.stopWatcher()
}
func (d *ContainerManager) Name() string {
