Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#10883 from awprice/issue-10882
Browse files Browse the repository at this point in the history
🐛 Also use tls options for metrics/diagnostics server
  • Loading branch information
k8s-ci-robot authored Jul 25, 2024
2 parents 0908bfc + f4db345 commit c5b4e93
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 229 deletions.
16 changes: 6 additions & 10 deletions bootstrap/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ var (
webhookCertName string
webhookKeyName string
healthAddr string
tlsOptions = flags.TLSOptions{}
diagnosticsOptions = flags.DiagnosticsOptions{}
managerOptions = flags.ManagerOptions{}
logOptions = logs.NewOptions()
// CABPK specific flags.
clusterConcurrency int
Expand Down Expand Up @@ -170,8 +169,7 @@ func InitFlags(fs *pflag.FlagSet) {
fs.StringVar(&healthAddr, "health-addr", ":9440",
"The address the health endpoint binds to.")

flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
flags.AddTLSOptions(fs, &tlsOptions)
flags.AddManagerOptions(fs, &managerOptions)

feature.MutableGates.AddFlag(fs)
}
Expand Down Expand Up @@ -204,14 +202,12 @@ func main() {
restConfig.Burst = restConfigBurst
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent(controllerName)

tlsOptionOverrides, err := flags.GetTLSOptionOverrideFuncs(tlsOptions)
tlsOptions, metricsOptions, err := flags.GetManagerOptions(managerOptions)
if err != nil {
setupLog.Error(err, "unable to add TLS settings to the webhook server")
setupLog.Error(err, "Unable to start manager: invalid flags")
os.Exit(1)
}

diagnosticsOpts := flags.GetDiagnosticsOptions(diagnosticsOptions)

var watchNamespaces map[string]cache.Config
if watchNamespace != "" {
watchNamespaces = map[string]cache.Config{
Expand All @@ -236,7 +232,7 @@ func main() {
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
HealthProbeBindAddress: healthAddr,
PprofBindAddress: profilerAddress,
Metrics: diagnosticsOpts,
Metrics: *metricsOptions,
Cache: cache.Options{
DefaultNamespaces: watchNamespaces,
SyncPeriod: &syncPeriod,
Expand Down Expand Up @@ -265,7 +261,7 @@ func main() {
CertDir: webhookCertDir,
CertName: webhookCertName,
KeyName: webhookKeyName,
TLSOpts: tlsOptionOverrides,
TLSOpts: tlsOptions,
},
),
}
Expand Down
16 changes: 6 additions & 10 deletions controlplane/kubeadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ var (
webhookCertName string
webhookKeyName string
healthAddr string
tlsOptions = flags.TLSOptions{}
diagnosticsOptions = flags.DiagnosticsOptions{}
managerOptions = flags.ManagerOptions{}
logOptions = logs.NewOptions()
// KCP specific flags.
kubeadmControlPlaneConcurrency int
Expand Down Expand Up @@ -180,8 +179,7 @@ func InitFlags(fs *pflag.FlagSet) {
"Use the deprecated naming convention for infra machines where they are named after the InfraMachineTemplate.")
_ = fs.MarkDeprecated("use-deprecated-infra-machine-naming", "This flag will be removed in v1.9.")

flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
flags.AddTLSOptions(fs, &tlsOptions)
flags.AddManagerOptions(fs, &managerOptions)

feature.MutableGates.AddFlag(fs)
}
Expand Down Expand Up @@ -214,14 +212,12 @@ func main() {
restConfig.Burst = restConfigBurst
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent(controllerName)

tlsOptionOverrides, err := flags.GetTLSOptionOverrideFuncs(tlsOptions)
tlsOptions, metricsOptions, err := flags.GetManagerOptions(managerOptions)
if err != nil {
setupLog.Error(err, "unable to add TLS settings to the webhook server")
setupLog.Error(err, "Unable to start manager: invalid flags")
os.Exit(1)
}

diagnosticsOpts := flags.GetDiagnosticsOptions(diagnosticsOptions)

var watchNamespaces map[string]cache.Config
if watchNamespace != "" {
watchNamespaces = map[string]cache.Config{
Expand All @@ -246,7 +242,7 @@ func main() {
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
HealthProbeBindAddress: healthAddr,
PprofBindAddress: profilerAddress,
Metrics: diagnosticsOpts,
Metrics: *metricsOptions,
Cache: cache.Options{
DefaultNamespaces: watchNamespaces,
SyncPeriod: &syncPeriod,
Expand Down Expand Up @@ -278,7 +274,7 @@ func main() {
CertDir: webhookCertDir,
CertName: webhookCertName,
KeyName: webhookKeyName,
TLSOpts: tlsOptionOverrides,
TLSOpts: tlsOptions,
},
),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ maintainers of providers and consumers of our Go API.
and [kubernetes-sigs/controller-runtime#2811](https://github.com/kubernetes-sigs/controller-runtime/pull/2811).
- `remote.NewClusterCacheTracker` now has options to configure QPS & Burst. It's highly recommended to implement corresponding flags
the same way as core Cluster API (see PR: https://github.com/kubernetes-sigs/cluster-api/pull/10880).
- There were changes made to flags in core CAPI (https://github.com/kubernetes-sigs/cluster-api/pull/10883, https://github.com/kubernetes-sigs/cluster-api/pull/10880). It's recommended to adopt these changes in providers as well.
16 changes: 6 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ var (
webhookCertName string
webhookKeyName string
healthAddr string
tlsOptions = flags.TLSOptions{}
diagnosticsOptions = flags.DiagnosticsOptions{}
managerOptions = flags.ManagerOptions{}
logOptions = logs.NewOptions()
// core Cluster API specific flags.
clusterTopologyConcurrency int
Expand Down Expand Up @@ -243,8 +242,7 @@ func InitFlags(fs *pflag.FlagSet) {
"Use deprecated infrastructure machine naming")
_ = fs.MarkDeprecated("use-deprecated-infra-machine-naming", "This flag will be removed in v1.9.")

flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
flags.AddTLSOptions(fs, &tlsOptions)
flags.AddManagerOptions(fs, &managerOptions)

feature.MutableGates.AddFlag(fs)
}
Expand Down Expand Up @@ -292,14 +290,12 @@ func main() {
os.Exit(1)
}

tlsOptionOverrides, err := flags.GetTLSOptionOverrideFuncs(tlsOptions)
tlsOptions, metricsOptions, err := flags.GetManagerOptions(managerOptions)
if err != nil {
setupLog.Error(err, "Unable to add TLS settings to the webhook server")
setupLog.Error(err, "Unable to start manager: invalid flags")
os.Exit(1)
}

diagnosticsOpts := flags.GetDiagnosticsOptions(diagnosticsOptions)

var watchNamespaces map[string]cache.Config
if watchNamespace != "" {
watchNamespaces = map[string]cache.Config{
Expand All @@ -324,7 +320,7 @@ func main() {
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
HealthProbeBindAddress: healthAddr,
PprofBindAddress: profilerAddress,
Metrics: diagnosticsOpts,
Metrics: *metricsOptions,
Cache: cache.Options{
DefaultNamespaces: watchNamespaces,
SyncPeriod: &syncPeriod,
Expand Down Expand Up @@ -353,7 +349,7 @@ func main() {
CertDir: webhookCertDir,
CertName: webhookCertName,
KeyName: webhookKeyName,
TLSOpts: tlsOptionOverrides,
TLSOpts: tlsOptions,
},
),
}
Expand Down
16 changes: 6 additions & 10 deletions test/extension/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ var (
webhookCertName string
webhookKeyName string
healthAddr string
tlsOptions = flags.TLSOptions{}
diagnosticsOptions = flags.DiagnosticsOptions{}
managerOptions = flags.ManagerOptions{}
logOptions = logs.NewOptions()
)

Expand Down Expand Up @@ -153,8 +152,7 @@ func InitFlags(fs *pflag.FlagSet) {
fs.StringVar(&healthAddr, "health-addr", ":9440",
"The address the health endpoint binds to.")

flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
flags.AddTLSOptions(fs, &tlsOptions)
flags.AddManagerOptions(fs, &managerOptions)

// Add test-extension specific flags
// NOTE: it is not mandatory to use the same flag names in all RuntimeExtension, but it is recommended when
Expand Down Expand Up @@ -197,14 +195,12 @@ func main() {
restConfig.Burst = restConfigBurst
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent(controllerName)

tlsOptionOverrides, err := flags.GetTLSOptionOverrideFuncs(tlsOptions)
tlsOptions, metricsOptions, err := flags.GetManagerOptions(managerOptions)
if err != nil {
setupLog.Error(err, "Unable to add TLS settings to the webhook server")
setupLog.Error(err, "Unable to start manager: invalid flags")
os.Exit(1)
}

diagnosticsOpts := flags.GetDiagnosticsOptions(diagnosticsOptions)

if enableContentionProfiling {
goruntime.SetBlockProfileRate(1)
}
Expand All @@ -215,7 +211,7 @@ func main() {
CertDir: webhookCertDir,
CertName: webhookCertName,
KeyName: webhookKeyName,
TLSOpts: tlsOptionOverrides,
TLSOpts: tlsOptions,
Catalog: catalog,
})
if err != nil {
Expand All @@ -233,7 +229,7 @@ func main() {
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
HealthProbeBindAddress: healthAddr,
PprofBindAddress: profilerAddress,
Metrics: diagnosticsOpts,
Metrics: *metricsOptions,
Cache: cache.Options{
SyncPeriod: &syncPeriod,
},
Expand Down
16 changes: 6 additions & 10 deletions test/infrastructure/docker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ var (
webhookCertName string
webhookKeyName string
healthAddr string
tlsOptions = flags.TLSOptions{}
diagnosticsOptions = flags.DiagnosticsOptions{}
managerOptions = flags.ManagerOptions{}
logOptions = logs.NewOptions()
// CAPD specific flags.
concurrency int
Expand Down Expand Up @@ -171,8 +170,7 @@ func InitFlags(fs *pflag.FlagSet) {
fs.StringVar(&healthAddr, "health-addr", ":9440",
"The address the health endpoint binds to.")

flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
flags.AddTLSOptions(fs, &tlsOptions)
flags.AddManagerOptions(fs, &managerOptions)

feature.MutableGates.AddFlag(fs)
}
Expand Down Expand Up @@ -210,14 +208,12 @@ func main() {
restConfig.Burst = restConfigBurst
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent(controllerName)

tlsOptionOverrides, err := flags.GetTLSOptionOverrideFuncs(tlsOptions)
tlsOptions, metricsOptions, err := flags.GetManagerOptions(managerOptions)
if err != nil {
setupLog.Error(err, "Unable to add TLS settings to the webhook server")
setupLog.Error(err, "Unable to start manager: invalid flags")
os.Exit(1)
}

diagnosticsOpts := flags.GetDiagnosticsOptions(diagnosticsOptions)

var watchNamespaces map[string]cache.Config
if watchNamespace != "" {
watchNamespaces = map[string]cache.Config{
Expand All @@ -242,7 +238,7 @@ func main() {
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
HealthProbeBindAddress: healthAddr,
PprofBindAddress: profilerAddress,
Metrics: diagnosticsOpts,
Metrics: *metricsOptions,
Cache: cache.Options{
DefaultNamespaces: watchNamespaces,
SyncPeriod: &syncPeriod,
Expand Down Expand Up @@ -271,7 +267,7 @@ func main() {
CertDir: webhookCertDir,
CertName: webhookCertName,
KeyName: webhookKeyName,
TLSOpts: tlsOptionOverrides,
TLSOpts: tlsOptions,
},
),
}
Expand Down
16 changes: 6 additions & 10 deletions test/infrastructure/inmemory/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ var (
webhookCertName string
webhookKeyName string
healthAddr string
tlsOptions = flags.TLSOptions{}
diagnosticsOptions = flags.DiagnosticsOptions{}
managerOptions = flags.ManagerOptions{}
logOptions = logs.NewOptions()
// CAPIM specific flags.
clusterConcurrency int
Expand Down Expand Up @@ -158,8 +157,7 @@ func InitFlags(fs *pflag.FlagSet) {
fs.StringVar(&healthAddr, "health-addr", ":9440",
"The address the health endpoint binds to.")

flags.AddDiagnosticsOptions(fs, &diagnosticsOptions)
flags.AddTLSOptions(fs, &tlsOptions)
flags.AddManagerOptions(fs, &managerOptions)

feature.MutableGates.AddFlag(fs)
}
Expand Down Expand Up @@ -192,14 +190,12 @@ func main() {
restConfig.Burst = restConfigBurst
restConfig.UserAgent = remote.DefaultClusterAPIUserAgent(controllerName)

tlsOptionOverrides, err := flags.GetTLSOptionOverrideFuncs(tlsOptions)
tlsOptions, metricsOptions, err := flags.GetManagerOptions(managerOptions)
if err != nil {
setupLog.Error(err, "Unable to add TLS settings to the webhook server")
setupLog.Error(err, "Unable to start manager: invalid flags")
os.Exit(1)
}

diagnosticsOpts := flags.GetDiagnosticsOptions(diagnosticsOptions)

var watchNamespaces map[string]cache.Config
if watchNamespace != "" {
watchNamespaces = map[string]cache.Config{
Expand All @@ -221,7 +217,7 @@ func main() {
LeaderElectionResourceLock: resourcelock.LeasesResourceLock,
HealthProbeBindAddress: healthAddr,
PprofBindAddress: profilerAddress,
Metrics: diagnosticsOpts,
Metrics: *metricsOptions,
Cache: cache.Options{
DefaultNamespaces: watchNamespaces,
SyncPeriod: &syncPeriod,
Expand All @@ -242,7 +238,7 @@ func main() {
CertDir: webhookCertDir,
CertName: webhookCertName,
KeyName: webhookKeyName,
TLSOpts: tlsOptionOverrides,
TLSOpts: tlsOptions,
},
),
}
Expand Down
Loading

0 comments on commit c5b4e93

Please sign in to comment.