Skip to content

Commit

Permalink
Merge pull request #186 from mengqiy/installWebhookConfig_pointer
Browse files Browse the repository at this point in the history
Rename InstallWebhookConfig and change it to a pointer
  • Loading branch information
k8s-ci-robot committed Oct 29, 2018
2 parents a67a503 + ee29740 commit 5fd1e9e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
12 changes: 6 additions & 6 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import (
var log = logf.Log.WithName("example-controller")

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

flag.Parse()
logf.SetLogger(logf.ZapLogger(false))
Expand Down Expand Up @@ -108,9 +108,9 @@ func main() {

entryLog.Info("setting up webhook server")
as, err := webhook.NewServer("foo-admission-server", mgr, webhook.ServerOptions{
Port: 9876,
CertDir: "/tmp/cert",
InstallWebhookConfig: installWebhookConfig,
Port: 9876,
CertDir: "/tmp/cert",
DisableWebhookConfigInstaller: &disableWebhookConfigInstaller,
BootstrapOptions: &webhook.BootstrapOptions{
Secret: &apitypes.NamespacedName{
Namespace: "default",
Expand Down
4 changes: 4 additions & 0 deletions pkg/webhook/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (s *Server) setServerDefault() {
if len(s.CertDir) == 0 {
s.CertDir = path.Join("k8s-webhook-server", "cert")
}
if s.DisableWebhookConfigInstaller == nil {
diwc := false
s.DisableWebhookConfigInstaller = &diwc
}

if s.Client == nil {
cfg, err := config.GetConfig()
Expand Down
16 changes: 13 additions & 3 deletions pkg/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ type ServerOptions struct {
// Client will be injected by the manager if not set.
Client client.Client

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

// BootstrapOptions contains the options for bootstrapping the admission server.
*BootstrapOptions
Expand Down Expand Up @@ -190,7 +191,12 @@ var _ manager.Runnable = &Server{}
// Start runs the server.
// It will install the webhook related resources depend on the server configuration.
func (s *Server) Start(stop <-chan struct{}) error {
if s.InstallWebhookConfig {
s.once.Do(s.setDefault)
if s.err != nil {
return s.err
}

if s.DisableWebhookConfigInstaller != nil && !*s.DisableWebhookConfigInstaller {
log.Info("installing webhook configuration in cluster")
err := s.InstallWebhookManifests()
if err != nil {
Expand All @@ -200,6 +206,10 @@ func (s *Server) Start(stop <-chan struct{}) error {
log.Info("webhook installer is disabled")
}

return s.run(stop)
}

func (s *Server) run(stop <-chan struct{}) error {
srv := &http.Server{
Addr: fmt.Sprintf(":%v", s.Port),
Handler: s.sMux,
Expand Down

0 comments on commit 5fd1e9e

Please sign in to comment.