Skip to content

Commit b919853

Browse files
authored
Merge pull request #760 from qinqon/parameterize-webhook-key-cert-name-2
✨ Parameterize webhook key/cert name
2 parents b1f3d2e + e01173f commit b919853

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

pkg/webhook/server.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ import (
3333
"sigs.k8s.io/controller-runtime/pkg/webhook/internal/metrics"
3434
)
3535

36-
const (
37-
certName = "tls.crt"
38-
keyName = "tls.key"
39-
)
40-
4136
// DefaultPort is the default port that the webhook server serves.
4237
var DefaultPort = 443
4338

@@ -53,10 +48,15 @@ type Server struct {
5348
Port int
5449

5550
// CertDir is the directory that contains the server key and certificate. The
56-
// server key and certificate must be named tls.key and tls.crt,
57-
// respectively.
51+
// server key and certificate.
5852
CertDir string
5953

54+
// CertName is the server certificate name. Defaults to tls.crt.
55+
CertName string
56+
57+
// CertName is the server key name. Defaults to tls.key.
58+
KeyName string
59+
6060
// WebhookMux is the multiplexer that handles different webhooks.
6161
WebhookMux *http.ServeMux
6262

@@ -85,6 +85,14 @@ func (s *Server) setDefaults() {
8585
if len(s.CertDir) == 0 {
8686
s.CertDir = filepath.Join(os.TempDir(), "k8s-webhook-server", "serving-certs")
8787
}
88+
89+
if len(s.CertName) == 0 {
90+
s.CertName = "tls.crt"
91+
}
92+
93+
if len(s.KeyName) == 0 {
94+
s.KeyName = "tls.key"
95+
}
8896
}
8997

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

144-
certPath := filepath.Join(s.CertDir, certName)
145-
keyPath := filepath.Join(s.CertDir, keyName)
152+
certPath := filepath.Join(s.CertDir, s.CertName)
153+
keyPath := filepath.Join(s.CertDir, s.KeyName)
146154

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

0 commit comments

Comments
 (0)