Skip to content

Commit bc5c4a5

Browse files
committed
Allow custom timeout value for webhook calls
Because webhooks add to API request latency, they should evaluate as quickly as possible. timeoutSeconds allows configuring how long the API server should wait for a webhook to respond before treating the call as a failure. The default values from Kubernetes are, however, too large. For admissionregistration.k8s.io/v1 the default value is 10 seconds while for admissionregistration.k8s.io/v1beta1 is 30 seconds. We keep 30 seconds as this was the original unconfigurable value. Signed-off-by: Renan Gonçalves <[email protected]>
1 parent b774e57 commit bc5c4a5

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

vertical-pod-autoscaler/pkg/admission-controller/config.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func configTLS(clientset *kubernetes.Clientset, serverCert, serverKey []byte) *t
5757

5858
// register this webhook admission controller with the kube-apiserver
5959
// by creating MutatingWebhookConfiguration.
60-
func selfRegistration(clientset *kubernetes.Clientset, caCert []byte, namespace, serviceName, url string, registerByURL bool) {
60+
func selfRegistration(clientset *kubernetes.Clientset, caCert []byte, namespace, serviceName, url string, registerByURL bool, timeoutSeconds int32) {
6161
time.Sleep(10 * time.Second)
6262
client := clientset.AdmissionregistrationV1().MutatingWebhookConfigurations()
6363
_, err := client.Get(context.TODO(), webhookConfigName, metav1.GetOptions{})
@@ -104,9 +104,10 @@ func selfRegistration(clientset *kubernetes.Clientset, caCert []byte, namespace,
104104
},
105105
},
106106
},
107-
FailurePolicy: &failurePolicy,
108-
ClientConfig: RegisterClientConfig,
109-
SideEffects: &sideEffects,
107+
FailurePolicy: &failurePolicy,
108+
ClientConfig: RegisterClientConfig,
109+
SideEffects: &sideEffects,
110+
TimeoutSeconds: &timeoutSeconds,
110111
},
111112
},
112113
}

vertical-pod-autoscaler/pkg/admission-controller/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ var (
6363
serviceName = flag.String("webhook-service", "vpa-webhook", "Kubernetes service under which webhook is registered. Used when registerByURL is set to false.")
6464
webhookAddress = flag.String("webhook-address", "", "Address under which webhook is registered. Used when registerByURL is set to true.")
6565
webhookPort = flag.String("webhook-port", "", "Server Port for Webhook")
66+
webhookTimeout = flag.Int("webhook-timeout-seconds", 30, "Timeout in seconds that the API server should wait for this webhook to respond before failing.")
6667
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.")
6768
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")
6869
vpaObjectNamespace = flag.String("vpa-object-namespace", apiv1.NamespaceAll, "Namespace to search for VPA objects. Empty means all namespaces will be used.")
@@ -133,7 +134,7 @@ func main() {
133134
url := fmt.Sprintf("%v:%v", *webhookAddress, *webhookPort)
134135
go func() {
135136
if *registerWebhook {
136-
selfRegistration(clientset, certs.caCert, namespace, *serviceName, url, *registerByURL)
137+
selfRegistration(clientset, certs.caCert, namespace, *serviceName, url, *registerByURL, int32(*webhookTimeout))
137138
}
138139
// Start status updates after the webhook is initialized.
139140
statusUpdater.Run(stopCh)

0 commit comments

Comments
 (0)