diff --git a/vertical-pod-autoscaler/pkg/admission-controller/config.go b/vertical-pod-autoscaler/pkg/admission-controller/config.go index d702c046e53..949909876ef 100644 --- a/vertical-pod-autoscaler/pkg/admission-controller/config.go +++ b/vertical-pod-autoscaler/pkg/admission-controller/config.go @@ -24,7 +24,6 @@ import ( admissionregistration "k8s.io/api/admissionregistration/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" "k8s.io/klog/v2" ) @@ -32,20 +31,7 @@ const ( webhookConfigName = "vpa-webhook-config" ) -// get a clientset with in-cluster config. -func getClient() *kubernetes.Clientset { - config, err := rest.InClusterConfig() - if err != nil { - klog.Fatal(err) - } - clientset, err := kubernetes.NewForConfig(config) - if err != nil { - klog.Fatal(err) - } - return clientset -} - -func configTLS(clientset *kubernetes.Clientset, serverCert, serverKey []byte) *tls.Config { +func configTLS(serverCert, serverKey []byte) *tls.Config { sCert, err := tls.X509KeyPair(serverCert, serverKey) if err != nil { klog.Fatal(err) diff --git a/vertical-pod-autoscaler/pkg/admission-controller/main.go b/vertical-pod-autoscaler/pkg/admission-controller/main.go index 12a385cd6c0..f3b3c2a1751 100644 --- a/vertical-pod-autoscaler/pkg/admission-controller/main.go +++ b/vertical-pod-autoscaler/pkg/admission-controller/main.go @@ -123,15 +123,14 @@ func main() { as.Serve(w, r) healthCheck.UpdateLastActivity() }) - clientset := getClient() server := &http.Server{ Addr: fmt.Sprintf(":%d", *port), - TLSConfig: configTLS(clientset, certs.serverCert, certs.serverKey), + TLSConfig: configTLS(certs.serverCert, certs.serverKey), } url := fmt.Sprintf("%v:%v", *webhookAddress, *webhookPort) go func() { if *registerWebhook { - selfRegistration(clientset, certs.caCert, namespace, *serviceName, url, *registerByURL, int32(*webhookTimeout)) + selfRegistration(kubeClient, certs.caCert, namespace, *serviceName, url, *registerByURL, int32(*webhookTimeout)) } // Start status updates after the webhook is initialized. statusUpdater.Run(stopCh)