From ddabb46ba5a6af037cc87a9309aabf0680e37c53 Mon Sep 17 00:00:00 2001 From: Kevin Gibbs Date: Thu, 16 Jun 2022 18:48:24 +0000 Subject: [PATCH] Add a container loader for AppNet Agent --- agent/serviceconnect/error.go | 52 ++++++++ agent/serviceconnect/error_test.go | 52 ++++++++ agent/serviceconnect/generate_mocks.go | 16 +++ agent/serviceconnect/load.go | 82 ++++++++++++ agent/serviceconnect/load_linux.go | 70 ++++++++++ agent/serviceconnect/load_linux_test.go | 122 +++++++++++++++++ agent/serviceconnect/load_test.go | 158 +++++++++++++++++++++++ agent/serviceconnect/load_unsupported.go | 43 ++++++ agent/serviceconnect/mocks/load_mocks.go | 81 ++++++++++++ 9 files changed, 676 insertions(+) create mode 100644 agent/serviceconnect/error.go create mode 100644 agent/serviceconnect/error_test.go create mode 100644 agent/serviceconnect/generate_mocks.go create mode 100644 agent/serviceconnect/load.go create mode 100644 agent/serviceconnect/load_linux.go create mode 100644 agent/serviceconnect/load_linux_test.go create mode 100644 agent/serviceconnect/load_test.go create mode 100644 agent/serviceconnect/load_unsupported.go create mode 100644 agent/serviceconnect/mocks/load_mocks.go diff --git a/agent/serviceconnect/error.go b/agent/serviceconnect/error.go new file mode 100644 index 00000000000..bbd9c71a7ce --- /dev/null +++ b/agent/serviceconnect/error.go @@ -0,0 +1,52 @@ +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package serviceconnect + +// https://golang.org/src/syscall/zerrors_linux_386.go#L1382 +const noSuchFile = "no such file or directory" + +// UnsupportedPlatformError indicates an error when loading appnet container +// image on an unsupported OS platform +type UnsupportedPlatformError struct { + error +} + +// IsUnsupportedPlatform returns true if the error is of UnsupportedPlatformError +// type +func IsUnsupportedPlatform(err error) bool { + _, ok := err.(UnsupportedPlatformError) + return ok +} + +// NewUnsupportedPlatformError creates a new UnsupportedPlatformError object +func NewUnsupportedPlatformError(err error) UnsupportedPlatformError { + return UnsupportedPlatformError{err} +} + +// NoSuchFileError wraps the error from the os package with the message +// "no such file error" +type NoSuchFileError struct { + error +} + +// NewNoSuchFileError creates a new NoSuchFileError object +func NewNoSuchFileError(err error) NoSuchFileError { + return NoSuchFileError{err} +} + +// IsNoSuchFileError returns true if the error is of NoSuchFileError type +func IsNoSuchFileError(err error) bool { + _, ok := err.(NoSuchFileError) + return ok +} diff --git a/agent/serviceconnect/error_test.go b/agent/serviceconnect/error_test.go new file mode 100644 index 00000000000..ee9702eeea4 --- /dev/null +++ b/agent/serviceconnect/error_test.go @@ -0,0 +1,52 @@ +//go:build unit +// +build unit + +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package serviceconnect + +import ( + "errors" + "fmt" + "reflect" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestUnsupportedPlatform(t *testing.T) { + testCases := map[error]bool{ + errors.New("error"): false, + NewUnsupportedPlatformError(errors.New("error")): true, + } + + for err, expected := range testCases { + t.Run(fmt.Sprintf("returns %t for type %s", expected, reflect.TypeOf(err)), func(t *testing.T) { + assert.Equal(t, expected, IsUnsupportedPlatform(err)) + }) + } +} + +func TestIsNoSuchFileError(t *testing.T) { + testCases := map[error]bool{ + errors.New("error"): false, + NewNoSuchFileError(errors.New("No such file")): true, + } + + for err, expected := range testCases { + t.Run(fmt.Sprintf("return %t for type %s", expected, reflect.TypeOf(err)), func(t *testing.T) { + assert.Equal(t, expected, IsNoSuchFileError(err)) + }) + } +} diff --git a/agent/serviceconnect/generate_mocks.go b/agent/serviceconnect/generate_mocks.go new file mode 100644 index 00000000000..4bc8760fd70 --- /dev/null +++ b/agent/serviceconnect/generate_mocks.go @@ -0,0 +1,16 @@ +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package serviceconnect + +//go:generate mockgen -destination=mocks/load_mocks.go -copyright_file=../../scripts/copyright_file github.com/aws/amazon-ecs-agent/agent/serviceconnect Loader diff --git a/agent/serviceconnect/load.go b/agent/serviceconnect/load.go new file mode 100644 index 00000000000..2e1affd7d26 --- /dev/null +++ b/agent/serviceconnect/load.go @@ -0,0 +1,82 @@ +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package serviceconnect + +import ( + "context" + "fmt" + + "github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi" + "github.com/aws/amazon-ecs-agent/agent/logger" + "github.com/aws/amazon-ecs-agent/agent/logger/field" + "github.com/docker/docker/api/types" +) + +var ( + defaultAgentContainerImageName = "appnet_agent" + defaultAgentContainerTag = "service_connect.v1" +) + +// Loader defines an interface for loading the appnetAgent container image. This is mostly +// to facilitate mocking and testing of the LoadImage method +type Loader interface { + LoadImage(ctx context.Context, dockerClient dockerapi.DockerClient) (*types.ImageInspect, error) + IsLoaded(dockerClient dockerapi.DockerClient) (bool, error) +} + +type loader struct { + AgentContainerImageName string + AgentContainerTag string + AgentContainerTarballPath string +} + +// New creates a new AppNet Agent image loader +func New() Loader { + return &loader{ + AgentContainerImageName: defaultAgentContainerImageName, + AgentContainerTag: defaultAgentContainerTag, + AgentContainerTarballPath: defaultAgentContainerTarballPath, + } +} + +// This function uses the DockerClient to inspect the image with the given name and tag. +func getAgentContainerImage(name string, tag string, dockerClient dockerapi.DockerClient) (*types.ImageInspect, error) { + imageName := fmt.Sprintf("%s:%s", name, tag) + logger.Debug("Inspecting appnet agent container image:", logger.Fields{ + field.Image: imageName, + }) + + image, err := dockerClient.InspectImage(imageName) + if err != nil { + return nil, fmt.Errorf("appnet agent container load: failed to inspect image: %s; %w", imageName, err) + } + + return image, nil +} + +// Common function for linux and windows to check if the container appnet Agent image has been loaded +func (agent *loader) isImageLoaded(dockerClient dockerapi.DockerClient) (bool, error) { + image, err := getAgentContainerImage( + agent.AgentContainerImageName, agent.AgentContainerTag, dockerClient) + + if err != nil { + return false, err + } + + if image == nil || image.ID == "" { + return false, nil + } + + return true, nil +} diff --git a/agent/serviceconnect/load_linux.go b/agent/serviceconnect/load_linux.go new file mode 100644 index 00000000000..063cd1fc695 --- /dev/null +++ b/agent/serviceconnect/load_linux.go @@ -0,0 +1,70 @@ +//go:build linux +// +build linux + +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package serviceconnect + +import ( + "context" + "fmt" + "os" + + "github.com/aws/amazon-ecs-agent/agent/dockerclient" + "github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi" + "github.com/aws/amazon-ecs-agent/agent/logger" + "github.com/aws/amazon-ecs-agent/agent/logger/field" + + "github.com/docker/docker/api/types" +) + +var ( + defaultAgentContainerTarballPath = "/managed-agents/serviceconnect/appnet_agent.interface-v1.tar" +) + +// LoadImage helps load the AppNetAgent container image for the agent +func (agent *loader) LoadImage(ctx context.Context, dockerClient dockerapi.DockerClient) (*types.ImageInspect, error) { + logger.Debug("Loading appnet agent container tarball:", logger.Fields{ + field.Image: agent.AgentContainerTarballPath, + }) + if err := loadFromFile(ctx, agent.AgentContainerTarballPath, dockerClient); err != nil { + return nil, err + } + + return getAgentContainerImage( + agent.AgentContainerImageName, agent.AgentContainerTag, dockerClient) +} + +func (agent *loader) IsLoaded(dockerClient dockerapi.DockerClient) (bool, error) { + return agent.isImageLoaded(dockerClient) +} + +var open = os.Open + +func loadFromFile(ctx context.Context, path string, dockerClient dockerapi.DockerClient) error { + containerReader, err := open(path) + if err != nil { + if err.Error() == noSuchFile { + return NewNoSuchFileError(fmt.Errorf( + "appnet agent container load: failed to read container image: %s : %w", path, err)) + } + return fmt.Errorf("appnet agent container load: failed to read container image: %s : %w", path, err) + } + if err := dockerClient.LoadImage(ctx, containerReader, dockerclient.LoadImageTimeout); err != nil { + return fmt.Errorf("appnet agent container load: failed to load container image: %s : %w", path, err) + } + + return nil + +} diff --git a/agent/serviceconnect/load_linux_test.go b/agent/serviceconnect/load_linux_test.go new file mode 100644 index 00000000000..9e30a3acca7 --- /dev/null +++ b/agent/serviceconnect/load_linux_test.go @@ -0,0 +1,122 @@ +//go:build linux && unit +// +build linux,unit + +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package serviceconnect + +import ( + "context" + "errors" + "os" + "testing" + + "github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi" + mock_sdkclient "github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclient/mocks" + mock_sdkclientfactory "github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclientfactory/mocks" + + "github.com/docker/docker/api/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" +) + +const ( + containerTarballPath = "/path/to/container.tar" +) + +func mockOpen() func() { + open = func(name string) (*os.File, error) { + return nil, nil + } + return func() { + open = os.Open + } +} + +// TestLoadFromFileWithReaderError tests loadFromFile with reader error +func TestLoadFromFileWithReaderError(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Docker SDK tests + mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) + mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) + sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) + sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) + + ctx, cancel := context.WithCancel(context.TODO()) + defer cancel() + + client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) + assert.NoError(t, err) + + open = func(name string) (*os.File, error) { + return nil, errors.New("Dummy Reader Error") + } + defer func() { + open = os.Open + }() + + err = loadFromFile(ctx, containerTarballPath, client) + assert.Error(t, err) +} + +// TestLoadFromFileHappyPath tests loadFromFile against happy path +func TestLoadFromFileHappyPath(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Docker SDK tests + mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) + mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) + sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) + sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) + + ctx, cancel := context.WithCancel(context.TODO()) + defer cancel() + + client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) + assert.NoError(t, err) + mockDockerSDK.EXPECT().ImageLoad(gomock.Any(), gomock.Any(), false).Return(types.ImageLoadResponse{}, nil) + defer mockOpen()() + + err = loadFromFile(ctx, containerTarballPath, client) + assert.NoError(t, err) +} + +// TestLoadFromFileDockerLoadImageError tests loadFromFile against error +// from Docker clients LoadImage +func TestLoadFromFileDockerLoadImageError(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Docker SDK tests + mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) + mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) + sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) + sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) + + ctx, cancel := context.WithCancel(context.TODO()) + defer cancel() + + client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) + assert.NoError(t, err) + mockDockerSDK.EXPECT().ImageLoad(gomock.Any(), gomock.Any(), false).Return(types.ImageLoadResponse{}, + errors.New("Dummy Load Image Error")) + + defer mockOpen()() + + err = loadFromFile(ctx, containerTarballPath, client) + assert.Error(t, err) +} diff --git a/agent/serviceconnect/load_test.go b/agent/serviceconnect/load_test.go new file mode 100644 index 00000000000..c96e7ebd92f --- /dev/null +++ b/agent/serviceconnect/load_test.go @@ -0,0 +1,158 @@ +//go:build unit +// +build unit + +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package serviceconnect + +import ( + "context" + "errors" + "testing" + + "github.com/aws/amazon-ecs-agent/agent/config" + "github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi" + mock_sdkclient "github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclient/mocks" + mock_sdkclientfactory "github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclientfactory/mocks" + + "github.com/docker/docker/api/types" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/assert" +) + +const ( + agentName = "appnet-agent" + agentTag = "tag" +) + +var defaultConfig = config.DefaultConfig() + +func TestGetAppnetAgentContainerImageInspectImageError(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Docker SDK tests + mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) + mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) + sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) + sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) + + ctx, cancel := context.WithCancel(context.TODO()) + defer cancel() + + client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) + assert.NoError(t, err) + mockDockerSDK.EXPECT().ImageInspectWithRaw(gomock.Any(), agentName+":"+agentTag).Return( + types.ImageInspect{}, nil, errors.New("error")) + + _, err = getAgentContainerImage(agentName, agentTag, client) + assert.Error(t, err) +} + +func TestGetAgentContainerHappyPath(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Docker SDK tests + mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) + mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) + sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) + sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) + + ctx, cancel := context.WithCancel(context.TODO()) + defer cancel() + + client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) + assert.NoError(t, err) + mockDockerSDK.EXPECT().ImageInspectWithRaw(gomock.Any(), agentName+":"+agentTag).Return(types.ImageInspect{}, nil, nil) + + _, err = getAgentContainerImage(agentName, agentTag, client) + assert.NoError(t, err) +} + +func TestIsImageLoadedHappyPath(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Docker SDK tests + mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) + mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) + sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) + sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) + + ctx, cancel := context.WithCancel(context.TODO()) + defer cancel() + + client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) + assert.NoError(t, err) + mockDockerSDK.EXPECT().ImageInspectWithRaw(gomock.Any(), gomock.Any()).Return(types.ImageInspect{ID: "test123"}, nil, nil) + + isLoaded, err := (&loader{ + AgentContainerImageName: agentName, + AgentContainerTag: agentTag, + }).isImageLoaded(client) + assert.NoError(t, err) + assert.True(t, isLoaded) +} + +func TestIsImageLoadedNotLoaded(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Docker SDK tests + mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) + mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) + sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) + sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) + + ctx, cancel := context.WithCancel(context.TODO()) + defer cancel() + + client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) + assert.NoError(t, err) + mockDockerSDK.EXPECT().ImageInspectWithRaw(gomock.Any(), gomock.Any()).Return(types.ImageInspect{}, nil, nil) + + isLoaded, err := (&loader{ + AgentContainerImageName: agentName, + AgentContainerTag: agentTag, + }).isImageLoaded(client) + assert.NoError(t, err) + assert.False(t, isLoaded) +} + +func TestIsImageLoadedError(t *testing.T) { + ctrl := gomock.NewController(t) + defer ctrl.Finish() + + // Docker SDK tests + mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) + mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) + sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) + sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) + + ctx, cancel := context.WithCancel(context.TODO()) + defer cancel() + + client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) + assert.NoError(t, err) + mockDockerSDK.EXPECT().ImageInspectWithRaw(gomock.Any(), gomock.Any()).Return( + types.ImageInspect{}, nil, errors.New("error")) + + isLoaded, err := (&loader{ + AgentContainerImageName: agentName, + AgentContainerTag: agentTag, + }).isImageLoaded(client) + assert.Error(t, err) + assert.False(t, isLoaded) +} diff --git a/agent/serviceconnect/load_unsupported.go b/agent/serviceconnect/load_unsupported.go new file mode 100644 index 00000000000..fd7556c3fe4 --- /dev/null +++ b/agent/serviceconnect/load_unsupported.go @@ -0,0 +1,43 @@ +//go:build !linux +// +build !linux + +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. + +package serviceconnect + +import ( + "context" + "fmt" + "runtime" + + "github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi" + "github.com/docker/docker/api/types" +) + +var ( + defaultAgentContainerTarballPath = "" +) + +// LoadImage returns UnsupportedPlatformError on the unsupported platform +func (*loader) LoadImage(ctx context.Context, dockerClient dockerapi.DockerClient) (*types.ImageInspect, error) { + return nil, NewUnsupportedPlatformError(fmt.Errorf( + "appnetAgent container load: unsupported platform: %s/%s", + runtime.GOOS, runtime.GOARCH)) +} + +func (*loader) IsLoaded(dockerClient dockerapi.DockerClient) (bool, error) { + return false, NewUnsupportedPlatformError(fmt.Errorf( + "appnetAgent container isloaded: unsupported platform: %s/%s", + runtime.GOOS, runtime.GOARCH)) +} diff --git a/agent/serviceconnect/mocks/load_mocks.go b/agent/serviceconnect/mocks/load_mocks.go new file mode 100644 index 00000000000..33bcfe3b113 --- /dev/null +++ b/agent/serviceconnect/mocks/load_mocks.go @@ -0,0 +1,81 @@ +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"). You may +// not use this file except in compliance with the License. A copy of the +// License is located at +// +// http://aws.amazon.com/apache2.0/ +// +// or in the "license" file accompanying this file. This file is distributed +// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +// express or implied. See the License for the specific language governing +// permissions and limitations under the License. +// + +// Code generated by MockGen. DO NOT EDIT. +// Source: github.com/aws/amazon-ecs-agent/agent/serviceconnect (interfaces: Loader) + +// Package mock_serviceconnect is a generated GoMock package. +package mock_serviceconnect + +import ( + context "context" + reflect "reflect" + + dockerapi "github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi" + types "github.com/docker/docker/api/types" + gomock "github.com/golang/mock/gomock" +) + +// MockLoader is a mock of Loader interface +type MockLoader struct { + ctrl *gomock.Controller + recorder *MockLoaderMockRecorder +} + +// MockLoaderMockRecorder is the mock recorder for MockLoader +type MockLoaderMockRecorder struct { + mock *MockLoader +} + +// NewMockLoader creates a new mock instance +func NewMockLoader(ctrl *gomock.Controller) *MockLoader { + mock := &MockLoader{ctrl: ctrl} + mock.recorder = &MockLoaderMockRecorder{mock} + return mock +} + +// EXPECT returns an object that allows the caller to indicate expected use +func (m *MockLoader) EXPECT() *MockLoaderMockRecorder { + return m.recorder +} + +// IsLoaded mocks base method +func (m *MockLoader) IsLoaded(arg0 dockerapi.DockerClient) (bool, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "IsLoaded", arg0) + ret0, _ := ret[0].(bool) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// IsLoaded indicates an expected call of IsLoaded +func (mr *MockLoaderMockRecorder) IsLoaded(arg0 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsLoaded", reflect.TypeOf((*MockLoader)(nil).IsLoaded), arg0) +} + +// LoadImage mocks base method +func (m *MockLoader) LoadImage(arg0 context.Context, arg1 dockerapi.DockerClient) (*types.ImageInspect, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "LoadImage", arg0, arg1) + ret0, _ := ret[0].(*types.ImageInspect) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// LoadImage indicates an expected call of LoadImage +func (mr *MockLoaderMockRecorder) LoadImage(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadImage", reflect.TypeOf((*MockLoader)(nil).LoadImage), arg0, arg1) +}