Commit 95254d54 authored by Jonathan Basseri's avatar Jonathan Basseri

Move CacheDebugger signal handling into the package.

This moves the signal handling for CacheDebugger from the factory package into the CacheDebugger's package. That makes it easier to reuse from packages other than factory.
parent 18778ea4
...@@ -5,8 +5,6 @@ go_library( ...@@ -5,8 +5,6 @@ go_library(
srcs = [ srcs = [
"factory.go", "factory.go",
"plugins.go", "plugins.go",
"signal.go",
"signal_windows.go",
], ],
importpath = "k8s.io/kubernetes/pkg/scheduler/factory", importpath = "k8s.io/kubernetes/pkg/scheduler/factory",
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
......
...@@ -20,8 +20,6 @@ package factory ...@@ -20,8 +20,6 @@ package factory
import ( import (
"fmt" "fmt"
"os"
"os/signal"
"reflect" "reflect"
"time" "time"
...@@ -385,28 +383,18 @@ func NewConfigFactory(args *ConfigFactoryArgs) Configurator { ...@@ -385,28 +383,18 @@ func NewConfigFactory(args *ConfigFactoryArgs) Configurator {
}, },
) )
// Setup cache comparer // Setup cache debugger
debugger := cachedebugger.New( debugger := cachedebugger.New(
args.NodeInformer.Lister(), args.NodeInformer.Lister(),
args.PodInformer.Lister(), args.PodInformer.Lister(),
c.schedulerCache, c.schedulerCache,
c.podQueue, c.podQueue,
) )
debugger.ListenForSignal(c.StopEverything)
ch := make(chan os.Signal, 1)
signal.Notify(ch, compareSignal)
go func() { go func() {
for { <-c.StopEverything
select { c.podQueue.Close()
case <-c.StopEverything:
c.podQueue.Close()
return
case <-ch:
debugger.Comparer.Compare()
debugger.Dumper.DumpAll()
}
}
}() }()
return c return c
......
...@@ -6,6 +6,8 @@ go_library( ...@@ -6,6 +6,8 @@ go_library(
"comparer.go", "comparer.go",
"debugger.go", "debugger.go",
"dumper.go", "dumper.go",
"signal.go",
"signal_windows.go",
], ],
importpath = "k8s.io/kubernetes/pkg/scheduler/internal/cache/debugger", importpath = "k8s.io/kubernetes/pkg/scheduler/internal/cache/debugger",
visibility = ["//pkg/scheduler:__subpackages__"], visibility = ["//pkg/scheduler:__subpackages__"],
......
...@@ -17,6 +17,9 @@ limitations under the License. ...@@ -17,6 +17,9 @@ limitations under the License.
package debugger package debugger
import ( import (
"os"
"os/signal"
corelisters "k8s.io/client-go/listers/core/v1" corelisters "k8s.io/client-go/listers/core/v1"
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache" internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue" internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
...@@ -48,3 +51,22 @@ func New( ...@@ -48,3 +51,22 @@ func New(
}, },
} }
} }
// ListenForSignal starts a goroutine that will trigger the CacheDebugger's
// behavior when the process receives SIGINT (Windows) or SIGUSER2 (non-Windows).
func (d *CacheDebugger) ListenForSignal(stopCh <-chan struct{}) {
ch := make(chan os.Signal, 1)
signal.Notify(ch, compareSignal)
go func() {
for {
select {
case <-stopCh:
return
case <-ch:
d.Comparer.Compare()
d.Dumper.DumpAll()
}
}
}()
}
...@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and ...@@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package factory package debugger
import "syscall" import "syscall"
......
...@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and ...@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package factory package debugger
import "os" import "os"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment