This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Fix "index out of range" error while getting IP #25
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?