4 Commits

Author SHA1 Message Date
Mayuresh Gaitonde
a99f92e9a5 fix 2021-10-18 18:21:01 -07:00
Mayuresh Gaitonde
5ac02c373b dockerfile fix 2021-10-18 18:16:22 -07:00
Mayuresh Gaitonde
6fdff28716 fix the deadlock 2021-10-18 15:50:13 -07:00
mayuresh82
e32ff1d52c Merge pull request #8 from mayuresh82/vip_config
Add ability to specify vip parameters
2021-05-14 09:35:05 -07:00
3 changed files with 14 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
FROM golang:alpine as builder FROM golang:1.14-alpine as builder
RUN apk update && \ RUN apk update && \
apk upgrade && \ apk upgrade && \
apk add --no-cache git && \ apk add --no-cache git && \

View File

@@ -69,7 +69,8 @@ type MonitorMgr struct {
ctrl *Controller ctrl *Controller
consul *ConsulMon consul *ConsulMon
sync.Mutex monMu sync.Mutex
clMu sync.Mutex
} }
func NewMonitor(config *c.Config) *MonitorMgr { func NewMonitor(config *c.Config) *MonitorMgr {
@@ -123,7 +124,7 @@ func (m *MonitorMgr) consulMon() {
} }
// remove currently running apps that are not discovered in this pass // remove currently running apps that are not discovered in this pass
var toRemove []string var toRemove []string
m.Lock() m.monMu.Lock()
for name, mon := range m.monitors { for name, mon := range m.monitors {
if mon.app.Source != "consul" { if mon.app.Source != "consul" {
continue continue
@@ -140,10 +141,10 @@ func (m *MonitorMgr) consulMon() {
toRemove = append(toRemove, name) toRemove = append(toRemove, name)
} }
} }
m.monMu.Unlock()
for _, tr := range toRemove { for _, tr := range toRemove {
m.Remove(tr) m.Remove(tr)
} }
m.Unlock()
} }
<-time.After(m.config.Agent.ConsulQueryInterval) <-time.After(m.config.Agent.ConsulQueryInterval)
} }
@@ -152,18 +153,20 @@ func (m *MonitorMgr) consulMon() {
// Add adds a new app into monitor manager // Add adds a new app into monitor manager
func (m *MonitorMgr) Add(app *App) { func (m *MonitorMgr) Add(app *App) {
// check if already running // check if already running
m.Lock() m.monMu.Lock()
defer m.Unlock()
for _, appMon := range m.monitors { for _, appMon := range m.monitors {
if appMon.app.Equal(app) && appMon.checkOn { if appMon.app.Equal(app) && appMon.checkOn {
glog.V(2).Infof("App %s already exists", app.Name) glog.V(2).Infof("App %s already exists", app.Name)
m.monMu.Unlock()
return return
} }
if appMon.app.Vip.Net.String() == app.Vip.Net.String() && appMon.app.Name != app.Name { if appMon.app.Vip.Net.String() == app.Vip.Net.String() && appMon.app.Name != app.Name {
glog.Errorf("Error: Vip %s is already being announced by app: %s", app.Vip.Net.String(), appMon.app.Name) glog.Errorf("Error: Vip %s is already being announced by app: %s", app.Vip.Net.String(), appMon.app.Name)
m.monMu.Unlock()
return return
} }
} }
m.monMu.Unlock()
m.Remove(app.Name) m.Remove(app.Name)
appMon := &appMon{app: app, done: make(chan bool)} appMon := &appMon{app: app, done: make(chan bool)}
m.monitors[app.Name] = appMon m.monitors[app.Name] = appMon
@@ -174,6 +177,8 @@ func (m *MonitorMgr) Add(app *App) {
// Remove removes an app from monitor manager, stops BGP // Remove removes an app from monitor manager, stops BGP
/// announcement and cleans up state /// announcement and cleans up state
func (m *MonitorMgr) Remove(appName string) { func (m *MonitorMgr) Remove(appName string) {
m.monMu.Lock()
defer m.monMu.Unlock()
if a, ok := m.monitors[appName]; ok { if a, ok := m.monitors[appName]; ok {
if a.checkOn { if a.checkOn {
a.done <- true a.done <- true
@@ -223,8 +228,8 @@ func (m *MonitorMgr) runMonitors(app *App) bool {
func (m *MonitorMgr) checkCond(am *appMon) error { func (m *MonitorMgr) checkCond(am *appMon) error {
app := am.app app := am.app
m.Lock() m.clMu.Lock()
defer m.Unlock() defer m.clMu.Unlock()
if m.runMonitors(app) { if m.runMonitors(app) {
glog.V(2).Infof("All Monitors for app: %s succeeded", app.Name) glog.V(2).Infof("All Monitors for app: %s succeeded", app.Name)
if !am.announced { if !am.announced {
@@ -246,6 +251,7 @@ func (m *MonitorMgr) checkCond(am *appMon) error {
am.announced = true am.announced = true
if exit, ok := m.cleanups[app.Name]; ok { if exit, ok := m.cleanups[app.Name]; ok {
exit <- true exit <- true
delete(m.cleanups, app.Name)
} }
} }
} else { } else {
@@ -313,9 +319,7 @@ func (m *MonitorMgr) Cleanup(app string, exit chan bool) {
select { select {
case <-t.C: case <-t.C:
glog.Infof("Cleaning up app %s", app) glog.Infof("Cleaning up app %s", app)
m.Lock()
m.Remove(app) m.Remove(app)
m.Unlock()
case <-exit: case <-exit:
return return
} }

View File

@@ -68,9 +68,7 @@ func (s *Server) unregisterHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Invalid request, need app name specified", http.StatusBadRequest) http.Error(w, "Invalid request, need app name specified", http.StatusBadRequest)
return return
} }
s.mon.Lock()
s.mon.Remove(appName[0]) s.mon.Remove(appName[0])
s.mon.Unlock()
} }
func (s *Server) infoHandler(w http.ResponseWriter, r *http.Request) { func (s *Server) infoHandler(w http.ResponseWriter, r *http.Request) {