Skip to content

Commit

Permalink
Add nil checks and debug logs for CNI client
Browse files Browse the repository at this point in the history
  • Loading branch information
ohsoo committed Aug 26, 2024
1 parent 82c018a commit d21f24c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ecs-agent/netlib/model/ecscni/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/containernetworking/cni/pkg/invoke"
"github.com/containernetworking/cni/pkg/types"
"github.com/pkg/errors"

"github.com/aws/amazon-ecs-agent/ecs-agent/logger"
)

const (
Expand Down Expand Up @@ -51,6 +53,15 @@ func (c *cniClient) Add(ctx context.Context, config PluginConfig) (types.Result,
if err != nil {
return nil, err
}
if net == nil {
err = errors.New("Failed to build network config, net is nil.")
return nil, err
}
if net.Network == nil {
err = errors.New("Failed to build network config, net.Network is nil.")
return nil, err
}
logger.Debug("Built network config.", logger.Fields{"Type": net.Network.Type})

return c.cni.AddNetwork(ctx, net, rt)
}
Expand Down

0 comments on commit d21f24c

Please sign in to comment.