Skip to content

Commit

Permalink
also ping the webhook server after start
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Jul 9, 2021
1 parent 8b8d524 commit 0fd3e3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"path/filepath"
"strconv"
"sync"
"time"

"k8s.io/apimachinery/pkg/runtime"
kscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -294,9 +295,17 @@ func (s *Server) StartedChecker() healthz.Checker {
return func(req *http.Request) error {
s.mu.Lock()
defer s.mu.Unlock()

if !s.started {
return fmt.Errorf("webhook server has not been started yet")
}

conn, err := net.DialTimeout("tcp", net.JoinHostPort(s.Host, strconv.Itoa(s.Port)), 10*time.Second)
if err != nil {
return fmt.Errorf("webhook server is not reachable: %v", err)
}
conn.Close()

return nil
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/webhook/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ var _ = Describe("Webhook Server", func() {
It("should serve a webhook on the requested path", func() {
server.Register("/somepath", &testHandler{})

Expect(server.StartedChecker()(nil)).ToNot(Succeed())

doneCh := startServer()

Eventually(func() ([]byte, error) {
Expand Down

0 comments on commit 0fd3e3f

Please sign in to comment.