Skip to content

Commit 8b52408

Browse files
authored
Merge pull request #1983 from lxlxok/main
Add flags to set server key and certificate
2 parents 08c9c93 + 5f5eee5 commit 8b52408

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func main() {
9191
setupLog.Error(err, "unable to start manager")
9292
os.Exit(1)
9393
}
94+
config.ConfigureWebhookServerCert(controllerCFG.RuntimeConfig, mgr)
9495
clientSet, err := kubernetes.NewForConfig(mgr.GetConfig())
9596
if err != nil {
9697
setupLog.Error(err, "unable to obtain clientSet")

pkg/config/runtime_config.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const (
2020
flagWatchNamespace = "watch-namespace"
2121
flagSyncPeriod = "sync-period"
2222
flagKubeconfig = "kubeconfig"
23+
flagWebhookCertDir = "webhook-cert-dir"
24+
flagWebhookCertName = "webhook-cert-file"
25+
flagWebhookKeyName = "webhook-key-file"
2326

2427
defaultKubeconfig = ""
2528
defaultLeaderElectionID = "aws-load-balancer-controller-leader"
@@ -34,7 +37,10 @@ const (
3437
defaultQPS = 1e6
3538
// High enough Burst to fit all expected use cases. Burst=0 is not set here, because
3639
// client code is overriding it.
37-
defaultBurst = 1e6
40+
defaultBurst = 1e6
41+
defaultWebhookCertDir = ""
42+
defaultWebhookCertName = ""
43+
defaultWebhookKeyName = ""
3844
)
3945

4046
// RuntimeConfig stores the configuration for the controller-runtime
@@ -49,6 +55,9 @@ type RuntimeConfig struct {
4955
LeaderElectionNamespace string
5056
WatchNamespace string
5157
SyncPeriod time.Duration
58+
WebhookCertDir string
59+
WebhookCertName string
60+
WebhookKeyName string
5261
}
5362

5463
// BindFlags binds the command line flags to the fields in the config object
@@ -72,6 +81,10 @@ func (c *RuntimeConfig) BindFlags(fs *pflag.FlagSet) {
7281
"Namespace the controller watches for updates to Kubernetes objects, If empty, all namespaces are watched.")
7382
fs.DurationVar(&c.SyncPeriod, flagSyncPeriod, defaultSyncPeriod,
7483
"Period at which the controller forces the repopulation of its local object stores.")
84+
fs.StringVar(&c.WebhookCertDir, flagWebhookCertDir, defaultWebhookCertDir, "WebhookCertDir is the directory that contains the webhook server key and certificate.")
85+
fs.StringVar(&c.WebhookCertName, flagWebhookCertName, defaultWebhookCertName, "WebhookCertName is the webhook server certificate name.")
86+
fs.StringVar(&c.WebhookKeyName, flagWebhookKeyName, defaultWebhookKeyName, "WebhookKeyName is the webhook server key name.")
87+
7588
}
7689

7790
// BuildRestConfig builds the REST config for the controller runtime
@@ -107,3 +120,10 @@ func BuildRuntimeOptions(rtCfg RuntimeConfig, scheme *runtime.Scheme) ctrl.Optio
107120
SyncPeriod: &rtCfg.SyncPeriod,
108121
}
109122
}
123+
124+
// ConfigureCert set up the server cert for the webhook server.
125+
func ConfigureWebhookServerCert(rtCfg RuntimeConfig, mgr ctrl.Manager) {
126+
mgr.GetWebhookServer().CertDir = rtCfg.WebhookCertDir
127+
mgr.GetWebhookServer().CertName = rtCfg.WebhookCertName
128+
mgr.GetWebhookServer().KeyName = rtCfg.WebhookKeyName
129+
}

0 commit comments

Comments
 (0)