Skip to content

Commit

Permalink
pinger: fix process not terminated on sigkill (#4329)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian authored Jul 23, 2024
1 parent 05984fc commit af95247
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/ovn_ic_controller/ovn_ic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ovn_ic_controller

import (
"k8s.io/klog/v2"
"k8s.io/sample-controller/pkg/signals"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

"github.com/kubeovn/kube-ovn/pkg/ovn_ic_controller"
"github.com/kubeovn/kube-ovn/pkg/util"
Expand Down
7 changes: 4 additions & 3 deletions cmd/pinger/pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
_ "net/http/pprof" // #nosec

"k8s.io/klog/v2"
"k8s.io/sample-controller/pkg/signals"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

"github.com/kubeovn/kube-ovn/pkg/metrics"
"github.com/kubeovn/kube-ovn/pkg/pinger"
Expand All @@ -20,12 +20,13 @@ func CmdMain() {
if err != nil {
util.LogFatalAndExit(err, "failed to parse config")
}

ctx := signals.SetupSignalHandler()
if config.Mode == "server" {
if config.EnableMetrics {
go func() {
pinger.InitPingerMetrics()
metrics.InitKlogMetrics()
ctx := signals.SetupSignalHandler()
if err := metrics.Run(ctx, nil, util.JoinHostPort("0.0.0.0", config.Port), false); err != nil {
util.LogFatalAndExit(err, "failed to run metrics server")
}
Expand All @@ -45,5 +46,5 @@ func CmdMain() {
}
}
}
pinger.StartPinger(config)
pinger.StartPinger(config, ctx.Done())
}
2 changes: 1 addition & 1 deletion cmd/speaker/speaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/prometheus/client_golang/prometheus/promhttp"
"k8s.io/klog/v2"
"k8s.io/sample-controller/pkg/signals"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"

"github.com/kubeovn/kube-ovn/pkg/speaker"
"github.com/kubeovn/kube-ovn/pkg/util"
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ require (
k8s.io/kubectl v0.30.3
k8s.io/kubernetes v1.30.3
k8s.io/pod-security-admission v0.30.3
k8s.io/sample-controller v0.30.3
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
kubevirt.io/api v1.3.0
kubevirt.io/client-go v1.3.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2323,8 +2323,6 @@ k8s.io/pod-security-admission v0.30.3 h1:UDGZWR3ry/XrN/Ki/w7qrp49OwgQsKyh+6xWbex
k8s.io/pod-security-admission v0.30.3/go.mod h1:T1EQSOLl9YyDMnXNJfsq2jeci6uoymY0mrRkkKihd98=
k8s.io/sample-apiserver v0.30.3 h1:SGlc1FvY+5CGolD0Qn1iGuhbhBWMUru/kcjQ9ki2iEs=
k8s.io/sample-apiserver v0.30.3/go.mod h1:P4g1Jw2lq2wtCiibqVX3KIRAfXtHpw6pOD/dzwmVG/w=
k8s.io/sample-controller v0.30.3 h1:oZTxERF8U3gANT2H5VxpkW32asgmW0IYGyUv9Opspvs=
k8s.io/sample-controller v0.30.3/go.mod h1:yhy/cWCzevQLa2+7Gvj0J9+xzmNExypunffSNANBy7o=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
Expand Down
15 changes: 13 additions & 2 deletions pkg/pinger/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ import (
"github.com/kubeovn/kube-ovn/pkg/util"
)

func StartPinger(config *Configuration) {
func StartPinger(config *Configuration, stopCh <-chan struct{}) {
errHappens := false
var exporter *Exporter
withMetrics := config.Mode == "server" && config.EnableMetrics
internval := time.Duration(config.Interval) * time.Second
timer := time.NewTimer(internval)
timer.Stop()
LOOP:
for {
if config.NetworkMode == "kube-ovn" {
if checkOvs(config, withMetrics) != nil {
Expand All @@ -49,8 +53,15 @@ func StartPinger(config *Configuration) {
if config.Mode != "server" {
break
}
time.Sleep(time.Duration(config.Interval) * time.Second)

timer.Reset(internval)
select {
case <-stopCh:
break LOOP
case <-timer.C:
}
}
timer.Stop()
if errHappens && config.ExitCode != 0 {
os.Exit(config.ExitCode)
}
Expand Down

0 comments on commit af95247

Please sign in to comment.