diff --git a/vertical-pod-autoscaler/pkg/admission-controller/config.go b/vertical-pod-autoscaler/pkg/admission-controller/config.go index 9a18b032beee..06b5ad879038 100644 --- a/vertical-pod-autoscaler/pkg/admission-controller/config.go +++ b/vertical-pod-autoscaler/pkg/admission-controller/config.go @@ -90,8 +90,8 @@ func configTLS(cfg certsConfig, minTlsVersion, ciphers string, stop <-chan struc // register this webhook admission controller with the kube-apiserver // by creating MutatingWebhookConfiguration. -func selfRegistration(clientset kubernetes.Interface, caCert []byte, namespace, serviceName, url string, registerByURL bool, timeoutSeconds int32, selectedNamespace string, ignoredNamespaces []string) { - time.Sleep(10 * time.Second) +func selfRegistration(clientset kubernetes.Interface, caCert []byte, webHookDelay time.Duration, namespace, serviceName, url string, registerByURL bool, timeoutSeconds int32, selectedNamespace string, ignoredNamespaces []string) { + time.Sleep(webHookDelay) client := clientset.AdmissionregistrationV1().MutatingWebhookConfigurations() _, err := client.Get(context.TODO(), webhookConfigName, metav1.GetOptions{}) if err == nil { diff --git a/vertical-pod-autoscaler/pkg/admission-controller/config_test.go b/vertical-pod-autoscaler/pkg/admission-controller/config_test.go index 857bab45110c..8f91eadad92d 100644 --- a/vertical-pod-autoscaler/pkg/admission-controller/config_test.go +++ b/vertical-pod-autoscaler/pkg/admission-controller/config_test.go @@ -19,6 +19,7 @@ package main import ( "context" "testing" + "time" "github.com/stretchr/testify/assert" admissionregistration "k8s.io/api/admissionregistration/v1" @@ -30,6 +31,7 @@ func TestSelfRegistrationBase(t *testing.T) { testClientSet := fake.NewSimpleClientset() caCert := []byte("fake") + webHookDelay := 0 * time.Second namespace := "default" serviceName := "vpa-service" url := "http://example.com/" @@ -38,7 +40,7 @@ func TestSelfRegistrationBase(t *testing.T) { selectedNamespace := "" ignoredNamespaces := []string{} - selfRegistration(testClientSet, caCert, namespace, serviceName, url, registerByURL, timeoutSeconds, selectedNamespace, ignoredNamespaces) + selfRegistration(testClientSet, caCert, webHookDelay, namespace, serviceName, url, registerByURL, timeoutSeconds, selectedNamespace, ignoredNamespaces) webhookConfigInterface := testClientSet.AdmissionregistrationV1().MutatingWebhookConfigurations() webhookConfig, err := webhookConfigInterface.Get(context.TODO(), webhookConfigName, metav1.GetOptions{}) @@ -72,6 +74,7 @@ func TestSelfRegistrationWithURL(t *testing.T) { testClientSet := fake.NewSimpleClientset() caCert := []byte("fake") + webHookDelay := 0 * time.Second namespace := "default" serviceName := "vpa-service" url := "http://example.com/" @@ -80,7 +83,7 @@ func TestSelfRegistrationWithURL(t *testing.T) { selectedNamespace := "" ignoredNamespaces := []string{} - selfRegistration(testClientSet, caCert, namespace, serviceName, url, registerByURL, timeoutSeconds, selectedNamespace, ignoredNamespaces) + selfRegistration(testClientSet, caCert, webHookDelay, namespace, serviceName, url, registerByURL, timeoutSeconds, selectedNamespace, ignoredNamespaces) webhookConfigInterface := testClientSet.AdmissionregistrationV1().MutatingWebhookConfigurations() webhookConfig, err := webhookConfigInterface.Get(context.TODO(), webhookConfigName, metav1.GetOptions{}) @@ -99,6 +102,7 @@ func TestSelfRegistrationWithOutURL(t *testing.T) { testClientSet := fake.NewSimpleClientset() caCert := []byte("fake") + webHookDelay := 0 * time.Second namespace := "default" serviceName := "vpa-service" url := "http://example.com/" @@ -107,7 +111,7 @@ func TestSelfRegistrationWithOutURL(t *testing.T) { selectedNamespace := "" ignoredNamespaces := []string{} - selfRegistration(testClientSet, caCert, namespace, serviceName, url, registerByURL, timeoutSeconds, selectedNamespace, ignoredNamespaces) + selfRegistration(testClientSet, caCert, webHookDelay, namespace, serviceName, url, registerByURL, timeoutSeconds, selectedNamespace, ignoredNamespaces) webhookConfigInterface := testClientSet.AdmissionregistrationV1().MutatingWebhookConfigurations() webhookConfig, err := webhookConfigInterface.Get(context.TODO(), webhookConfigName, metav1.GetOptions{}) @@ -128,6 +132,7 @@ func TestSelfRegistrationWithIgnoredNamespaces(t *testing.T) { testClientSet := fake.NewSimpleClientset() caCert := []byte("fake") + webHookDelay := 0 * time.Second namespace := "default" serviceName := "vpa-service" url := "http://example.com/" @@ -136,7 +141,7 @@ func TestSelfRegistrationWithIgnoredNamespaces(t *testing.T) { selectedNamespace := "" ignoredNamespaces := []string{"test"} - selfRegistration(testClientSet, caCert, namespace, serviceName, url, registerByURL, timeoutSeconds, selectedNamespace, ignoredNamespaces) + selfRegistration(testClientSet, caCert, webHookDelay, namespace, serviceName, url, registerByURL, timeoutSeconds, selectedNamespace, ignoredNamespaces) webhookConfigInterface := testClientSet.AdmissionregistrationV1().MutatingWebhookConfigurations() webhookConfig, err := webhookConfigInterface.Get(context.TODO(), webhookConfigName, metav1.GetOptions{}) @@ -158,6 +163,7 @@ func TestSelfRegistrationWithSelectedNamespaces(t *testing.T) { testClientSet := fake.NewSimpleClientset() caCert := []byte("fake") + webHookDelay := 0 * time.Second namespace := "default" serviceName := "vpa-service" url := "http://example.com/" @@ -166,7 +172,7 @@ func TestSelfRegistrationWithSelectedNamespaces(t *testing.T) { selectedNamespace := "test" ignoredNamespaces := []string{} - selfRegistration(testClientSet, caCert, namespace, serviceName, url, registerByURL, timeoutSeconds, selectedNamespace, ignoredNamespaces) + selfRegistration(testClientSet, caCert, webHookDelay, namespace, serviceName, url, registerByURL, timeoutSeconds, selectedNamespace, ignoredNamespaces) webhookConfigInterface := testClientSet.AdmissionregistrationV1().MutatingWebhookConfigurations() webhookConfig, err := webhookConfigInterface.Get(context.TODO(), webhookConfigName, metav1.GetOptions{}) diff --git a/vertical-pod-autoscaler/pkg/admission-controller/main.go b/vertical-pod-autoscaler/pkg/admission-controller/main.go index 21ee935dc1a3..a0fe4f678ce0 100644 --- a/vertical-pod-autoscaler/pkg/admission-controller/main.go +++ b/vertical-pod-autoscaler/pkg/admission-controller/main.go @@ -52,6 +52,7 @@ const ( scaleCacheEntryLifetime time.Duration = time.Hour scaleCacheEntryFreshnessTime time.Duration = 10 * time.Minute scaleCacheEntryJitterFactor float64 = 1. + webHookDelay = 10 * time.Second ) var ( @@ -145,7 +146,7 @@ func main() { ignoredNamespaces := strings.Split(*ignoredVpaObjectNamespaces, ",") go func() { if *registerWebhook { - selfRegistration(kubeClient, readFile(*certsConfiguration.clientCaFile), namespace, *serviceName, url, *registerByURL, int32(*webhookTimeout), *vpaObjectNamespace, ignoredNamespaces) + 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)