Merge pull request #72554 from misterikkit/cachecompare

Move CacheDebugger signal handling into the package.
pull/564/head
Kubernetes Prow Robot 2019-01-04 16:20:42 -08:00 committed by GitHub
commit dd53c82d7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 20 deletions

View File

@ -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"],

View File

@ -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 {
}, },
) )
// 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

View File

@ -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__"],

View File

@ -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(
}, },
} }
} }
// 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()
}
}
}()
}

View File

@ -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"

View File

@ -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"