mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
feat: use api to get and release ip
This commit is contained in:
@@ -55,7 +55,7 @@ func (d *dhcpServer) releaseIP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Infof("handling rent ip request, pod name: %s, ns: %s", podName, namespace)
|
||||
log.Infof("handling release ip request, pod name: %s, ns: %s", podName, namespace)
|
||||
clientset, err := d.f.KubernetesClientSet()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
|
||||
@@ -11,9 +11,10 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
v1 "k8s.io/api/admission/v1"
|
||||
"k8s.io/api/admission/v1beta1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/pkg/config"
|
||||
)
|
||||
|
||||
// admissionReviewHandler is a handler to handle business logic, holding an util.Factory
|
||||
@@ -123,17 +124,17 @@ func serve(w http.ResponseWriter, r *http.Request, admit admitHandler) {
|
||||
func Main(f cmdutil.Factory) error {
|
||||
h := &admissionReviewHandler{f: f}
|
||||
http.HandleFunc("/pods", func(w http.ResponseWriter, r *http.Request) { serve(w, r, newDelegateToV1AdmitHandler(h.admitPods)) })
|
||||
http.HandleFunc("/readyz", func(w http.ResponseWriter, req *http.Request) { _, _ = w.Write([]byte("ok")) })
|
||||
http.HandleFunc("/readyz", func(w http.ResponseWriter, req *http.Request) { w.Write([]byte("ok")) })
|
||||
s := dhcpServer{f: f}
|
||||
http.HandleFunc("/rent/ip", s.rentIP)
|
||||
http.HandleFunc("/release/ip", s.releaseIP)
|
||||
cert, ok := os.LookupEnv(corev1.TLSCertKey)
|
||||
http.HandleFunc(config.APIRentIP, s.rentIP)
|
||||
http.HandleFunc(config.APIReleaseIP, s.releaseIP)
|
||||
cert, ok := os.LookupEnv(config.TLSCertKey)
|
||||
if !ok {
|
||||
return fmt.Errorf("can not get %s from env", corev1.TLSCertKey)
|
||||
return fmt.Errorf("can not get %s from env", config.TLSCertKey)
|
||||
}
|
||||
key, ok := os.LookupEnv(corev1.TLSPrivateKeyKey)
|
||||
key, ok := os.LookupEnv(config.TLSPrivateKeyKey)
|
||||
if !ok {
|
||||
return fmt.Errorf("can not get %s from env", corev1.TLSPrivateKeyKey)
|
||||
return fmt.Errorf("can not get %s from env", config.TLSPrivateKeyKey)
|
||||
}
|
||||
pair, err := tls.X509KeyPair([]byte(cert), []byte(key))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user