-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding retry for eni plugin to acquire mac address #62
Conversation
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.
Looks good in general. Just a couple of comments on style that you can choose to address or not.
// express or implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
package utils |
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.
I wonder if now might be the right time to split this code out into a standalone library. Copy & Paste between projects is not so good.
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.
yeah, I don't like copy and paste either, but it will require additional work which probably won't happen within this pr, I will create an issue to follow up.
plugins/eni/commands/commands.go
Outdated
@@ -152,6 +163,63 @@ func add(args *skel.CmdArgs, engine engine.Engine, dhclient engine.DHClient) err | |||
return cnitypes.PrintResult(result, conf.CNIVersion) | |||
} | |||
|
|||
// getMACAddressOfENIAndVerify acquires the mac address of eni and verify the ip address information | |||
func getMACAddressOfENIAndVerify(conf *types.NetConf, engine engine.Engine, timeout time.Duration) (string, error) { |
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.
I don't really like the name getMACAddressOfENIAndVerify
. It feels unnecessarily verbose and isn't descriptive of the fact that we're also verifying IP info (not just MAC addr). I'd name this getENIMetadata
and leave the "verify" part as implicit. Or getAndVerifyENIMetadata
maybe, if you really want "verify" to be part of the function name.
plugins/eni/commands/commands.go
Outdated
return nil | ||
} | ||
|
||
_, ok := err.(*engine.UnmappedMACAddressError) |
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.
I realize that we don't actually have the issue here, but this style of type assertion gives me flashbacks to aws/amazon-ecs-agent#910. Interface conversions are a less error prone way to perform type assertions, IMO.
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.
Can you address @nmeyerhans 's comment here as well?
plugins/eni/commands/commands.go
Outdated
ec2InstanceMetadataBackoffMax = 1 * time.Second | ||
ec2InstanceMetadataBackoffMultiple = 2 | ||
ec2InstanceMetadataBackoffJitter = 0.2 | ||
ec2InstanceMetadataTimeout = 5 * time.Second |
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.
How did you arrive at a 5 second timeout?
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.
@aaithal and I did some tests, the worst case I saw is 1.5s. So I put 5s here to be safe, but it's changeable.
for { | ||
select { | ||
case <-ctx.Done(): | ||
return ctx.Err() |
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.
nice. we need to fix this in the agent repo as well.
plugins/eni/commands/commands.go
Outdated
@@ -27,6 +30,14 @@ import ( | |||
"github.com/pkg/errors" | |||
) | |||
|
|||
const ( | |||
ec2InstanceMetadataBackoffMin = 500 * time.Millisecond |
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.
can you decrease this to 100ms
? half a second seems really long to wait here.
plugins/eni/commands/commands.go
Outdated
return nil | ||
} | ||
|
||
_, ok := err.(*engine.UnmappedMACAddressError) |
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.
Can you address @nmeyerhans 's comment here as well?
This PR adds backoff retry logic for retrieving mac address of the eni from ec2 instance metadata.