refactor: 按职责拆分 controller 启动流程
Verify / test (pull_request) Successful in 9m48s
Verify / lint (pull_request) Successful in 10m42s
Verify / database-integration (pull_request) Successful in 12m1s

This commit is contained in:
2026-09-27 17:37:45 +00:00
parent c7b80890fb
commit 356e21686f
8 changed files with 425 additions and 188 deletions
+59
View File
@@ -0,0 +1,59 @@
package bootstrap
import (
"flag"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
type options struct {
manager managerOptions
database databaseOptions
openBao openBaoOptions
logging zap.Options
}
func (o *options) bindFlags(flags *flag.FlagSet) {
o.manager.bindFlags(flags)
o.database.bindFlags(flags)
o.openBao.bindFlags(flags)
o.logging.Development = true
o.logging.BindFlags(flags)
}
type managerOptions struct {
metricsAddr string
metricsCertPath string
metricsCertName string
metricsCertKey string
webhookCertPath string
webhookCertName string
webhookCertKey string
webhookPort int
enableLeaderElection bool
probeAddr string
secureMetrics bool
enableHTTP2 bool
}
func (o *managerOptions) bindFlags(flags *flag.FlagSet) {
flags.StringVar(&o.metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
flags.StringVar(&o.probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flags.BoolVar(&o.enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flags.BoolVar(&o.secureMetrics, "metrics-secure", true,
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
flags.StringVar(&o.webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
flags.StringVar(&o.webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
flags.StringVar(&o.webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
flags.IntVar(&o.webhookPort, "webhook-port", 9443, "Port the webhook server listens on. "+
"Defaults to 9443. Set -1 to disable the webhook server.")
flags.StringVar(&o.metricsCertPath, "metrics-cert-path", "",
"The directory that contains the metrics server certificate.")
flags.StringVar(&o.metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
flags.StringVar(&o.metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
flags.BoolVar(&o.enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
}