mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 16:57:18 +00:00
agent: Return an error, not just an interface
Make `newAgentConfig()` return an explicit error rather than handling the error scenario by simply returning the `error` object in the `interface{}` return type. The old behaviour was confusing and inconsistent with the other functions creating a new config type (shim, proxy, etc). Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
63e1c440a1
commit
e803a7f870
@ -91,19 +91,19 @@ func newAgent(agentType AgentType) agent {
|
||||
}
|
||||
|
||||
// newAgentConfig returns an agent config from a generic SandboxConfig interface.
|
||||
func newAgentConfig(agentType AgentType, agentConfig interface{}) interface{} {
|
||||
func newAgentConfig(agentType AgentType, agentConfig interface{}) (interface{}, error) {
|
||||
switch agentType {
|
||||
case NoopAgentType:
|
||||
return nil
|
||||
return nil, nil
|
||||
case KataContainersAgent:
|
||||
var kataAgentConfig KataAgentConfig
|
||||
err := mapstructure.Decode(agentConfig, &kataAgentConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
return kataAgentConfig
|
||||
return kataAgentConfig, nil
|
||||
default:
|
||||
return nil
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,12 @@ func TestNewAgentFromUnknownAgentType(t *testing.T) {
|
||||
}
|
||||
|
||||
func testNewAgentConfig(t *testing.T, config SandboxConfig, expected interface{}) {
|
||||
agentConfig := newAgentConfig(config.AgentType, config.AgentConfig)
|
||||
agentConfig, err := newAgentConfig(config.AgentType, config.AgentConfig)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
}
|
||||
|
||||
if reflect.DeepEqual(agentConfig, expected) == false {
|
||||
t.Fatal()
|
||||
}
|
||||
|
@ -583,7 +583,11 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
|
||||
return nil, err
|
||||
}
|
||||
|
||||
agentConfig := newAgentConfig(sandboxConfig.AgentType, sandboxConfig.AgentConfig)
|
||||
agentConfig, err := newAgentConfig(sandboxConfig.AgentType, sandboxConfig.AgentConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = s.agent.init(ctx, s, agentConfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user