configUpdate updates the services, destinations, checks, and VIPs for a vserver.
()
| 650 | // configUpdate updates the services, destinations, checks, and VIPs for a |
| 651 | // vserver. |
| 652 | func (v *vserver) configUpdate() { |
| 653 | newSvcs := v.expandServices() |
| 654 | for svcKey, newSvc := range newSvcs { |
| 655 | if svc, ok := v.services[svcKey]; ok { |
| 656 | if svc.ip.Equal(newSvc.ip) { |
| 657 | svc.update(newSvc) |
| 658 | continue |
| 659 | } |
| 660 | log.Infof("%v: service %v: new IP address: %v", v, svc, newSvc.ip) |
| 661 | v.deleteService(svc) |
| 662 | } |
| 663 | log.Infof("%v: adding new service: %v", v, newSvc) |
| 664 | v.services[svcKey] = newSvc |
| 665 | v.updateState(newSvc.ip) |
| 666 | } |
| 667 | |
| 668 | for svcKey, svc := range v.services { |
| 669 | if newSvcs[svcKey] == nil { |
| 670 | // Service no longer exists |
| 671 | v.deleteService(svc) |
| 672 | continue |
| 673 | } |
| 674 | |
| 675 | // Update destinations for this service |
| 676 | newDests := v.expandDests(svc) |
| 677 | for destKey, newDest := range newDests { |
| 678 | if dest, ok := svc.dests[destKey]; ok { |
| 679 | dest.update(newDest) |
| 680 | continue |
| 681 | } |
| 682 | log.Infof("%v: service %v: adding new destination: %v", v, svc, newDest) |
| 683 | svc.dests[destKey] = newDest |
| 684 | } |
| 685 | |
| 686 | for destKey, dest := range svc.dests { |
| 687 | if newDests[destKey] == nil { |
| 688 | // Destination no longer exists |
| 689 | if dest.active { |
| 690 | dest.healthy = false |
| 691 | svc.updateState() |
| 692 | } |
| 693 | log.Infof("%v: service %v: deleting destination: %v", v, svc, dest) |
| 694 | delete(svc.dests, destKey) |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | // If a VIP has been re-IP'd or has no services configured, remove the old |
| 700 | // VIP from the interface. |
| 701 | needVIPs := make(map[seesaw.IP]bool) |
| 702 | for _, svc := range v.services { |
| 703 | needVIPs[svc.ip] = true |
| 704 | } |
| 705 | for vip := range v.vips { |
| 706 | if !needVIPs[vip.IP] { |
| 707 | log.Infof("%v: unconfiguring no longer needed VIP %v", v, vip.IP) |
| 708 | v.unconfigureVIP(&vip) |
| 709 | } |
no test coverage detected