Skip to content

Commit 5fd1e9e

Browse files
authored
Merge pull request #186 from mengqiy/installWebhookConfig_pointer
Rename InstallWebhookConfig and change it to a pointer
2 parents a67a503 + ee29740 commit 5fd1e9e

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

example/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ import (
3939
var log = logf.Log.WithName("example-controller")
4040

4141
func main() {
42-
var installWebhookConfig bool
43-
flag.BoolVar(&installWebhookConfig, "install-webhook-config", false,
44-
"enable the installer in the webhook server, so it will install webhook related resources during bootstrapping")
42+
var disableWebhookConfigInstaller bool
43+
flag.BoolVar(&disableWebhookConfigInstaller, "disable-webhook-config-installer", false,
44+
"disable the installer in the webhook server, so it won't install webhook configuration resources during bootstrapping")
4545

4646
flag.Parse()
4747
logf.SetLogger(logf.ZapLogger(false))
@@ -108,9 +108,9 @@ func main() {
108108

109109
entryLog.Info("setting up webhook server")
110110
as, err := webhook.NewServer("foo-admission-server", mgr, webhook.ServerOptions{
111-
Port: 9876,
112-
CertDir: "/tmp/cert",
113-
InstallWebhookConfig: installWebhookConfig,
111+
Port: 9876,
112+
CertDir: "/tmp/cert",
113+
DisableWebhookConfigInstaller: &disableWebhookConfigInstaller,
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.DisableWebhookConfigInstaller == nil {
67+
diwc := false
68+
s.DisableWebhookConfigInstaller = &diwc
69+
}
6670

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

pkg/webhook/server.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ type ServerOptions struct {
5454
// Client will be injected by the manager if not set.
5555
Client client.Client
5656

57-
// InstallWebhookConfig controls if the server will automatically create webhook related objects
57+
// DisableWebhookConfigInstaller controls if the server will automatically create webhook related objects
5858
// during bootstrapping. e.g. webhookConfiguration, service and secret.
59-
InstallWebhookConfig bool
59+
// If false, the server will install the webhook config objects. It is defaulted to false.
60+
DisableWebhookConfigInstaller *bool
6061

6162
// BootstrapOptions contains the options for bootstrapping the admission server.
6263
*BootstrapOptions
@@ -190,7 +191,12 @@ var _ manager.Runnable = &Server{}
190191
// Start runs the server.
191192
// It will install the webhook related resources depend on the server configuration.
192193
func (s *Server) Start(stop <-chan struct{}) error {
193-
if s.InstallWebhookConfig {
194+
s.once.Do(s.setDefault)
195+
if s.err != nil {
196+
return s.err
197+
}
198+
199+
if s.DisableWebhookConfigInstaller != nil && !*s.DisableWebhookConfigInstaller {
194200
log.Info("installing webhook configuration in cluster")
195201
err := s.InstallWebhookManifests()
196202
if err != nil {
@@ -200,6 +206,10 @@ func (s *Server) Start(stop <-chan struct{}) error {
200206
log.Info("webhook installer is disabled")
201207
}
202208

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

0 commit comments

Comments
 (0)