Skip to content

Commit 887ca88

Browse files
committed
feat(cmd): remove unnecessary code
1 parent 6fe7892 commit 887ca88

1 file changed

Lines changed: 9 additions & 48 deletions

File tree

cmd/main.go

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"sigs.k8s.io/controller-runtime/pkg/log/zap"
2020
"sigs.k8s.io/controller-runtime/pkg/metrics/filters"
2121
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
22-
"sigs.k8s.io/controller-runtime/pkg/webhook"
2322

2423
"github.com/jackc/pgx/v5/pgxpool"
2524

@@ -45,12 +44,13 @@ func init() {
4544
func main() {
4645
var metricsAddr string
4746
var metricsCertPath, metricsCertName, metricsCertKey string
48-
var webhookCertPath, webhookCertName, webhookCertKey string
4947
var enableLeaderElection bool
5048
var probeAddr string
5149
var secureMetrics bool
5250
var enableHTTP2 bool
5351
var tlsOpts []func(*tls.Config)
52+
var operatorInstanceName string
53+
5454
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+
5555
"Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.")
5656
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -59,15 +59,14 @@ func main() {
5959
"Enabling this will ensure there is only one active controller manager.")
6060
flag.BoolVar(&secureMetrics, "metrics-secure", true,
6161
"If set, the metrics endpoint is served securely via HTTPS. Use --metrics-secure=false to use HTTP instead.")
62-
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
63-
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
64-
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
6562
flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
6663
"The directory that contains the metrics server certificate.")
6764
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
6865
flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
6966
flag.BoolVar(&enableHTTP2, "enable-http2", false,
7067
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
68+
flag.StringVar(&operatorInstanceName, "operator-instance-name", "", "The name of this operator instance.")
69+
7170
opts := zap.Options{
7271
Development: true,
7372
StacktraceLevel: zapcore.DPanicLevel,
@@ -92,7 +91,9 @@ func main() {
9291
tlsOpts = append(tlsOpts, disableHTTP2)
9392
}
9493

95-
operatorInstanceName := os.Getenv("OPERATOR_INSTANCE_NAME")
94+
if operatorInstanceName == "" {
95+
operatorInstanceName = os.Getenv("OPERATOR_INSTANCE_NAME")
96+
}
9697

9798
pgpool, err := pgxpool.New(context.Background(), os.Getenv("DATABASE_URL"))
9899
if err != nil {
@@ -110,34 +111,8 @@ func main() {
110111

111112
cacheRolePasswords := make(map[string]string)
112113

113-
// Create watchers for metrics and webhooks certificates
114-
var metricsCertWatcher, webhookCertWatcher *certwatcher.CertWatcher
115-
116-
// Initial webhook TLS options
117-
webhookTLSOpts := tlsOpts
118-
119-
if len(webhookCertPath) > 0 {
120-
setupLog.Info("Initializing webhook certificate watcher using provided certificates",
121-
"webhook-cert-path", webhookCertPath, "webhook-cert-name", webhookCertName, "webhook-cert-key", webhookCertKey)
122-
123-
var err error
124-
webhookCertWatcher, err = certwatcher.New(
125-
filepath.Join(webhookCertPath, webhookCertName),
126-
filepath.Join(webhookCertPath, webhookCertKey),
127-
)
128-
if err != nil {
129-
setupLog.Error(err, "Failed to initialize webhook certificate watcher")
130-
os.Exit(1)
131-
}
132-
133-
webhookTLSOpts = append(webhookTLSOpts, func(config *tls.Config) {
134-
config.GetCertificate = webhookCertWatcher.GetCertificate
135-
})
136-
}
137-
138-
webhookServer := webhook.NewServer(webhook.Options{
139-
TLSOpts: webhookTLSOpts,
140-
})
114+
// Create watchers for metrics certificate
115+
var metricsCertWatcher *certwatcher.CertWatcher
141116

142117
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
143118
// More info:
@@ -160,11 +135,6 @@ func main() {
160135
// If the certificate is not specified, controller-runtime will automatically
161136
// generate self-signed certificates for the metrics server. While convenient for development and testing,
162137
// this setup is not recommended for production.
163-
//
164-
// TODO(user): If you enable certManager, uncomment the following lines:
165-
// - [METRICS-WITH-CERTS] at config/default/kustomization.yaml to generate and use certificates
166-
// managed by cert-manager for the metrics server.
167-
// - [PROMETHEUS-WITH-CERTS] at config/prometheus/kustomization.yaml for TLS certification.
168138
if len(metricsCertPath) > 0 {
169139
setupLog.Info("Initializing metrics certificate watcher using provided certificates",
170140
"metrics-cert-path", metricsCertPath, "metrics-cert-name", metricsCertName, "metrics-cert-key", metricsCertKey)
@@ -187,7 +157,6 @@ func main() {
187157
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
188158
Scheme: scheme,
189159
Metrics: metricsServerOptions,
190-
WebhookServer: webhookServer,
191160
HealthProbeBindAddress: probeAddr,
192161
LeaderElection: enableLeaderElection,
193162
LeaderElectionID: "b707bc79.managed-postgres-operator.hoppscale.com",
@@ -247,14 +216,6 @@ func main() {
247216
}
248217
}
249218

250-
if webhookCertWatcher != nil {
251-
setupLog.Info("Adding webhook certificate watcher to manager")
252-
if err := mgr.Add(webhookCertWatcher); err != nil {
253-
setupLog.Error(err, "unable to add webhook certificate watcher to manager")
254-
os.Exit(1)
255-
}
256-
}
257-
258219
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
259220
setupLog.Error(err, "unable to set up health check")
260221
os.Exit(1)

0 commit comments

Comments
 (0)