forked from kubernetes-retired/service-catalog
/
options.go
129 lines (115 loc) · 7.63 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// The controller is responsible for running control loops that reconcile
// the state of service catalog API resources with service brokers, service
// classes, service instances, and service instance credentials.
package options
import (
"time"
"github.com/spf13/pflag"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"github.com/kubernetes-sigs/service-catalog/pkg/apis/componentconfig"
"github.com/kubernetes-sigs/service-catalog/pkg/controller"
k8scomponentconfig "github.com/kubernetes-sigs/service-catalog/pkg/kubernetes/pkg/apis/componentconfig"
"github.com/kubernetes-sigs/service-catalog/pkg/kubernetes/pkg/client/leaderelectionconfig"
osb "github.com/pmorie/go-open-service-broker-client/v2"
genericoptions "k8s.io/apiserver/pkg/server/options"
)
const (
// Use the same SSL configuration as we use in Catalog API Server.
// Store generated SSL certificates in a place that won't collide with the
// k8s core API server.
certDirectory = "/var/run/kubernetes-service-catalog"
)
// ControllerManagerServer is the main context object for the controller
// manager.
type ControllerManagerServer struct {
componentconfig.ControllerManagerConfiguration
}
const (
defaultResyncInterval = 5 * time.Minute
defaultServiceBrokerRelistInterval = 24 * time.Hour
defaultContentType = "application/json"
defaultBindAddress = "0.0.0.0"
defaultPort = 8444
defaultK8sKubeconfigPath = "./kubeconfig"
defaultServiceCatalogKubeconfigPath = "./service-catalog-kubeconfig"
defaultOSBAPIContextProfile = true
defaultConcurrentSyncs = 5
defaultLeaderElectionNamespace = "kube-system"
defaultReconciliationRetryDuration = 7 * 24 * time.Hour
defaultOperationPollingMaximumBackoffDuration = 20 * time.Minute
defaultOSBAPITimeOut = 60 * time.Second
)
var defaultOSBAPIPreferredVersion = osb.LatestAPIVersion().HeaderValue()
// NewControllerManagerServer creates a new ControllerManagerServer with a
// default config.
func NewControllerManagerServer() *ControllerManagerServer {
s := ControllerManagerServer{
ControllerManagerConfiguration: componentconfig.ControllerManagerConfiguration{
Address: defaultBindAddress,
Port: 0,
ContentType: defaultContentType,
K8sKubeconfigPath: defaultK8sKubeconfigPath,
ServiceCatalogKubeconfigPath: defaultServiceCatalogKubeconfigPath,
ResyncInterval: defaultResyncInterval,
ServiceBrokerRelistInterval: defaultServiceBrokerRelistInterval,
OSBAPIContextProfile: defaultOSBAPIContextProfile,
OSBAPIPreferredVersion: defaultOSBAPIPreferredVersion,
OSBAPITimeOut: defaultOSBAPITimeOut,
ConcurrentSyncs: defaultConcurrentSyncs,
LeaderElection: leaderelectionconfig.DefaultLeaderElectionConfiguration(),
LeaderElectionNamespace: defaultLeaderElectionNamespace,
EnableProfiling: true,
EnableContentionProfiling: false,
ReconciliationRetryDuration: defaultReconciliationRetryDuration,
OperationPollingMaximumBackoffDuration: defaultOperationPollingMaximumBackoffDuration,
SecureServingOptions: genericoptions.NewSecureServingOptions(),
},
}
// set defaults, these will be overridden by user specified flags
s.SecureServingOptions.BindPort = defaultPort
s.SecureServingOptions.ServerCert.CertDirectory = certDirectory
s.LeaderElection.LeaderElect = true
return &s
}
// AddFlags adds flags for a ControllerManagerServer to the specified FlagSet.
func (s *ControllerManagerServer) AddFlags(fs *pflag.FlagSet) {
fs.Var(k8scomponentconfig.IPVar{Val: &s.Address}, "address", "DEPRECATED: see --bind-address instead")
fs.MarkDeprecated("address", "see --bind-address instead")
fs.Int32Var(&s.Port, "port", 0, "DEPRECATED: see --secure-port instead")
fs.IntVar(&s.ConcurrentSyncs, "concurrent-syncs", defaultConcurrentSyncs, "Number of concurrent syncs")
fs.MarkDeprecated("port", "see --secure-port instead")
fs.StringVar(&s.ContentType, "api-content-type", s.ContentType, "Content type of requests sent to API servers")
fs.StringVar(&s.K8sAPIServerURL, "k8s-api-server-url", "", "The URL for the k8s API server")
fs.StringVar(&s.K8sKubeconfigPath, "k8s-kubeconfig", "", "Path to k8s core kubeconfig")
fs.StringVar(&s.ServiceCatalogAPIServerURL, "service-catalog-api-server-url", "", "The URL for the service-catalog API server")
fs.StringVar(&s.ServiceCatalogKubeconfigPath, "service-catalog-kubeconfig", "", "Path to service-catalog kubeconfig")
fs.BoolVar(&s.ServiceCatalogInsecureSkipVerify, "service-catalog-insecure-skip-verify", s.ServiceCatalogInsecureSkipVerify, "Skip verification of the TLS certificate for the service-catalog API server")
fs.DurationVar(&s.ResyncInterval, "resync-interval", s.ResyncInterval, "The interval on which the controller will resync its informers")
fs.DurationVar(&s.ServiceBrokerRelistInterval, "broker-relist-interval", s.ServiceBrokerRelistInterval, "The interval on which a broker's catalog is relisted after the broker becomes ready")
fs.BoolVar(&s.OSBAPIContextProfile, "enable-osb-api-context-profile", s.OSBAPIContextProfile, "This does nothing.")
fs.MarkHidden("enable-osb-api-context-profile")
fs.StringVar(&s.OSBAPIPreferredVersion, "osb-api-preferred-version", s.OSBAPIPreferredVersion, "The string to send as the version header.")
fs.BoolVar(&s.EnableProfiling, "profiling", s.EnableProfiling, "Enable profiling via web interface host:port/debug/pprof/")
fs.BoolVar(&s.EnableContentionProfiling, "contention-profiling", s.EnableContentionProfiling, "Enable lock contention profiling, if profiling is enabled")
leaderelectionconfig.BindFlags(&s.LeaderElection, fs)
fs.StringVar(&s.LeaderElectionNamespace, "leader-election-namespace", s.LeaderElectionNamespace, "Namespace to use for leader election lock")
fs.DurationVar(&s.ReconciliationRetryDuration, "reconciliation-retry-duration", s.ReconciliationRetryDuration, "The maximum amount of time to retry reconciliations on a resource before failing")
fs.DurationVar(&s.OperationPollingMaximumBackoffDuration, "operation-polling-maximum-backoff-duration", s.OperationPollingMaximumBackoffDuration, "The maximum amount of time to back-off while polling an OSB API operation")
fs.DurationVar(&s.OSBAPITimeOut, "osb-api-request-timeout", s.OSBAPITimeOut, "The maximum amount of timeout to any request to the broker.")
s.SecureServingOptions.AddFlags(fs)
utilfeature.DefaultMutableFeatureGate.AddFlag(fs)
fs.StringVar(&s.ClusterIDConfigMapName, "cluster-id-configmap-name", controller.DefaultClusterIDConfigMapName, "k8s name for clusterid configmap")
fs.StringVar(&s.ClusterIDConfigMapNamespace, "cluster-id-configmap-namespace", controller.DefaultClusterIDConfigMapNamespace, "k8s namespace for clusterid configmap")
}