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

Adding EnableFaultInjection to task payload #4364

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions agent/acs/session/payload_responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ func (pmHandler *payloadMessageHandler) addPayloadTasks(payload *ecsacs.PayloadM
loggerfield.DesiredStatus: apiTask.GetDesiredStatus(),
})

if apiTask.IsFaultInjectionEnabled() {
logger.Info("Fault Injection Enabled for task", logger.Fields{
loggerfield.TaskARN: apiTask.Arn,
})
}

if task.RoleCredentials != nil {
// The payload from ACS for the task has credentials for the
// task. Add those to the credentials manager and set the
Expand Down
8 changes: 5 additions & 3 deletions agent/api/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ type Task struct {

NetworkNamespace string `json:"NetworkNamespace,omitempty"`

// TODO: Will need to initialize/set the value in a follow PR
FaultInjectionEnabled bool `json:"FaultInjectionEnabled,omitempty"`
EnableFaultInjection bool `json:"enableFaultInjection,omitempty"`
mye956 marked this conversation as resolved.
Show resolved Hide resolved

// DefaultIfname is used to reference the default network interface name on the task network namespace
// For AWSVPC mode, it can be eth0 which corresponds to the interface name on the task ENI
Expand All @@ -322,6 +321,9 @@ func TaskFromACS(acsTask *ecsacs.Task, envelope *ecsacs.PayloadMessage) (*Task,
return nil, err
}

// Set the EnableFaultInjection field if present
task.EnableFaultInjection = aws.BoolValue(acsTask.EnableFaultInjection)

// Overrides the container command if it's set
for _, container := range task.Containers {
if (container.Overrides != apicontainer.ContainerOverrides{}) && container.Overrides.Command != nil {
Expand Down Expand Up @@ -3771,7 +3773,7 @@ func (task *Task) IsFaultInjectionEnabled() bool {
task.lock.RLock()
defer task.lock.RUnlock()

return task.FaultInjectionEnabled
return task.EnableFaultInjection
}

func (task *Task) GetNetworkMode() string {
Expand Down
24 changes: 12 additions & 12 deletions agent/handlers/task_server_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,9 @@ var (
}},
})

agentStateExpectations = func(state *mock_dockerstate.MockTaskEngineState, faultInjectionEnabled bool, networkMode string) {
agentStateExpectations = func(state *mock_dockerstate.MockTaskEngineState, enableFaultInjection bool, networkMode string) {
task := standardTask()
task.FaultInjectionEnabled = faultInjectionEnabled
task.EnableFaultInjection = enableFaultInjection
task.NetworkMode = networkMode
task.NetworkNamespace = networkNamespace
task.DefaultIfname = defaultIfname
Expand Down Expand Up @@ -590,7 +590,7 @@ func expectedV4TaskResponse() v4.TaskResponse {
)
}

func expectedV4TaskNetworkConfig(faultInjectionEnabled bool, networkMode, path, deviceName string) *v4.TaskNetworkConfig {
func expectedV4TaskNetworkConfig(enableFaultInjection bool, networkMode, path, deviceName string) *v4.TaskNetworkConfig {
return v4.NewTaskNetworkConfig(networkMode, path, deviceName)
}

Expand Down Expand Up @@ -2093,7 +2093,7 @@ func TestV4TaskMetadata(t *testing.T) {
testTMDSRequest(t, TMDSTestCase[v4.TaskResponse]{
path: v4BasePath + v3EndpointID + "/task",
setStateExpectations: func(state *mock_dockerstate.MockTaskEngineState) {
task.FaultInjectionEnabled = true
task.EnableFaultInjection = true
task.NetworkNamespace = networkNamespace
task.DefaultIfname = defaultIfname
gomock.InOrder(
Expand All @@ -2116,7 +2116,7 @@ func TestV4TaskMetadata(t *testing.T) {
path: v4BasePath + v3EndpointID + "/task",
setStateExpectations: func(state *mock_dockerstate.MockTaskEngineState) {
hostTask := standardHostTask()
hostTask.FaultInjectionEnabled = true
hostTask.EnableFaultInjection = true
hostTask.NetworkNamespace = networkNamespace
hostTask.DefaultIfname = defaultIfname
gomock.InOrder(
Expand Down Expand Up @@ -3733,9 +3733,9 @@ type networkFaultTestCase struct {
expectedStatusCode int
requestBody interface{}
expectedFaultResponse faulttype.NetworkFaultInjectionResponse
setStateExpectations func(state *mock_dockerstate.MockTaskEngineState, faultInjectionEnabled bool, networkMode string)
setStateExpectations func(state *mock_dockerstate.MockTaskEngineState, enableFaultInjection bool, networkMode string)
setExecExpectations execExpectations
faultInjectionEnabled bool
enableFaultInjection bool
networkMode string
}

Expand All @@ -3750,7 +3750,7 @@ func generateCommonNetworkFaultInjectionTestCases(requestType, successResponse s
expectedFaultResponse: faulttype.NewNetworkFaultInjectionSuccessResponse(successResponse),
setStateExpectations: agentStateExpectations,
setExecExpectations: exec,
faultInjectionEnabled: true,
enableFaultInjection: true,
networkMode: apitask.HostNetworkMode,
},
{
Expand All @@ -3760,7 +3760,7 @@ func generateCommonNetworkFaultInjectionTestCases(requestType, successResponse s
expectedFaultResponse: faulttype.NewNetworkFaultInjectionSuccessResponse(successResponse),
setStateExpectations: agentStateExpectations,
setExecExpectations: exec,
faultInjectionEnabled: true,
enableFaultInjection: true,
networkMode: apitask.AWSVPCNetworkMode,
},
}
Expand Down Expand Up @@ -3910,7 +3910,7 @@ func testRegisterFaultHandler(t *testing.T, tcs []networkFaultTestCase, tmdsEndp
execWrapper := mock_execwrapper.NewMockExec(ctrl)

if tc.setStateExpectations != nil {
tc.setStateExpectations(state, tc.faultInjectionEnabled, tc.networkMode)
tc.setStateExpectations(state, tc.enableFaultInjection, tc.networkMode)
}

if tc.setExecExpectations != nil {
Expand Down Expand Up @@ -3979,7 +3979,7 @@ func TestV4GetTaskMetadataWithTaskNetworkConfig(t *testing.T) {
name: "happy case with awsvpc mode",
setStateExpectations: func(state *mock_dockerstate.MockTaskEngineState) {
task := standardTask()
task.FaultInjectionEnabled = true
task.EnableFaultInjection = true
task.NetworkNamespace = networkNamespace
task.DefaultIfname = defaultIfname
gomock.InOrder(
Expand All @@ -3998,7 +3998,7 @@ func TestV4GetTaskMetadataWithTaskNetworkConfig(t *testing.T) {
name: "happy case with host mode",
setStateExpectations: func(state *mock_dockerstate.MockTaskEngineState) {
hostTask := standardHostTask()
hostTask.FaultInjectionEnabled = true
hostTask.EnableFaultInjection = true
hostTask.NetworkNamespace = networkNamespace
hostTask.DefaultIfname = defaultIfname
gomock.InOrder(
Expand Down
Loading