forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
flags.go
269 lines (242 loc) · 9.8 KB
/
flags.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package openshiftkubeapiserver
import (
"fmt"
"net"
"sort"
"io/ioutil"
"bytes"
configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
configapilatest "github.com/openshift/origin/pkg/cmd/server/apis/config/latest"
originadmission "github.com/openshift/origin/pkg/cmd/server/origin/admission"
"k8s.io/apimachinery/pkg/runtime"
)
func ConfigToFlags(kubeAPIServerConfig *configapi.KubeAPIServerConfig) ([]string, error) {
args := map[string][]string{}
for key, slice := range kubeAPIServerConfig.APIServerArguments {
for _, val := range slice {
args[key] = append(args[key], val)
}
}
host, portString, err := net.SplitHostPort(kubeAPIServerConfig.ServingInfo.BindAddress)
if err != nil {
return nil, err
}
// TODO this list (and the content below) will be used to drive a config struct and a reflective test matching config to flags
// these flags are overridden by a patch
// admission-control
// authentication-token-webhook-cache-ttl
// authentication-token-webhook-config-file
// authorization-mode
// authorization-policy-file
// authorization-webhook-cache-authorized-ttl
// authorization-webhook-cache-unauthorized-ttl
// authorization-webhook-config-file
// basic-auth-file
// enable-aggregator-routing
// enable-bootstrap-token-auth
// oidc-client-id
// oidc-groups-claim
// oidc-groups-prefix
// oidc-issuer-url
// oidc-required-claim
// oidc-signing-algs
// oidc-username-claim
// oidc-username-prefix
// service-account-lookup
// token-auth-file
// alsologtostderr - don't know whether to change it
// apiserver-count - ignored, hopefully we don't have to fix via patch
// cert-dir - ignored because we set certs
// these flags were never supported via config
// cloud-config
// cloud-provider
// cloud-provider-gce-lb-src-cidrs
// contention-profiling
// default-not-ready-toleration-seconds
// default-unreachable-toleration-seconds
// default-watch-cache-size
// delete-collection-workers
// deserialization-cache-size
// enable-garbage-collector
// etcd-compaction-interval
// etcd-count-metric-poll-period
// etcd-servers-overrides
// experimental-encryption-provider-config
// feature-gates
// http2-max-streams-per-connection
// insecure-bind-address
// kubelet-timeout
// log-backtrace-at
// log-dir
// log-flush-frequency
// logtostderr
// master-service-namespace
// max-connection-bytes-per-sec
// profiling
// request-timeout
// runtime-config
// service-account-api-audiences
// service-account-issuer
// service-account-key-file
// service-account-max-token-expiration
// service-account-signing-key-file
// stderrthreshold
// storage-versions
// target-ram-mb
// v
// version
// vmodule
// watch-cache
// watch-cache-sizes
// TODO, we need to set these in order to enable the right admission plugins in each of the servers
// TODO this is needed for a viable cluster up
admissionFlags, err := admissionFlags(kubeAPIServerConfig.AdmissionPluginConfig)
if err != nil {
return nil, err
}
for flag, value := range admissionFlags {
setIfUnset(args, flag, value...)
}
setIfUnset(args, "allow-privileged", "true")
setIfUnset(args, "anonymous-auth", "false")
setIfUnset(args, "authorization-mode", "RBAC", "Node") // overridden later, but this runs the poststarthook for bootstrapping RBAC
for flag, value := range auditFlags(kubeAPIServerConfig) {
setIfUnset(args, flag, value...)
}
setIfUnset(args, "bind-address", host)
setIfUnset(args, "client-ca-file", kubeAPIServerConfig.ServingInfo.ClientCA)
setIfUnset(args, "cors-allowed-origins", kubeAPIServerConfig.CORSAllowedOrigins...)
setIfUnset(args, "enable-logs-handler", "false")
setIfUnset(args, "enable-swagger-ui", "true")
setIfUnset(args, "endpoint-reconciler-type", "lease")
setIfUnset(args, "etcd-cafile", kubeAPIServerConfig.EtcdClientInfo.CA)
setIfUnset(args, "etcd-certfile", kubeAPIServerConfig.EtcdClientInfo.ClientCert.CertFile)
setIfUnset(args, "etcd-keyfile", kubeAPIServerConfig.EtcdClientInfo.ClientCert.KeyFile)
setIfUnset(args, "etcd-prefix", kubeAPIServerConfig.StoragePrefix)
setIfUnset(args, "etcd-servers", kubeAPIServerConfig.EtcdClientInfo.URLs...)
setIfUnset(args, "insecure-port", "0")
setIfUnset(args, "kubelet-certificate-authority", kubeAPIServerConfig.KubeletClientInfo.CA)
setIfUnset(args, "kubelet-client-certificate", kubeAPIServerConfig.KubeletClientInfo.ClientCert.CertFile)
setIfUnset(args, "kubelet-client-key", kubeAPIServerConfig.KubeletClientInfo.ClientCert.KeyFile)
setIfUnset(args, "kubelet-https", "true")
setIfUnset(args, "kubelet-preferred-address-types", "Hostname", "InternalIP", "ExternalIP")
setIfUnset(args, "kubelet-read-only-port", "0")
setIfUnset(args, "kubernetes-service-node-port", "0")
setIfUnset(args, "max-mutating-requests-inflight", fmt.Sprintf("%d", kubeAPIServerConfig.ServingInfo.MaxRequestsInFlight/2))
setIfUnset(args, "max-requests-inflight", fmt.Sprintf("%d", kubeAPIServerConfig.ServingInfo.MaxRequestsInFlight))
setIfUnset(args, "min-request-timeout", fmt.Sprintf("%d", kubeAPIServerConfig.ServingInfo.RequestTimeoutSeconds))
setIfUnset(args, "proxy-client-cert-file", kubeAPIServerConfig.AggregatorConfig.ProxyClientInfo.CertFile)
setIfUnset(args, "proxy-client-key-file", kubeAPIServerConfig.AggregatorConfig.ProxyClientInfo.KeyFile)
setIfUnset(args, "requestheader-allowed-names", kubeAPIServerConfig.AuthConfig.RequestHeader.ClientCommonNames...)
setIfUnset(args, "requestheader-client-ca-file", kubeAPIServerConfig.AuthConfig.RequestHeader.ClientCA)
setIfUnset(args, "requestheader-extra-headers-prefix", kubeAPIServerConfig.AuthConfig.RequestHeader.ExtraHeaderPrefixes...)
setIfUnset(args, "requestheader-group-headers", kubeAPIServerConfig.AuthConfig.RequestHeader.GroupHeaders...)
setIfUnset(args, "requestheader-username-headers", kubeAPIServerConfig.AuthConfig.RequestHeader.UsernameHeaders...)
setIfUnset(args, "secure-port", portString)
setIfUnset(args, "service-cluster-ip-range", kubeAPIServerConfig.ServicesSubnet)
setIfUnset(args, "service-node-port-range", kubeAPIServerConfig.ServicesNodePortRange)
setIfUnset(args, "storage-backend", "etcd3")
setIfUnset(args, "storage-media-type", "application/vnd.kubernetes.protobuf")
setIfUnset(args, "tls-cert-file", kubeAPIServerConfig.ServingInfo.ServerCert.CertFile)
setIfUnset(args, "tls-cipher-suites", kubeAPIServerConfig.ServingInfo.CipherSuites...)
setIfUnset(args, "tls-min-version", kubeAPIServerConfig.ServingInfo.MinTLSVersion)
setIfUnset(args, "tls-private-key-file", kubeAPIServerConfig.ServingInfo.ServerCert.KeyFile)
// TODO re-enable SNI for cluster up
// tls-sni-cert-key
setIfUnset(args, "secure-port", portString)
var keys []string
for key := range args {
keys = append(keys, key)
}
sort.Strings(keys)
var arguments []string
for _, key := range keys {
for _, token := range args[key] {
arguments = append(arguments, fmt.Sprintf("--%s=%v", key, token))
}
}
return arguments, nil
}
// currently for cluster up, audit is just broken.
// TODO fix this
func auditFlags(kubeAPIServerConfig *configapi.KubeAPIServerConfig) map[string][]string {
args := map[string][]string{}
for key, slice := range kubeAPIServerConfig.APIServerArguments {
for _, val := range slice {
args[key] = append(args[key], val)
}
}
return args
}
func setIfUnset(cmdLineArgs map[string][]string, key string, value ...string) {
if _, ok := cmdLineArgs[key]; !ok {
cmdLineArgs[key] = value
}
}
func admissionFlags(admissionPluginConfig map[string]*configapi.AdmissionPluginConfig) (map[string][]string, error) {
args := map[string][]string{}
forceOn := []string{}
forceOff := []string{}
pluginConfig := map[string]*configapi.AdmissionPluginConfig{}
for pluginName, origConfig := range admissionPluginConfig {
config := origConfig.DeepCopy()
if len(config.Location) > 0 {
content, err := ioutil.ReadFile(config.Location)
if err != nil {
return nil, err
}
// if the config isn't a DefaultAdmissionConfig, then assume we're enabled (we were called out after all)
// if the config *is* a DefaultAdmissionConfig and it explicitly said to disable us, we are disabled
obj, err := configapilatest.ReadYAML(bytes.NewBuffer(content))
// if we can't read it, let the plugin deal with it
// if nothing was there, let the plugin deal with it
if err != nil || obj == nil {
forceOn = append(forceOn, pluginName)
config.Location = ""
config.Configuration = &runtime.Unknown{Raw: content}
pluginConfig[pluginName] = config
continue
}
if defaultConfig, ok := obj.(*configapi.DefaultAdmissionConfig); !ok {
forceOn = append(forceOn, pluginName)
config.Location = ""
config.Configuration = &runtime.Unknown{Raw: content}
pluginConfig[pluginName] = config
} else if defaultConfig.Disable {
forceOff = append(forceOff, pluginName)
} else {
forceOn = append(forceOn, pluginName)
}
continue
}
// if it wasn't a DefaultAdmissionConfig object, let the plugin deal with it
if defaultConfig, ok := config.Configuration.(*configapi.DefaultAdmissionConfig); !ok {
forceOn = append(forceOn, pluginName)
pluginConfig[pluginName] = config
} else if defaultConfig.Disable {
forceOff = append(forceOff, pluginName)
} else {
forceOn = append(forceOn, pluginName)
}
}
upstreamAdmissionConfig, err := originadmission.ConvertOpenshiftAdmissionConfigToKubeAdmissionConfig(pluginConfig)
if err != nil {
return nil, err
}
configBytes, err := configapilatest.WriteYAML(upstreamAdmissionConfig)
if err != nil {
return nil, err
}
tempFile, err := ioutil.TempFile("", "kubeapiserver-admission-config.yaml")
if err != nil {
return nil, err
}
if _, err := tempFile.Write(configBytes); err != nil {
return nil, err
}
tempFile.Close()
setIfUnset(args, "admission-control-config-file", tempFile.Name())
setIfUnset(args, "disable-admission-plugins", forceOff...)
setIfUnset(args, "enable-admission-plugins", forceOn...)
return args, nil
}