Skip to content

Commit

Permalink
launcher-monitor: Remove dependency on wait
Browse files Browse the repository at this point in the history
Signed-off-by: L. Pivarc <[email protected]>
  • Loading branch information
xpivarc committed Feb 22, 2023
1 parent 53a3fce commit 7f16fb9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
1 change: 0 additions & 1 deletion cmd/virt-launcher-monitor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ go_library(
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/net:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
"//vendor/k8s.io/client-go/util/retry:go_default_library",
],
)
Expand Down
30 changes: 21 additions & 9 deletions cmd/virt-launcher-monitor/virt-launcher-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"k8s.io/apimachinery/pkg/util/net"

"github.com/spf13/pflag"
utilwait "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"

"kubevirt.io/client-go/log"
Expand Down Expand Up @@ -166,15 +165,28 @@ func RunAndMonitor(containerDiskDir string) (int, error) {
}

// Wait for 10 seconds for the qemu process to disappear
err = utilwait.PollImmediate(1*time.Second, 10*time.Second, func() (bool, error) {
pid, _ := findPid(qemuProcessCommandPrefix)
if pid == 0 {
return true, nil
timeout := time.After(10 * time.Second)
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
period := make(chan struct{}, 1)

go func() {
period <- struct{}{}
for range ticker.C {
period <- struct{}{}
}
}()

for {
select {
case <-timeout:
return 1, err
case <-period:
pid, _ := findPid(qemuProcessCommandPrefix)
if pid == 0 {
return exitCode, nil
}
}
return false, nil
})
if err != nil {
return 1, err
}
}
return exitCode, nil
Expand Down
1 change: 0 additions & 1 deletion staging/src/kubevirt.io/client-go/log/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ go_test(
"//vendor/github.com/onsi/ginkgo/v2:go_default_library",
"//vendor/github.com/onsi/ginkgo/v2/reporters:go_default_library",
"//vendor/github.com/onsi/gomega:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
],
)

0 comments on commit 7f16fb9

Please sign in to comment.