mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 12:15:52 +00:00
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.
This commit is contained in:
parent
18778ea4a1
commit
95254d5457
@ -5,8 +5,6 @@ go_library(
|
||||
srcs = [
|
||||
"factory.go",
|
||||
"plugins.go",
|
||||
"signal.go",
|
||||
"signal_windows.go",
|
||||
],
|
||||
importpath = "k8s.io/kubernetes/pkg/scheduler/factory",
|
||||
visibility = ["//visibility:public"],
|
||||
|
@ -20,8 +20,6 @@ package factory
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
@ -385,28 +383,18 @@ func NewConfigFactory(args *ConfigFactoryArgs) Configurator {
|
||||
},
|
||||
)
|
||||
|
||||
// Setup cache comparer
|
||||
// Setup cache debugger
|
||||
debugger := cachedebugger.New(
|
||||
args.NodeInformer.Lister(),
|
||||
args.PodInformer.Lister(),
|
||||
c.schedulerCache,
|
||||
c.podQueue,
|
||||
)
|
||||
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, compareSignal)
|
||||
debugger.ListenForSignal(c.StopEverything)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-c.StopEverything:
|
||||
c.podQueue.Close()
|
||||
return
|
||||
case <-ch:
|
||||
debugger.Comparer.Compare()
|
||||
debugger.Dumper.DumpAll()
|
||||
}
|
||||
}
|
||||
<-c.StopEverything
|
||||
c.podQueue.Close()
|
||||
}()
|
||||
|
||||
return c
|
||||
|
2
pkg/scheduler/internal/cache/debugger/BUILD
vendored
2
pkg/scheduler/internal/cache/debugger/BUILD
vendored
@ -6,6 +6,8 @@ go_library(
|
||||
"comparer.go",
|
||||
"debugger.go",
|
||||
"dumper.go",
|
||||
"signal.go",
|
||||
"signal_windows.go",
|
||||
],
|
||||
importpath = "k8s.io/kubernetes/pkg/scheduler/internal/cache/debugger",
|
||||
visibility = ["//pkg/scheduler:__subpackages__"],
|
||||
|
@ -17,6 +17,9 @@ limitations under the License.
|
||||
package debugger
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
corelisters "k8s.io/client-go/listers/core/v1"
|
||||
internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
||||
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()
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package factory
|
||||
package debugger
|
||||
|
||||
import "syscall"
|
||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package factory
|
||||
package debugger
|
||||
|
||||
import "os"
|
||||
|
Loading…
Reference in New Issue
Block a user