Skip to content

Commit

Permalink
Update sdk client for NA mocks (#26)
Browse files Browse the repository at this point in the history
* Update sdk client

* fix var
  • Loading branch information
jayanthvn authored Aug 17, 2023
1 parent 3941711 commit ed84377
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
18 changes: 9 additions & 9 deletions pkg/elfparser/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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/[email protected]/
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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/elfparser/generate_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 24 additions & 24 deletions pkg/elfparser/mocks/elfparser_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ed84377

Please sign in to comment.