-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to ignore namespaces #6788
Merged
k8s-ci-robot
merged 25 commits into
kubernetes:master
from
adrianmoisey:vpa-ignore-namespace
Jul 15, 2024
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
e23e769
gcp: fix unsafe webhook vpa-webhook-config
britslampe b5bdba3
Fix operator value
britslampe 81ab072
wrap namespaceSelector values for admission-controller with a flag
britslampe 6474581
Merge branch 'master' into master
britslampe a5f6d01
Merge remote-tracking branch 'britdm/master' into vpa-ignore-namespace
adrianmoisey 2d38ced
Add "ignored-vpa-object-namespaces"
adrianmoisey cfb625e
Rename the option in the admission-controller for consistency
adrianmoisey 3e4cc78
Move README comment to the toplevel readme
adrianmoisey 5cca0cc
Add the new example to the index
adrianmoisey 9e9ca33
Don't pass around pointers
adrianmoisey 590b4fc
Move error log to below startup log
adrianmoisey cef6dcb
Make namespaceSelector empty when the list of namespaces is empty
adrianmoisey 4073194
Allow webhook to select namespaces
adrianmoisey af33e13
Use build in 'contains'
adrianmoisey 8d2bbb8
Merge master
adrianmoisey 1b36617
Add tests
adrianmoisey 6b73976
Merge master
adrianmoisey ee9d626
Use slices.Contains
adrianmoisey a8a16a4
Be more explicit about the flags
adrianmoisey 7a1aea1
Pass around comma separate strings rather than lists
adrianmoisey e14db24
selectedNamespace contains a single namespace
adrianmoisey a7f2c93
Revert "Pass around comma separate strings rather than lists"
adrianmoisey 7e19ebe
Revert unintentional change
adrianmoisey edc8091
Remove hardcoded 10 second delay
adrianmoisey 74e7c5f
Merge master
adrianmoisey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ import ( | |
"fmt" | ||
"net/http" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
apiv1 "k8s.io/api/core/v1" | ||
|
@@ -51,6 +52,7 @@ const ( | |
scaleCacheEntryLifetime time.Duration = time.Hour | ||
scaleCacheEntryFreshnessTime time.Duration = 10 * time.Minute | ||
scaleCacheEntryJitterFactor float64 = 1. | ||
webHookDelay = 10 * time.Second | ||
) | ||
|
||
var ( | ||
|
@@ -63,26 +65,31 @@ var ( | |
ciphers = flag.String("tls-ciphers", "", "A comma-separated or colon-separated list of ciphers to accept. Only works when min-tls-version is set to tls1_2.") | ||
minTlsVersion = flag.String("min-tls-version", "tls1_2", "The minimum TLS version to accept. Must be set to either tls1_2 (default) or tls1_3.") | ||
|
||
port = flag.Int("port", 8000, "The port to listen on.") | ||
address = flag.String("address", ":8944", "The address to expose Prometheus metrics.") | ||
kubeconfig = flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.") | ||
kubeApiQps = flag.Float64("kube-api-qps", 5.0, `QPS limit when making requests to Kubernetes apiserver`) | ||
kubeApiBurst = flag.Float64("kube-api-burst", 10.0, `QPS burst limit when making requests to Kubernetes apiserver`) | ||
namespace = os.Getenv("NAMESPACE") | ||
serviceName = flag.String("webhook-service", "vpa-webhook", "Kubernetes service under which webhook is registered. Used when registerByURL is set to false.") | ||
webhookAddress = flag.String("webhook-address", "", "Address under which webhook is registered. Used when registerByURL is set to true.") | ||
webhookPort = flag.String("webhook-port", "", "Server Port for Webhook") | ||
webhookTimeout = flag.Int("webhook-timeout-seconds", 30, "Timeout in seconds that the API server should wait for this webhook to respond before failing.") | ||
registerWebhook = flag.Bool("register-webhook", true, "If set to true, admission webhook object will be created on start up to register with the API server.") | ||
registerByURL = flag.Bool("register-by-url", false, "If set to true, admission webhook will be registered by URL (webhookAddress:webhookPort) instead of by service name") | ||
vpaObjectNamespace = flag.String("vpa-object-namespace", apiv1.NamespaceAll, "Namespace to search for VPA objects. Empty means all namespaces will be used.") | ||
port = flag.Int("port", 8000, "The port to listen on.") | ||
address = flag.String("address", ":8944", "The address to expose Prometheus metrics.") | ||
kubeconfig = flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.") | ||
kubeApiQps = flag.Float64("kube-api-qps", 5.0, `QPS limit when making requests to Kubernetes apiserver`) | ||
kubeApiBurst = flag.Float64("kube-api-burst", 10.0, `QPS burst limit when making requests to Kubernetes apiserver`) | ||
namespace = os.Getenv("NAMESPACE") | ||
serviceName = flag.String("webhook-service", "vpa-webhook", "Kubernetes service under which webhook is registered. Used when registerByURL is set to false.") | ||
webhookAddress = flag.String("webhook-address", "", "Address under which webhook is registered. Used when registerByURL is set to true.") | ||
webhookPort = flag.String("webhook-port", "", "Server Port for Webhook") | ||
webhookTimeout = flag.Int("webhook-timeout-seconds", 30, "Timeout in seconds that the API server should wait for this webhook to respond before failing.") | ||
registerWebhook = flag.Bool("register-webhook", true, "If set to true, admission webhook object will be created on start up to register with the API server.") | ||
registerByURL = flag.Bool("register-by-url", false, "If set to true, admission webhook will be registered by URL (webhookAddress:webhookPort) instead of by service name") | ||
vpaObjectNamespace = flag.String("vpa-object-namespace", apiv1.NamespaceAll, "Namespace to search for VPA objects. Empty means all namespaces will be used. Must not be used if ignored-vpa-object-namespaces is set.") | ||
ignoredVpaObjectNamespaces = flag.String("ignored-vpa-object-namespaces", "", "Comma separated list of namespaces to ignore. Must not be used if vpa-object-namespace is used.") | ||
) | ||
|
||
func main() { | ||
klog.InitFlags(nil) | ||
kube_flag.InitFlags() | ||
klog.V(1).Infof("Vertical Pod Autoscaler %s Admission Controller", common.VerticalPodAutoscalerVersion) | ||
|
||
if len(*vpaObjectNamespace) > 0 && len(*ignoredVpaObjectNamespaces) > 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably happen after the info log below to still give a log about the version used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 590b4fc |
||
klog.Fatalf("--vpa-object-namespace and --ignored-vpa-object-namespaces are mutually exclusive and can't be set together.") | ||
} | ||
|
||
healthCheck := metrics.NewHealthCheck(time.Minute) | ||
metrics.Initialize(*address, healthCheck) | ||
metrics_admission.Register() | ||
|
@@ -136,9 +143,10 @@ func main() { | |
TLSConfig: configTLS(*certsConfiguration, *minTlsVersion, *ciphers, stopCh), | ||
} | ||
url := fmt.Sprintf("%v:%v", *webhookAddress, *webhookPort) | ||
ignoredNamespaces := strings.Split(*ignoredVpaObjectNamespaces, ",") | ||
go func() { | ||
if *registerWebhook { | ||
selfRegistration(kubeClient, readFile(*certsConfiguration.clientCaFile), namespace, *serviceName, url, *registerByURL, int32(*webhookTimeout)) | ||
selfRegistration(kubeClient, readFile(*certsConfiguration.clientCaFile), webHookDelay, namespace, *serviceName, url, *registerByURL, int32(*webhookTimeout), *vpaObjectNamespace, ignoredNamespaces) | ||
} | ||
// Start status updates after the webhook is initialized. | ||
statusUpdater.Run(stopCh) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we also be setting a nameSpaceSelector for the case where vpa-object-namespace is used to cause the webhook to operate only for that namespace? This way the pods for all other namespaces do not have to wait for an answer from the admission controller before they start (it will also reduce the load on the admission controller)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
Fixed in 4073194