Skip to content

Commit ba09808

Browse files
author
Mengqi Yu
committed
change InstallWebhookConfig to pointer
1 parent 4376e6e commit ba09808

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

example/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func main() {
110110
as, err := webhook.NewServer("foo-admission-server", mgr, webhook.ServerOptions{
111111
Port: 9876,
112112
CertDir: "/tmp/cert",
113-
InstallWebhookConfig: installWebhookConfig,
113+
InstallWebhookConfig: &installWebhookConfig,
114114
BootstrapOptions: &webhook.BootstrapOptions{
115115
Secret: &apitypes.NamespacedName{
116116
Namespace: "default",

pkg/webhook/bootstrap.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ func (s *Server) setServerDefault() {
6363
if len(s.CertDir) == 0 {
6464
s.CertDir = path.Join("k8s-webhook-server", "cert")
6565
}
66+
if s.InstallWebhookConfig == nil {
67+
iwc := true
68+
s.InstallWebhookConfig = &iwc
69+
}
6670

6771
if s.Client == nil {
6872
cfg, err := config.GetConfig()

pkg/webhook/server.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type ServerOptions struct {
5656

5757
// InstallWebhookConfig controls if the server will automatically create webhook related objects
5858
// during bootstrapping. e.g. webhookConfiguration, service and secret.
59-
InstallWebhookConfig bool
59+
InstallWebhookConfig *bool
6060

6161
// BootstrapOptions contains the options for bootstrapping the admission server.
6262
*BootstrapOptions
@@ -190,7 +190,12 @@ var _ manager.Runnable = &Server{}
190190
// Start runs the server.
191191
// It will install the webhook related resources depend on the server configuration.
192192
func (s *Server) Start(stop <-chan struct{}) error {
193-
if s.InstallWebhookConfig {
193+
s.once.Do(s.setDefault)
194+
if s.err != nil {
195+
return s.err
196+
}
197+
198+
if s.InstallWebhookConfig != nil && *s.InstallWebhookConfig {
194199
log.Info("installing webhook configuration in cluster")
195200
err := s.InstallWebhookManifests()
196201
if err != nil {
@@ -200,6 +205,10 @@ func (s *Server) Start(stop <-chan struct{}) error {
200205
log.Info("webhook installer is disabled")
201206
}
202207

208+
return s.run(stop)
209+
}
210+
211+
func (s *Server) run(stop <-chan struct{}) error {
203212
srv := &http.Server{
204213
Addr: fmt.Sprintf(":%v", s.Port),
205214
Handler: s.sMux,

0 commit comments

Comments
 (0)