handleConfigUpdate updates the internal structures of a vserver using the new configuration.
(config *config.Vserver)
| 552 | // handleConfigUpdate updates the internal structures of a vserver using the |
| 553 | // new configuration. |
| 554 | func (v *vserver) handleConfigUpdate(config *config.Vserver) { |
| 555 | if config == nil { |
| 556 | return |
| 557 | } |
| 558 | switch { |
| 559 | case v.config == nil: |
| 560 | v.configInit(config) |
| 561 | return |
| 562 | |
| 563 | case v.enabled && !vserverEnabled(config, v.vserverOverride.State()): |
| 564 | log.Infof("%v: disabling vserver", v) |
| 565 | v.downAll() |
| 566 | v.unconfigureVIPs() |
| 567 | v.configInit(config) |
| 568 | return |
| 569 | |
| 570 | case !v.enabled && !vserverEnabled(config, v.vserverOverride.State()): |
| 571 | v.configInit(config) |
| 572 | return |
| 573 | |
| 574 | case !v.enabled && vserverEnabled(config, v.vserverOverride.State()): |
| 575 | log.Infof("%v: enabling vserver", v) |
| 576 | v.configInit(config) |
| 577 | return |
| 578 | |
| 579 | default: |
| 580 | // Some updates require changes to the iptables rules. Since we currently |
| 581 | // can't make fine-grained changes to the iptables rules, we must |
| 582 | // re-initialise the entire vserver. This is necessary in the following |
| 583 | // scenarios: |
| 584 | // - A port or protocol is added, removed or changed |
| 585 | // - A vserver is changed from FWM to non-FWM or vice versa |
| 586 | // - A vserverEntry is changed from DSR to NAT or vice versa |
| 587 | // |
| 588 | // (Changing a VIP address also requires updating iptables, but |
| 589 | // v.configUpdate() handles this case) |
| 590 | // |
| 591 | // TODO(angusc): Add support for finer-grained updates to ncc so we can |
| 592 | // avoid re-initialising the vserver in these cases. |
| 593 | reInit := false |
| 594 | switch { |
| 595 | case config.UseFWM != v.config.UseFWM: |
| 596 | reInit = true |
| 597 | case len(config.Entries) != len(v.config.Entries): |
| 598 | reInit = true |
| 599 | default: |
| 600 | for k, entry := range config.Entries { |
| 601 | if v.config.Entries[k] == nil { |
| 602 | reInit = true |
| 603 | break |
| 604 | } |
| 605 | if v.config.Entries[k].Mode != entry.Mode { |
| 606 | reInit = true |
| 607 | break |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | if reInit { |
no test coverage detected