Skip to content

Commit

Permalink
Fix when virtual server config be removed. (#33)
Browse files Browse the repository at this point in the history
* Fix when virtual server config be removed.

Signed-off-by: huaiyou <huaiyou.cyz@alibaba-inc.com>

* If target ip is nil, skip sync route.

Signed-off-by: huaiyou <huaiyou.cyz@alibaba-inc.com>
  • Loading branch information
VinceCui committed Jul 5, 2022
1 parent 40c1385 commit 51e1809
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
15 changes: 12 additions & 3 deletions care/care.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ func (care *LvsCare) VsAndRsCare() {
for {
select {
case <-t.C:
// in some cases, virtual server maybe removed
isAvailable := care.lvs.IsVirtualServerAvailable(care.VirtualServer)
if !isAvailable {
err := care.lvs.CreateVirtualServer(care.VirtualServer, true)
//virtual server is exists
if err != nil {
glog.Errorf("failed to create virtual server: %v", err)

return
}
}
//check real server
lvs.CheckRealServers(care.HealthPath, care.HealthSchem)
case signa := <-sig:
Expand Down Expand Up @@ -75,8 +86,6 @@ func SetTargetIP() error {
if LVS.TargetIP == nil {
LVS.TargetIP = net.ParseIP(os.Getenv("LVSCARE_NODE_IP"))
}
if LVS.TargetIP == nil {
return errors.New("target ip can't empty")
}

return nil
}
4 changes: 4 additions & 0 deletions cmd/care.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ var careCmd = &cobra.Command{
if err := care.SetTargetIP(); err != nil {
return err
}
// if target ip is empty, skip sync router
if care.LVS.TargetIP == nil {
return nil
}
return care.LVS.SyncRouter()
},
}
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (l *lvscare) CheckRealServers(path, schem string) {
//add it back
ip := realServer.IP
port := strconv.Itoa(int(realServer.Port))
err := l.CreateRealServer(ip+":"+port, false)
err := l.CreateRealServer(net.JoinHostPort(ip, port), false)
if err != nil {
glog.Warningf("CheckRealServers error[add real server failed]: %s; %d; %v ", realServer.IP, realServer.Port, err)
}
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func SplitServer(server string) (string, uint16) {
//IsHTTPAPIHealth is check http error
func IsHTTPAPIHealth(ip, port, path, schem string) bool {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
url := fmt.Sprintf("%s://%s:%s%s", schem, ip, port, path)
url := fmt.Sprintf("%s://%s%s", schem, net.JoinHostPort(ip, port), path)
resp, err := http.Get(url)
if err != nil {
glog.V(8).Infof("IsHTTPAPIHealth error: %v", err)
Expand Down

0 comments on commit 51e1809

Please sign in to comment.