Skip to content
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

Support firelens for bridge mode ServiceConnect task #3693

Merged
merged 4 commits into from
May 23, 2023
Merged
Changes from 3 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
68 changes: 56 additions & 12 deletions agent/engine/docker_task_engine.go
Original file line number Diff line number Diff line change
@@ -1377,7 +1377,21 @@ func (engine *DockerTaskEngine) createContainer(task *apitask.Task, container *a
fluentNetworkPort: FluentNetworkPortValue,
})
} else if container.GetNetworkModeFromHostConfig() == "" || container.GetNetworkModeFromHostConfig() == apitask.BridgeNetworkMode {
ipAddress, ok := getContainerHostIP(task.GetFirelensContainer().GetNetworkSettings())
targetContainer := task.GetFirelensContainer()
// For bridge-mode ServiceConnect-enabled tasks, we inject pause container for each application container
// including the firelens container. Therefore, when resolving the container IP, we should be checking that
// of the associated pause container.
if task.IsServiceConnectEnabled() {
var err error
targetContainer, err = task.GetBridgeModePauseContainerForTaskContainer(targetContainer)
if err != nil {
return dockerapi.DockerContainerMetadata{
Error: dockerapi.CannotStartContainerError{FromError: errors.New(fmt.Sprintf(
"failed to start firelens container: %v", err))},
}
}
}
ipAddress, ok := getContainerHostIP(targetContainer.GetNetworkSettings())
if !ok {
err := apierrors.DockerClientConfigError{Msg: "unable to get BridgeIP for task in bridge mode"}
return dockerapi.DockerContainerMetadata{Error: apierrors.NamedError(&err)}
@@ -1629,26 +1643,56 @@ func (engine *DockerTaskEngine) startContainer(task *apitask.Task, container *ap
// If container is a firelens container, fluent host is needed to be added to the environment variable for the task.
// For the supported network mode - bridge and awsvpc, the awsvpc take the host 127.0.0.1 but in bridge mode,
// there is a need to wait for the IP to be present before the container using the firelens can be created.
//
// For bridge-mode ServiceConnect-enabled tasks, we inject pause container for each application container
// including the firelens container. Therefore, when resolving the container IP, we should be checking that
// of the associated pause container. In such case, the firelens container has network mode "container" since it's
//launched into its pause container's network namespace.
yinyic marked this conversation as resolved.
Show resolved Hide resolved
if container.GetFirelensConfig() != nil {
if !task.IsNetworkModeAWSVPC() && (container.GetNetworkModeFromHostConfig() == "" || container.GetNetworkModeFromHostConfig() == apitask.BridgeNetworkMode) {
if !task.IsNetworkModeAWSVPC() &&
(container.GetNetworkModeFromHostConfig() == "" ||
container.GetNetworkModeFromHostConfig() == apitask.BridgeNetworkMode ||
(container.GetNetworkModeFromHostConfig() == "container" && task.IsServiceConnectEnabled())) {
_, gotContainerIP := getContainerHostIP(dockerContainerMD.NetworkSettings)
if task.IsServiceConnectEnabled() {
targetContainer, err := task.GetBridgeModePauseContainerForTaskContainer(container)
yinyic marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return dockerapi.DockerContainerMetadata{
Error: dockerapi.CannotStartContainerError{FromError: errors.New(fmt.Sprintf(
"failed to start firelens container: %v", err))},
}
}
_, gotContainerIP = getContainerHostIP(targetContainer.GetNetworkSettings())
}

if !gotContainerIP {
getIPBridgeBackoff := retry.NewExponentialBackoff(minGetIPBridgeTimeout, maxGetIPBridgeTimeout, getIPBridgeRetryJitterMultiplier, getIPBridgeRetryDelayMultiplier)
contextWithTimeout, cancel := context.WithTimeout(engine.ctx, time.Minute)
defer cancel()
err := retry.RetryWithBackoffCtx(contextWithTimeout, getIPBridgeBackoff, func() error {
inspectOutput, err := engine.client.InspectContainer(engine.ctx, dockerContainerMD.DockerID,
dockerclient.InspectContainerTimeout)
if err != nil {
return err
}
_, gotIPBridge := getContainerHostIP(inspectOutput.NetworkSettings)
if gotIPBridge {
dockerContainerMD.NetworkSettings = inspectOutput.NetworkSettings
return nil
gotIPBridge := false
if task.IsServiceConnectEnabled() {
targetContainer, err := task.GetBridgeModePauseContainerForTaskContainer(container)
if err != nil {
return err
}
_, gotIPBridge = getContainerHostIP(targetContainer.GetNetworkSettings())
if gotIPBridge {
return nil
}
} else {
return errors.New("Bridge IP not available to use for firelens")
inspectOutput, err := engine.client.InspectContainer(engine.ctx, dockerContainerMD.DockerID,
dockerclient.InspectContainerTimeout)
if err != nil {
return err
}
_, gotIPBridge = getContainerHostIP(inspectOutput.NetworkSettings)
if gotIPBridge {
dockerContainerMD.NetworkSettings = inspectOutput.NetworkSettings
return nil
}
}
return errors.New("Bridge IP not available to use for firelens")
})
if err != nil {
return dockerapi.DockerContainerMetadata{