Skip to content

Commit

Permalink
Fix bug in admission-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
shafeeqes committed May 2, 2022
1 parent 561a9da commit 6cf55e7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
16 changes: 1 addition & 15 deletions vertical-pod-autoscaler/pkg/admission-controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,14 @@ 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"
)

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)
Expand Down
5 changes: 2 additions & 3 deletions vertical-pod-autoscaler/pkg/admission-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6cf55e7

Please sign in to comment.