Skip to content

✨ Parameterize webhook key/cert name #760

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
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
26 changes: 17 additions & 9 deletions pkg/webhook/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/internal/metrics"
)

const (
certName = "tls.crt"
keyName = "tls.key"
)

// DefaultPort is the default port that the webhook server serves.
var DefaultPort = 443

Expand All @@ -53,10 +48,15 @@ type Server struct {
Port int

// CertDir is the directory that contains the server key and certificate. The
// server key and certificate must be named tls.key and tls.crt,
// respectively.
// server key and certificate.
CertDir string

// CertName is the server certificate name. Defaults to tls.crt.
CertName string

// CertName is the server key name. Defaults to tls.key.
KeyName string

// WebhookMux is the multiplexer that handles different webhooks.
WebhookMux *http.ServeMux

Expand Down Expand Up @@ -85,6 +85,14 @@ func (s *Server) setDefaults() {
if len(s.CertDir) == 0 {
s.CertDir = filepath.Join(os.TempDir(), "k8s-webhook-server", "serving-certs")
}

if len(s.CertName) == 0 {
s.CertName = "tls.crt"
}

if len(s.KeyName) == 0 {
s.KeyName = "tls.key"
}
}

// NeedLeaderElection implements the LeaderElectionRunnable interface, which indicates
Expand Down Expand Up @@ -141,8 +149,8 @@ func (s *Server) Start(stop <-chan struct{}) error {
}
}

certPath := filepath.Join(s.CertDir, certName)
keyPath := filepath.Join(s.CertDir, keyName)
certPath := filepath.Join(s.CertDir, s.CertName)
keyPath := filepath.Join(s.CertDir, s.KeyName)

certWatcher, err := certwatcher.New(certPath, keyPath)
if err != nil {
Expand Down