From 6cf55e778e291e6df1d1d4e2cec2892328a1caea Mon Sep 17 00:00:00 2001 From: Shafeeque E S Date: Mon, 2 May 2022 16:09:48 +0530 Subject: [PATCH] Fix bug in admission-controller --- .../pkg/admission-controller/config.go | 16 +--------------- .../pkg/admission-controller/main.go | 5 ++--- 2 files changed, 3 insertions(+), 18 deletions(-) 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)