Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Fix "index out of range" error while getting IP #25

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions handlers/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,23 +150,16 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container
return errors.Wrapf(err, "failed to setup network for namespace %q: %v", id, err)
}

// Get the IP of the default interface.
defaultInterface := gocni.DefaultPrefix + "0"

if _, ok := result.Interfaces[defaultInterface]; !ok {
return fmt.Errorf("failed to find interface %q", defaultInterface)
}
if result.Interfaces[defaultInterface].IPConfigs != nil &&
len(result.Interfaces[defaultInterface].IPConfigs) == 0 {
return fmt.Errorf("failed to find IP for interface %q, no configs found", defaultInterface)
// Get the IP of the created interface
for _, config := range result.Interfaces {
if config.Sandbox == netns {
for _, ipConfig := range config.IPConfigs {
serviceMap.Add(name, &ipConfig.IP)
log.Printf("%s has IP: %s.\n", name, &ipConfig.IP)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why aren't we doing a break out of the loops here?

}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's discover the IP in the loop, then act on it after the loop, either from breaking out or from finishing without a result.

}

ip := &result.Interfaces[defaultInterface].IPConfigs[0].IP

serviceMap.Add(name, ip)

log.Printf("%s has IP: %s\n", name, ip.String())

_, waitErr := task.Wait(ctx)
if waitErr != nil {
return errors.Wrapf(waitErr, "Unable to wait for task to start: %s", name)
Expand Down