mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-08 08:54:29 +01: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:
@@ -91,19 +91,19 @@ func newAgent(agentType AgentType) agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newAgentConfig returns an agent config from a generic SandboxConfig interface.
|
// 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 {
|
switch agentType {
|
||||||
case NoopAgentType:
|
case NoopAgentType:
|
||||||
return nil
|
return nil, nil
|
||||||
case KataContainersAgent:
|
case KataContainersAgent:
|
||||||
var kataAgentConfig KataAgentConfig
|
var kataAgentConfig KataAgentConfig
|
||||||
err := mapstructure.Decode(agentConfig, &kataAgentConfig)
|
err := mapstructure.Decode(agentConfig, &kataAgentConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
return kataAgentConfig
|
return kataAgentConfig, nil
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,12 @@ func TestNewAgentFromUnknownAgentType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testNewAgentConfig(t *testing.T, config SandboxConfig, expected interface{}) {
|
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 {
|
if reflect.DeepEqual(agentConfig, expected) == false {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -583,7 +583,11 @@ func newSandbox(ctx context.Context, sandboxConfig SandboxConfig, factory Factor
|
|||||||
return nil, err
|
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 {
|
if err = s.agent.init(ctx, s, agentConfig); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user