Skip to content

Commit e8eca3c

Browse files
committed
make it possible to monitor if the webhook server has been started
Signed-off-by: Stefan Büringer [email protected]
1 parent ef5c8a3 commit e8eca3c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pkg/webhook/server.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ type Server struct {
8787
// defaultingOnce ensures that the default fields are only ever set once.
8888
defaultingOnce sync.Once
8989

90+
// started is set to true immediately before the server is started
91+
// and thus can be used to check if the server has been started
92+
started bool
93+
9094
// mu protects access to the webhook map & setFields for Start, Register, etc
9195
mu sync.Mutex
9296
}
@@ -272,6 +276,9 @@ func (s *Server) Start(ctx context.Context) error {
272276
close(idleConnsClosed)
273277
}()
274278

279+
s.mu.Lock()
280+
s.started = true
281+
s.mu.Unlock()
275282
if err := srv.Serve(listener); err != nil && err != http.ErrServerClosed {
276283
return err
277284
}
@@ -280,6 +287,13 @@ func (s *Server) Start(ctx context.Context) error {
280287
return nil
281288
}
282289

290+
// Started returns if the server has been started
291+
func (s *Server) Started() bool {
292+
s.mu.Lock()
293+
defer s.mu.Unlock()
294+
return s.started
295+
}
296+
283297
// InjectFunc injects the field setter into the server.
284298
func (s *Server) InjectFunc(f inject.Func) error {
285299
s.setFields = f

pkg/webhook/server_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ var _ = Describe("Webhook Server", func() {
137137
return ioutil.ReadAll(resp.Body)
138138
}).Should(Equal([]byte("gadzooks!")))
139139

140+
Expect(server.Started()).To(BeTrue())
141+
140142
ctxCancel()
141143
Eventually(doneCh, "4s").Should(BeClosed())
142144
})

0 commit comments

Comments
 (0)