Skip to content

Commit 0fd3e3f

Browse files
committed
also ping the webhook server after start
1 parent 8b8d524 commit 0fd3e3f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pkg/webhook/server.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"path/filepath"
2929
"strconv"
3030
"sync"
31+
"time"
3132

3233
"k8s.io/apimachinery/pkg/runtime"
3334
kscheme "k8s.io/client-go/kubernetes/scheme"
@@ -294,9 +295,17 @@ func (s *Server) StartedChecker() healthz.Checker {
294295
return func(req *http.Request) error {
295296
s.mu.Lock()
296297
defer s.mu.Unlock()
298+
297299
if !s.started {
298300
return fmt.Errorf("webhook server has not been started yet")
299301
}
302+
303+
conn, err := net.DialTimeout("tcp", net.JoinHostPort(s.Host, strconv.Itoa(s.Port)), 10*time.Second)
304+
if err != nil {
305+
return fmt.Errorf("webhook server is not reachable: %v", err)
306+
}
307+
conn.Close()
308+
300309
return nil
301310
}
302311
}

pkg/webhook/server_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ var _ = Describe("Webhook Server", func() {
128128
It("should serve a webhook on the requested path", func() {
129129
server.Register("/somepath", &testHandler{})
130130

131+
Expect(server.StartedChecker()(nil)).ToNot(Succeed())
132+
131133
doneCh := startServer()
132134

133135
Eventually(func() ([]byte, error) {

0 commit comments

Comments
 (0)