mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #1550 from sanimej/plumb
Separate service LB & SD from network plumbing
This commit is contained in:
commit
a57efbd6c2
4 changed files with 65 additions and 24 deletions
|
@ -381,7 +381,57 @@ func (n *network) leaveCluster() error {
|
|||
return c.agent.networkDB.LeaveNetwork(n.ID())
|
||||
}
|
||||
|
||||
func (ep *endpoint) addToCluster() error {
|
||||
func (ep *endpoint) addDriverInfoToCluster() error {
|
||||
n := ep.getNetwork()
|
||||
if !n.isClusterEligible() {
|
||||
return nil
|
||||
}
|
||||
if ep.joinInfo == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
ctrlr := n.ctrlr
|
||||
ctrlr.Lock()
|
||||
agent := ctrlr.agent
|
||||
ctrlr.Unlock()
|
||||
if agent == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, te := range ep.joinInfo.driverTableEntries {
|
||||
if err := agent.networkDB.CreateEntry(te.tableName, n.ID(), te.key, te.value); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ep *endpoint) deleteDriverInfoFromCluster() error {
|
||||
n := ep.getNetwork()
|
||||
if !n.isClusterEligible() {
|
||||
return nil
|
||||
}
|
||||
if ep.joinInfo == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
ctrlr := n.ctrlr
|
||||
ctrlr.Lock()
|
||||
agent := ctrlr.agent
|
||||
ctrlr.Unlock()
|
||||
if agent == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, te := range ep.joinInfo.driverTableEntries {
|
||||
if err := agent.networkDB.DeleteEntry(te.tableName, n.ID(), te.key); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ep *endpoint) addServiceInfoToCluster() error {
|
||||
n := ep.getNetwork()
|
||||
if !n.isClusterEligible() {
|
||||
return nil
|
||||
|
@ -421,16 +471,10 @@ func (ep *endpoint) addToCluster() error {
|
|||
}
|
||||
}
|
||||
|
||||
for _, te := range ep.joinInfo.driverTableEntries {
|
||||
if err := c.agent.networkDB.CreateEntry(te.tableName, n.ID(), te.key, te.value); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ep *endpoint) deleteFromCluster() error {
|
||||
func (ep *endpoint) deleteServiceInfoFromCluster() error {
|
||||
n := ep.getNetwork()
|
||||
if !n.isClusterEligible() {
|
||||
return nil
|
||||
|
@ -453,17 +497,6 @@ func (ep *endpoint) deleteFromCluster() error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if ep.joinInfo == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, te := range ep.joinInfo.driverTableEntries {
|
||||
if err := c.agent.networkDB.DeleteEntry(te.tableName, n.ID(), te.key); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -515,6 +515,10 @@ func (ep *endpoint) sbJoin(sb *sandbox, options ...EndpointOption) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err = ep.addDriverInfoToCluster(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if sb.needDefaultGW() && sb.getEndpointInGWNetwork() == nil {
|
||||
return sb.setupDefaultGW()
|
||||
}
|
||||
|
@ -709,8 +713,12 @@ func (ep *endpoint) sbLeave(sb *sandbox, force bool, options ...EndpointOption)
|
|||
return err
|
||||
}
|
||||
|
||||
if e := ep.deleteFromCluster(); e != nil {
|
||||
logrus.Errorf("Could not delete state for endpoint %s from cluster: %v", ep.Name(), e)
|
||||
if e := ep.deleteServiceInfoFromCluster(); e != nil {
|
||||
logrus.Errorf("Could not delete service state for endpoint %s from cluster: %v", ep.Name(), e)
|
||||
}
|
||||
|
||||
if e := ep.deleteDriverInfoFromCluster(); e != nil {
|
||||
logrus.Errorf("Could not delete endpoint state for endpoint %s from cluster: %v", ep.Name(), e)
|
||||
}
|
||||
|
||||
sb.deleteHostsEntries(n.getSvcRecords(ep))
|
||||
|
|
|
@ -265,7 +265,7 @@ func (nDB *NetworkDB) CreateEntry(tname, nid, key string, value []byte) error {
|
|||
}
|
||||
|
||||
if err := nDB.sendTableEvent(TableEventTypeCreate, nid, tname, key, entry); err != nil {
|
||||
return fmt.Errorf("cannot send table create event: %v", err)
|
||||
return fmt.Errorf("cannot send create event for table %s, %v", tname, err)
|
||||
}
|
||||
|
||||
nDB.Lock()
|
||||
|
|
|
@ -670,7 +670,7 @@ func (sb *sandbox) SetKey(basePath string) error {
|
|||
func (sb *sandbox) EnableService() error {
|
||||
for _, ep := range sb.getConnectedEndpoints() {
|
||||
if ep.enableService(true) {
|
||||
if err := ep.addToCluster(); err != nil {
|
||||
if err := ep.addServiceInfoToCluster(); err != nil {
|
||||
ep.enableService(false)
|
||||
return fmt.Errorf("could not update state for endpoint %s into cluster: %v", ep.Name(), err)
|
||||
}
|
||||
|
@ -682,7 +682,7 @@ func (sb *sandbox) EnableService() error {
|
|||
func (sb *sandbox) DisableService() error {
|
||||
for _, ep := range sb.getConnectedEndpoints() {
|
||||
if ep.enableService(false) {
|
||||
if err := ep.deleteFromCluster(); err != nil {
|
||||
if err := ep.deleteServiceInfoFromCluster(); err != nil {
|
||||
ep.enableService(true)
|
||||
return fmt.Errorf("could not delete state for endpoint %s from cluster: %v", ep.Name(), err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue