Skip to content

Commit

Permalink
Allow vpa-admission-controler to installl on specific path
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat-0 committed Feb 25, 2019
1 parent 0a82f0e commit 916cd53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
18 changes: 10 additions & 8 deletions vertical-pod-autoscaler/pkg/admission-controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func configTLS(clientset *kubernetes.Clientset, serverCert, serverKey []byte) *t

// register this webhook admission controller with the kube-apiserver
// by creating MutatingWebhookConfiguration.
func selfRegistration(clientset *kubernetes.Clientset, caCert []byte, namespace *string) {
func selfRegistration(clientset *kubernetes.Clientset, caCert []byte, namespace *string, url string, registerByURL bool) {
time.Sleep(10 * time.Second)
client := clientset.AdmissionregistrationV1beta1().MutatingWebhookConfigurations()
_, err := client.Get(webhookConfigName, metav1.GetOptions{})
Expand All @@ -91,6 +91,14 @@ func selfRegistration(clientset *kubernetes.Clientset, caCert []byte, namespace
glog.Fatal(err2)
}
}
RegisterClientConfig := v1beta1.WebhookClientConfig{}
if !registerByURL {
RegisterClientConfig.Service.Name = *namespace
RegisterClientConfig.Service.Name = "vpa-webhook"
} else {
RegisterClientConfig.URL = url
}
RegisterClientConfig.CABundle = caCert
webhookConfig := &v1beta1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: webhookConfigName,
Expand All @@ -115,13 +123,7 @@ func selfRegistration(clientset *kubernetes.Clientset, caCert []byte, namespace
Resources: []string{"verticalpodautoscalers"},
},
}},
ClientConfig: v1beta1.WebhookClientConfig{
Service: &v1beta1.ServiceReference{
Namespace: *namespace,
Name: "vpa-webhook",
},
CABundle: caCert,
},
ClientConfig: RegisterClientConfig,
},
},
}
Expand Down
11 changes: 8 additions & 3 deletions vertical-pod-autoscaler/pkg/admission-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"flag"
"fmt"
"net/http"
"os"
"time"
Expand All @@ -41,8 +42,11 @@ var (
tlsPrivateKey: flag.String("tls-private-key", "/etc/tls-certs/serverKey.pem", "Path to server certificate key PEM file."),
}

address = flag.String("address", ":8944", "The address to expose Prometheus metrics.")
namespace = os.Getenv("NAMESPACE")
address = flag.String("address", ":8944", "The address to expose Prometheus metrics.")
namespace = os.Getenv("NAMESPACE")
webhookAddress = flag.String("webhookHostName", "", "Address under which webhook is registered. Used when registerByURL is set to true.")
webhookPort = flag.String("Server Port", "", "Server Port for Webhook")
registerByURL = flag.Bool("registerByURL", false, "If set to true, admission webhook will be registered by URL (webhookAddress:webhookPort) instead of by service name")
)

func newReadyVPALister(stopChannel <-chan struct{}) vpa_lister.VerticalPodAutoscalerLister {
Expand Down Expand Up @@ -75,6 +79,7 @@ func main() {
Addr: ":8000",
TLSConfig: configTLS(clientset, certs.serverCert, certs.serverKey),
}
go selfRegistration(clientset, certs.caCert, &namespace)
url := fmt.Sprintf("%v:%v", webhookAddress, webhookPort)
go selfRegistration(clientset, certs.caCert, &namespace, url, *registerByURL)
server.ListenAndServeTLS("", "")
}

0 comments on commit 916cd53

Please sign in to comment.