Browse Source

zones: allow RingInfo.Merge() to enable, but not disable

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/1/head
Alejandro Mery 1 year ago
parent
commit
975e166da7
  1. 15
      pkg/zones/rings.go

15
pkg/zones/rings.go

@ -31,9 +31,9 @@ func (ri *RingInfo) Merge(alter *RingInfo) error {
case ri.Ring != alter.Ring:
// different ring
return fmt.Errorf("invalid %s: %v ≠ %v", "ring", ri.Ring, alter.Ring)
case ri.Enabled != alter.Enabled:
// different state
return fmt.Errorf("invalid %s: %v %v", "enabled", ri.Enabled, alter.Enabled)
case ri.Enabled && !alter.Enabled:
// can't disable via Merge
return fmt.Errorf("invalid %s: %v %v", "enabled", ri.Enabled, alter.Enabled)
case !canMergeAddress(ri.Address, alter.Address):
// different address
return fmt.Errorf("invalid %s: %v ≠ %v", "address", ri.Address, alter.Address)
@ -42,6 +42,15 @@ func (ri *RingInfo) Merge(alter *RingInfo) error {
return fmt.Errorf("invalid %s: %s ≠ %s", "keys", ri.Keys, alter.Keys)
}
return ri.unsafeMerge(alter)
}
func (ri *RingInfo) unsafeMerge(alter *RingInfo) error {
// enable via Merge
if alter.Enabled {
ri.Enabled = true
}
switch {
case ri.Keys == nil:
// assign keypair

Loading…
Cancel
Save