Browse Source

Cleaned up some error handling/comments around config entries

pull/5539/head
Kyle Havlovitz 6 years ago
parent
commit
a2fa9a0019
  1. 6
      agent/consul/fsm/commands_oss_test.go
  2. 3
      agent/consul/fsm/snapshot_oss.go
  3. 14
      agent/structs/config_entry.go
  4. 2
      agent/structs/structs.go

6
agent/consul/fsm/commands_oss_test.go

@ -1369,7 +1369,7 @@ func TestFSM_ConfigEntry(t *testing.T) {
Kind: structs.ProxyDefaults,
Name: "global",
Config: map[string]interface{}{
"DestinationServiceName": "foo",
"foo": "bar",
},
}
@ -1399,8 +1399,8 @@ func TestFSM_ConfigEntry(t *testing.T) {
require.True(ok)
// Read the map[string]interface{} back out.
value, _ := proxyConf.Config["DestinationServiceName"].([]uint8)
proxyConf.Config["DestinationServiceName"] = structs.Uint8ToString(value)
value, _ := proxyConf.Config["foo"].([]uint8)
proxyConf.Config["foo"] = structs.Uint8ToString(value)
require.Equal(entry, config)
}

3
agent/consul/fsm/snapshot_oss.go

@ -375,6 +375,9 @@ func (s *snapshot) persistConfigEntries(sink raft.SnapshotSink,
if _, err := sink.Write([]byte{byte(structs.ConfigEntryRequestType)}); err != nil {
return err
}
// Encode the entry request without an operation since we don't need it for restoring.
// The request is used for its custom decoding/encoding logic around the ConfigEntry
// interface.
req := &structs.ConfigEntryRequest{
Entry: entry,
}

14
agent/structs/config_entry.go

@ -198,7 +198,11 @@ func (r *ConfigEntryRequest) UnmarshalBinary(data []byte) error {
}
// Then decode the real thing with appropriate kind of ConfigEntry
r.Entry = makeConfigEntry(kind)
entry, err := makeConfigEntry(kind)
if err != nil {
return err
}
r.Entry = entry
// Alias juggling to prevent infinite recursive calls back to this decode
// method.
@ -214,13 +218,13 @@ func (r *ConfigEntryRequest) UnmarshalBinary(data []byte) error {
return nil
}
func makeConfigEntry(kind string) ConfigEntry {
func makeConfigEntry(kind string) (ConfigEntry, error) {
switch kind {
case ServiceDefaults:
return &ServiceConfigEntry{}
return &ServiceConfigEntry{}, nil
case ProxyDefaults:
return &ProxyConfigEntry{}
return &ProxyConfigEntry{}, nil
default:
panic("invalid kind")
return nil, fmt.Errorf("invalid config entry kind: %s", kind)
}
}

2
agent/structs/structs.go

@ -55,7 +55,7 @@ const (
ACLPolicySetRequestType = 19
ACLPolicyDeleteRequestType = 20
ConnectCALeafRequestType = 21
ConfigEntryRequestType = 22 // FSM snapshots only.
ConfigEntryRequestType = 22
)
const (

Loading…
Cancel
Save