ToManagerOptions uses the flag set in f to configure options. Values of options take precedence over flag defaults, as values are assume to have been explicitly set.
(options manager.Options)
| 146 | // Values of options take precedence over flag defaults, |
| 147 | // as values are assume to have been explicitly set. |
| 148 | func (f *Flags) ToManagerOptions(options manager.Options) manager.Options { |
| 149 | // Alias FlagSet.Changed so options are still updated when fields are empty. |
| 150 | changed := func(flagName string) bool { |
| 151 | return f.flagSet.Changed(flagName) |
| 152 | } |
| 153 | if f.flagSet == nil { |
| 154 | //nolint:golint |
| 155 | changed = func(_ string) bool { return false } |
| 156 | } |
| 157 | |
| 158 | // TODO(2.0.0): remove metrics-addr |
| 159 | if changed("metrics-bind-address") || changed("metrics-addr") || options.Metrics.BindAddress == "" { |
| 160 | options.Metrics.BindAddress = f.MetricsBindAddress |
| 161 | } |
| 162 | if changed("health-probe-bind-address") || options.HealthProbeBindAddress == "" { |
| 163 | options.HealthProbeBindAddress = f.ProbeAddr |
| 164 | } |
| 165 | // TODO(2.0.0): remove enable-leader-election |
| 166 | if changed("leader-elect") || changed("enable-leader-election") || !options.LeaderElection { |
| 167 | options.LeaderElection = f.LeaderElection |
| 168 | } |
| 169 | if changed("leader-election-id") || options.LeaderElectionID == "" { |
| 170 | options.LeaderElectionID = f.LeaderElectionID |
| 171 | } |
| 172 | if changed("leader-election-namespace") || options.LeaderElectionNamespace == "" { |
| 173 | options.LeaderElectionNamespace = f.LeaderElectionNamespace |
| 174 | } |
| 175 | if options.LeaderElectionResourceLock == "" { |
| 176 | options.LeaderElectionResourceLock = resourcelock.LeasesResourceLock |
| 177 | } |
| 178 | |
| 179 | disableHTTP2 := func(c *tls.Config) { |
| 180 | c.NextProtos = []string{"http/1.1"} |
| 181 | } |
| 182 | if !f.EnableHTTP2 { |
| 183 | options.WebhookServer = webhook.NewServer(webhook.Options{ |
| 184 | TLSOpts: []func(*tls.Config){disableHTTP2}, |
| 185 | }) |
| 186 | options.Metrics.TLSOpts = append(options.Metrics.TLSOpts, disableHTTP2) |
| 187 | } |
| 188 | options.Metrics.SecureServing = f.SecureMetrics |
| 189 | |
| 190 | if f.MetricsRequireRBAC { |
| 191 | // FilterProvider is used to protect the metrics endpoint with authn/authz. |
| 192 | // These configurations ensure that only authorized users and service accounts |
| 193 | // can access the metrics endpoint. The RBAC are configured in 'config/rbac/kustomization.yaml'. More info: |
| 194 | // https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.18.4/pkg/metrics/filters#WithAuthenticationAndAuthorization |
| 195 | options.Metrics.FilterProvider = filters.WithAuthenticationAndAuthorization |
| 196 | } |
| 197 | |
| 198 | return options |
| 199 | } |
no outgoing calls
no test coverage detected