-
Notifications
You must be signed in to change notification settings - Fork 619
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
handlers: add eni info to instrospection endpoint #1271
Conversation
agent/handlers/types/v1/response.go
Outdated
@@ -28,6 +28,7 @@ type TaskResponse struct { | |||
Family string | |||
Version string | |||
Containers []ContainerResponse | |||
Networks []NetworkResponse |
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.
Similar to
Networks []containermetadata.Network `json:",omitempty"` |
ContainerResponse
struct.
agent/handlers/types/v1/response.go
Outdated
} | ||
|
||
// NetworkResponse is the schema for the network response JSON object | ||
type NetworkResponse struct { |
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.
You should just reuse this
type Network struct { |
agent/handlers/v1_handlers.go
Outdated
resp.DockerId = container.DockerID | ||
resp.DockerName = container.DockerName | ||
|
||
if eni != nil { |
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.
we should also populate resp.Networks
when eni == nil
, with whatever value we can get from container's metadata
agent/handlers/v1_handlers.go
Outdated
containers := []v1.ContainerResponse{} | ||
for containerName, container := range containerMap { | ||
if container.Container.IsInternal() { | ||
continue | ||
} | ||
containers = append(containers, v1.ContainerResponse{DockerId: container.DockerID, DockerName: container.DockerName, Name: containerName}) | ||
containerResponse := newContainerResponse(containerName, container, task.GetTaskENI()) | ||
containers = append(containers, containerResponse) |
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.
nit: would it be more readable to use containerResponses
instead of containers
?
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 decided against changing this because containerResponse
and containerResponses
are very similar
e777310
to
3b39656
Compare
agent/handlers/v1_handlers.go
Outdated
DockerName: dockerContainer.DockerName, | ||
} | ||
|
||
for _, binding := range container.Ports { |
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 add a getter in the container struct to return the Ports and use the getter instead?
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'll make the change. Just wondering why we should use a getter if Ports
is an exported field. I think we make it an exported field so we can serialize it.
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.
yes, some other fields like KnowStatus
is exported for the same purpose.
agent/handlers/v1_handlers.go
Outdated
if eni != nil { | ||
resp.Networks = []containermetadata.Network{ | ||
{ | ||
NetworkMode: "awsvpc", |
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.
minor, const this. there must be a const somewhere with that string.
agent/api/container.go
Outdated
c.lock.RLock() | ||
defer c.lock.RUnlock() | ||
|
||
return c.Ports |
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 rename Ports
to PortsUnsafe
?
agent/api/container.go
Outdated
@@ -493,6 +493,22 @@ func (c *Container) GetLabels() map[string]string { | |||
return c.labels | |||
} | |||
|
|||
// SetKnownPortBindings gets the ports for a container | |||
func (c *Container) SetKnownPortBindings(ports []PortBinding) { | |||
c.lock.RLock() |
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.
This should be a write lock.
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.
oops, good catch.
agent/api/container.go
Outdated
@@ -493,6 +493,22 @@ func (c *Container) GetLabels() map[string]string { | |||
return c.labels | |||
} | |||
|
|||
// SetKnownPortBindings gets the ports for a container |
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.
minor s/get/set/
|
||
if eni == nil { | ||
port.HostPort = binding.HostPort | ||
} else { |
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.
If the container does use ENI, the binding
should be empty, you should read the port information from container.Port
. So I think you can do this:
bindings := container.GetKnownPortBindings()
if len(bindings) == 0{
// Put the port information from task definition
}else{
// put the information from bindings
}
|
||
// if KnownPortBindings list is empty, then we use the port mapping | ||
// information that was passed down from ACS. | ||
if len(bindings) == 0 { |
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 update the test to cover this?
agent/handlers/types/v1/response.go
Outdated
@@ -40,4 +45,6 @@ type ContainerResponse struct { | |||
DockerId string | |||
DockerName string | |||
Name string | |||
Ports []v2.PortResponse |
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 think this needs an omitempty
tag
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.
ya you're right. added.
a02f0bf
to
374b08b
Compare
Summary
adding eni info to instrospection endpoint, addresses #1247
in awsvpc mode:
in bridge mode:
in host mode:
Implementation details
Testing
make release
)go build -out amazon-ecs-agent.exe ./agent
)make test
) passgo test -timeout=25s ./agent/...
) passmake run-integ-tests
) pass.\scripts\run-integ-tests.ps1
) passmake run-functional-tests
) pass.\scripts\run-functional-tests.ps1
) passNew tests cover the changes:
Description for the changelog
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.