forked from kubernetes/autoscaler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
133 lines (111 loc) · 5.97 KB
/
config.go
File metadata and controls
133 lines (111 loc) · 5.97 KB
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
/*
Copyright 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.
*/
package config
import (
"flag"
"os"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/api/resource"
kube_flag "k8s.io/component-base/cli/flag"
"k8s.io/klog/v2"
"k8s.io/autoscaler/vertical-pod-autoscaler/common"
"k8s.io/autoscaler/vertical-pod-autoscaler/pkg/features"
)
// CertsConfig holds configuration related to TLS certificates
type CertsConfig struct {
ClientCaFile string
TlsCertFile string
TlsPrivateKey string
Reload bool
}
// AdmissionControllerConfig holds all configuration for the admission controller component
type AdmissionControllerConfig struct {
// Common flags
CommonFlags *common.CommonFlags
CertsConfiguration *CertsConfig
Ciphers string
MinTlsVersion string
Port int
Address string
Namespace string
ServiceName string
WebhookAddress string
WebhookPort string
WebhookTimeout int
WebhookFailurePolicy bool
RegisterWebhook bool
WebhookLabels string
RegisterByURL bool
MaxAllowedCPUBoost resource.QuantityValue
}
// DefaultAdmissionControllerConfig returns a AdmissionControllerConfig with default values
func DefaultAdmissionControllerConfig() *AdmissionControllerConfig {
return &AdmissionControllerConfig{
CommonFlags: common.DefaultCommonConfig(),
CertsConfiguration: &CertsConfig{
ClientCaFile: "/etc/tls-certs/caCert.pem",
TlsCertFile: "/etc/tls-certs/serverCert.pem",
TlsPrivateKey: "/etc/tls-certs/serverKey.pem",
Reload: false,
},
Ciphers: "",
MinTlsVersion: "tls1_2",
Port: 8000,
Address: ":8944",
Namespace: os.Getenv("NAMESPACE"),
ServiceName: "vpa-webhook",
WebhookAddress: "",
WebhookPort: "",
WebhookTimeout: 30,
WebhookFailurePolicy: false,
RegisterWebhook: true,
WebhookLabels: "",
RegisterByURL: false,
MaxAllowedCPUBoost: resource.QuantityValue{},
}
}
// InitAdmissionControllerFlags initializes the flags for the admission controller component
func InitAdmissionControllerFlags() *AdmissionControllerConfig {
config := DefaultAdmissionControllerConfig()
config.CommonFlags = common.InitCommonFlags()
flag.StringVar(&config.CertsConfiguration.ClientCaFile, "client-ca-file", config.CertsConfiguration.ClientCaFile, "Path to CA PEM file.")
flag.StringVar(&config.CertsConfiguration.TlsCertFile, "tls-cert-file", config.CertsConfiguration.TlsCertFile, "Path to server certificate PEM file.")
flag.StringVar(&config.CertsConfiguration.TlsPrivateKey, "tls-private-key", config.CertsConfiguration.TlsPrivateKey, "Path to server certificate key PEM file.")
flag.BoolVar(&config.CertsConfiguration.Reload, "reload-cert", config.CertsConfiguration.Reload, "If set to true, reload leaf and CA certificates when changed.")
flag.StringVar(&config.Ciphers, "tls-ciphers", config.Ciphers, "A comma-separated or colon-separated list of ciphers to accept. Only works when min-tls-version is set to tls1_2.")
flag.StringVar(&config.MinTlsVersion, "min-tls-version", config.MinTlsVersion, "The minimum TLS version to accept. Must be set to either tls1_2 (default) or tls1_3.")
flag.IntVar(&config.Port, "port", config.Port, "The port to listen on.")
flag.StringVar(&config.Address, "address", config.Address, "The address to expose Prometheus metrics.")
flag.StringVar(&config.ServiceName, "webhook-service", config.ServiceName, "Kubernetes service under which webhook is registered. Used when registerByURL is set to false.")
flag.StringVar(&config.WebhookAddress, "webhook-address", config.WebhookAddress, "Address under which webhook is registered. Used when registerByURL is set to true.")
flag.StringVar(&config.WebhookPort, "webhook-port", config.WebhookPort, "Server Port for Webhook")
flag.IntVar(&config.WebhookTimeout, "webhook-timeout-seconds", config.WebhookTimeout, "Timeout in seconds that the API server should wait for this webhook to respond before failing.")
flag.BoolVar(&config.WebhookFailurePolicy, "webhook-failure-policy-fail", config.WebhookFailurePolicy, "If set to true, will configure the admission webhook failurePolicy to \"Fail\". Use with caution.")
flag.BoolVar(&config.RegisterWebhook, "register-webhook", config.RegisterWebhook, "If set to true, admission webhook object will be created on start up to register with the API server.")
flag.StringVar(&config.WebhookLabels, "webhook-labels", config.WebhookLabels, "Comma separated list of labels to add to the webhook object. Format: key1:value1,key2:value2")
flag.BoolVar(&config.RegisterByURL, "register-by-url", config.RegisterByURL, "If set to true, admission webhook will be registered by URL (webhookAddress:webhookPort) instead of by service name")
flag.Var(&config.MaxAllowedCPUBoost, "max-allowed-cpu-boost", "Maximum amount of CPU that will be applied for a container with boost.")
// These need to happen last. kube_flag.InitFlags() synchronizes and parses
// flags from the flag package to pflag, so feature gates must be added to
// pflag before InitFlags() is called.
klog.InitFlags(nil)
common.InitLoggingFlags()
features.MutableFeatureGate.AddFlag(pflag.CommandLine)
kube_flag.InitFlags()
ValidateAdmissionControllerConfig(config)
return config
}
// ValidateAdmissionControllerConfig performs validation of the admission-controller flags
func ValidateAdmissionControllerConfig(config *AdmissionControllerConfig) {
common.ValidateCommonConfig(config.CommonFlags)
}