From ed84377e6ef9f55e8df4a362af73757803b3aa10 Mon Sep 17 00:00:00 2001 From: Jayanth Varavani <1111446+jayanthvn@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:22:41 -0700 Subject: [PATCH] Update sdk client for NA mocks (#26) * Update sdk client * fix var --- pkg/elfparser/elf.go | 18 +++++----- pkg/elfparser/generate_mocks.go | 2 +- pkg/elfparser/mocks/elfparser_mocks.go | 48 +++++++++++++------------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/pkg/elfparser/elf.go b/pkg/elfparser/elf.go index 9a3ae08..d0997a8 100644 --- a/pkg/elfparser/elf.go +++ b/pkg/elfparser/elf.go @@ -47,7 +47,7 @@ var ( var log = logger.Get() var sdkCache = cache.Get() -type AWSeBpfSdkAPIs interface { +type BpfSDKClient interface { IncreaseRlimit() error LoadBpfFile(path, customizedPinPath string) (map[string]BpfData, map[string]ebpf_maps.BpfMap, error) RecoverGlobalMaps() (map[string]ebpf_maps.BpfMap, error) @@ -59,7 +59,7 @@ type BpfData struct { Maps map[string]ebpf_maps.BpfMap // List of associated maps } -type BpfSDKClient struct { +type bpfSDKClient struct { mapApi ebpf_maps.BpfMapAPIs progApi ebpf_progs.BpfProgAPIs } @@ -90,18 +90,18 @@ type elfLoader struct { progSectionMap map[uint32]progEntry } -func New() *BpfSDKClient { - return &BpfSDKClient{ +func New() BpfSDKClient { + return &bpfSDKClient{ mapApi: &ebpf_maps.BpfMap{}, progApi: &ebpf_progs.BpfProgram{}, } } -var _ AWSeBpfSdkAPIs = (*BpfSDKClient)(nil) +var _ BpfSDKClient = &bpfSDKClient{} // This is not needed 5.11 kernel onwards because per-cgroup mem limits // https://lore.kernel.org/bpf/20201201215900.3569844-1-guro@fb.com/ -func (b *BpfSDKClient) IncreaseRlimit() error { +func (b *bpfSDKClient) IncreaseRlimit() error { err := unix.Setrlimit(unix.RLIMIT_MEMLOCK, &unix.Rlimit{Cur: unix.RLIM_INFINITY, Max: unix.RLIM_INFINITY}) if err != nil { log.Infof("Failed to bump up the rlimit") @@ -122,7 +122,7 @@ func newElfLoader(elfFile *elf.File, bpfmapapi ebpf_maps.BpfMapAPIs, bpfprogapi return elfloader } -func (b *BpfSDKClient) LoadBpfFile(path, customizedPinPath string) (map[string]BpfData, map[string]ebpf_maps.BpfMap, error) { +func (b *bpfSDKClient) LoadBpfFile(path, customizedPinPath string) (map[string]BpfData, map[string]ebpf_maps.BpfMap, error) { bpfFile, err := os.Open(path) if err != nil { log.Infof("LoadBpfFile failed to open") @@ -669,7 +669,7 @@ func IsMapGlobal(pinPath string) bool { return true } -func (b *BpfSDKClient) RecoverGlobalMaps() (map[string]ebpf_maps.BpfMap, error) { +func (b *bpfSDKClient) RecoverGlobalMaps() (map[string]ebpf_maps.BpfMap, error) { _, err := os.Stat(constdef.BPF_DIR_MNT) if err != nil { log.Infof("BPF FS director is not present") @@ -737,7 +737,7 @@ func (b *BpfSDKClient) RecoverGlobalMaps() (map[string]ebpf_maps.BpfMap, error) return loadedGlobalMaps, nil } -func (b *BpfSDKClient) RecoverAllBpfProgramsAndMaps() (map[string]BpfData, error) { +func (b *bpfSDKClient) RecoverAllBpfProgramsAndMaps() (map[string]BpfData, error) { _, err := os.Stat(constdef.BPF_DIR_MNT) if err != nil { log.Infof("BPF FS directory is not present") diff --git a/pkg/elfparser/generate_mocks.go b/pkg/elfparser/generate_mocks.go index 989381f..e7fc5a9 100644 --- a/pkg/elfparser/generate_mocks.go +++ b/pkg/elfparser/generate_mocks.go @@ -12,4 +12,4 @@ // permissions and limitations under the License. package elfparser -//go:generate go run github.com/golang/mock/mockgen -destination mocks/elfparser_mocks.go . AWSeBpfSdkAPIs +//go:generate go run github.com/golang/mock/mockgen -destination mocks/elfparser_mocks.go . BpfSDKClient diff --git a/pkg/elfparser/mocks/elfparser_mocks.go b/pkg/elfparser/mocks/elfparser_mocks.go index f7224b6..abb87b2 100644 --- a/pkg/elfparser/mocks/elfparser_mocks.go +++ b/pkg/elfparser/mocks/elfparser_mocks.go @@ -1,5 +1,5 @@ // Code generated by MockGen. DO NOT EDIT. -// Source: github.com/aws/aws-ebpf-sdk-go/pkg/elfparser (interfaces: AWSeBpfSdkAPIs) +// Source: github.com/aws/aws-ebpf-sdk-go/pkg/elfparser (interfaces: BpfSDKClient) // Package mock_elfparser is a generated GoMock package. package mock_elfparser @@ -12,31 +12,31 @@ import ( gomock "github.com/golang/mock/gomock" ) -// MockAWSeBpfSdkAPIs is a mock of AWSeBpfSdkAPIs interface. -type MockAWSeBpfSdkAPIs struct { +// MockBpfSDKClient is a mock of BpfSDKClient interface. +type MockBpfSDKClient struct { ctrl *gomock.Controller - recorder *MockAWSeBpfSdkAPIsMockRecorder + recorder *MockBpfSDKClientMockRecorder } -// MockAWSeBpfSdkAPIsMockRecorder is the mock recorder for MockAWSeBpfSdkAPIs. -type MockAWSeBpfSdkAPIsMockRecorder struct { - mock *MockAWSeBpfSdkAPIs +// MockBpfSDKClientMockRecorder is the mock recorder for MockBpfSDKClient. +type MockBpfSDKClientMockRecorder struct { + mock *MockBpfSDKClient } -// NewMockAWSeBpfSdkAPIs creates a new mock instance. -func NewMockAWSeBpfSdkAPIs(ctrl *gomock.Controller) *MockAWSeBpfSdkAPIs { - mock := &MockAWSeBpfSdkAPIs{ctrl: ctrl} - mock.recorder = &MockAWSeBpfSdkAPIsMockRecorder{mock} +// NewMockBpfSDKClient creates a new mock instance. +func NewMockBpfSDKClient(ctrl *gomock.Controller) *MockBpfSDKClient { + mock := &MockBpfSDKClient{ctrl: ctrl} + mock.recorder = &MockBpfSDKClientMockRecorder{mock} return mock } // EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockAWSeBpfSdkAPIs) EXPECT() *MockAWSeBpfSdkAPIsMockRecorder { +func (m *MockBpfSDKClient) EXPECT() *MockBpfSDKClientMockRecorder { return m.recorder } // IncreaseRlimit mocks base method. -func (m *MockAWSeBpfSdkAPIs) IncreaseRlimit() error { +func (m *MockBpfSDKClient) IncreaseRlimit() error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "IncreaseRlimit") ret0, _ := ret[0].(error) @@ -44,13 +44,13 @@ func (m *MockAWSeBpfSdkAPIs) IncreaseRlimit() error { } // IncreaseRlimit indicates an expected call of IncreaseRlimit. -func (mr *MockAWSeBpfSdkAPIsMockRecorder) IncreaseRlimit() *gomock.Call { +func (mr *MockBpfSDKClientMockRecorder) IncreaseRlimit() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IncreaseRlimit", reflect.TypeOf((*MockAWSeBpfSdkAPIs)(nil).IncreaseRlimit)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IncreaseRlimit", reflect.TypeOf((*MockBpfSDKClient)(nil).IncreaseRlimit)) } // LoadBpfFile mocks base method. -func (m *MockAWSeBpfSdkAPIs) LoadBpfFile(arg0, arg1 string) (map[string]elfparser.BpfData, map[string]maps.BpfMap, error) { +func (m *MockBpfSDKClient) LoadBpfFile(arg0, arg1 string) (map[string]elfparser.BpfData, map[string]maps.BpfMap, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "LoadBpfFile", arg0, arg1) ret0, _ := ret[0].(map[string]elfparser.BpfData) @@ -60,13 +60,13 @@ func (m *MockAWSeBpfSdkAPIs) LoadBpfFile(arg0, arg1 string) (map[string]elfparse } // LoadBpfFile indicates an expected call of LoadBpfFile. -func (mr *MockAWSeBpfSdkAPIsMockRecorder) LoadBpfFile(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockBpfSDKClientMockRecorder) LoadBpfFile(arg0, arg1 interface{}) *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadBpfFile", reflect.TypeOf((*MockAWSeBpfSdkAPIs)(nil).LoadBpfFile), arg0, arg1) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LoadBpfFile", reflect.TypeOf((*MockBpfSDKClient)(nil).LoadBpfFile), arg0, arg1) } // RecoverAllBpfProgramsAndMaps mocks base method. -func (m *MockAWSeBpfSdkAPIs) RecoverAllBpfProgramsAndMaps() (map[string]elfparser.BpfData, error) { +func (m *MockBpfSDKClient) RecoverAllBpfProgramsAndMaps() (map[string]elfparser.BpfData, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RecoverAllBpfProgramsAndMaps") ret0, _ := ret[0].(map[string]elfparser.BpfData) @@ -75,13 +75,13 @@ func (m *MockAWSeBpfSdkAPIs) RecoverAllBpfProgramsAndMaps() (map[string]elfparse } // RecoverAllBpfProgramsAndMaps indicates an expected call of RecoverAllBpfProgramsAndMaps. -func (mr *MockAWSeBpfSdkAPIsMockRecorder) RecoverAllBpfProgramsAndMaps() *gomock.Call { +func (mr *MockBpfSDKClientMockRecorder) RecoverAllBpfProgramsAndMaps() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecoverAllBpfProgramsAndMaps", reflect.TypeOf((*MockAWSeBpfSdkAPIs)(nil).RecoverAllBpfProgramsAndMaps)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecoverAllBpfProgramsAndMaps", reflect.TypeOf((*MockBpfSDKClient)(nil).RecoverAllBpfProgramsAndMaps)) } // RecoverGlobalMaps mocks base method. -func (m *MockAWSeBpfSdkAPIs) RecoverGlobalMaps() (map[string]maps.BpfMap, error) { +func (m *MockBpfSDKClient) RecoverGlobalMaps() (map[string]maps.BpfMap, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "RecoverGlobalMaps") ret0, _ := ret[0].(map[string]maps.BpfMap) @@ -90,7 +90,7 @@ func (m *MockAWSeBpfSdkAPIs) RecoverGlobalMaps() (map[string]maps.BpfMap, error) } // RecoverGlobalMaps indicates an expected call of RecoverGlobalMaps. -func (mr *MockAWSeBpfSdkAPIsMockRecorder) RecoverGlobalMaps() *gomock.Call { +func (mr *MockBpfSDKClientMockRecorder) RecoverGlobalMaps() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecoverGlobalMaps", reflect.TypeOf((*MockAWSeBpfSdkAPIs)(nil).RecoverGlobalMaps)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecoverGlobalMaps", reflect.TypeOf((*MockBpfSDKClient)(nil).RecoverGlobalMaps)) }