Skip to content

Rename InstallWebhookConfig and change it to a pointer #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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