mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
fix: add lock in case of rent same ip (#136)
Co-authored-by: 冯才文 <fengcaiwen@buns-macbook-pro.local>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
@@ -15,11 +16,15 @@ import (
|
||||
)
|
||||
|
||||
type dhcpServer struct {
|
||||
sync.Mutex
|
||||
f util.Factory
|
||||
clientset *kubernetes.Clientset
|
||||
}
|
||||
|
||||
func (d *dhcpServer) rentIP(w http.ResponseWriter, r *http.Request) {
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
|
||||
podName := r.Header.Get(config.HeaderPodName)
|
||||
namespace := r.Header.Get(config.HeaderPodNamespace)
|
||||
ctx := context.Background()
|
||||
@@ -42,6 +47,9 @@ func (d *dhcpServer) rentIP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (d *dhcpServer) releaseIP(w http.ResponseWriter, r *http.Request) {
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
|
||||
podName := r.Header.Get(config.HeaderPodName)
|
||||
namespace := r.Header.Get(config.HeaderPodNamespace)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user