Skip to content

Commit 0c7e5e4

Browse files
authored
[CWS] make cgroup getter naming clear (#43992)
### What does this PR do? Rename cgroup getters so that it is clear what kind of workload is returned ### Motivation ### Describe how you validated your changes ### Additional Notes Co-authored-by: sylvain.afchain <sylvain.afchain@datadoghq.com>
1 parent 80ae8a9 commit 0c7e5e4

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

pkg/security/probe/field_handlers_ebpf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func (fh *EBPFFieldHandlers) ResolveContainerContext(ev *model.Event) (*model.Co
242242
}
243243

244244
if ev.ProcessContext.ContainerContext.ContainerID != "" {
245-
if containerContext, _ := fh.resolvers.CGroupResolver.GetWorkload(ev.ProcessContext.ContainerContext.ContainerID); containerContext != nil {
245+
if containerContext, _ := fh.resolvers.CGroupResolver.GetContainerWorkload(ev.ProcessContext.ContainerContext.ContainerID); containerContext != nil {
246246
ev.ProcessContext.ContainerContext = containerContext.ContainerContext
247247
ev.ProcessContext.ContainerContext.Resolved = true
248248
}

pkg/security/resolvers/cgroup/resolver.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ func (cr *Resolver) iterate(cb func(*cgroupModel.CacheEntry) bool) {
348348
}
349349
}
350350

351-
// GetWorkload returns the workload referenced by the provided ID
352-
func (cr *Resolver) GetWorkload(id containerutils.ContainerID) (*cgroupModel.CacheEntry, bool) {
351+
// GetContainerWorkload returns the workload referenced by the provided container ID
352+
func (cr *Resolver) GetContainerWorkload(id containerutils.ContainerID) (*cgroupModel.CacheEntry, bool) {
353353
if id == "" {
354354
return nil, false
355355
}
@@ -360,8 +360,8 @@ func (cr *Resolver) GetWorkload(id containerutils.ContainerID) (*cgroupModel.Cac
360360
return cr.containerWorkloads.Get(id)
361361
}
362362

363-
// GetWorkloadByCGroupID returns the workload referenced by the provided cgroup ID
364-
func (cr *Resolver) GetWorkloadByCGroupID(cgroupID containerutils.CGroupID) (*cgroupModel.CacheEntry, bool) {
363+
// GetHostWorkload returns the workload referenced by the provided cgroup ID
364+
func (cr *Resolver) GetHostWorkload(cgroupID containerutils.CGroupID) (*cgroupModel.CacheEntry, bool) {
365365
if cgroupID == "" {
366366
return nil, false
367367
}

pkg/security/resolvers/file/resolver_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (r *Resolver) ResolveFileMetadata(event *model.Event, file *model.FileEvent
101101
process := event.ProcessContext.Process
102102
rootPIDs := []uint32{process.Pid, 1}
103103
if process.ContainerContext.ContainerID != "" && r.cgroupResolver != nil {
104-
w, ok := r.cgroupResolver.GetWorkload(process.ContainerContext.ContainerID)
104+
w, ok := r.cgroupResolver.GetContainerWorkload(process.ContainerContext.ContainerID)
105105
if ok {
106106
rootPIDs = w.GetPIDs()
107107
}

pkg/security/resolvers/hash/resolver_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (resolver *Resolver) HashFileEvent(eventType model.EventType, ctrID contain
276276
// add pid one for hash resolution outside of a container
277277
rootPIDs := []uint32{1, pid}
278278
if resolver.cgroupResolver != nil {
279-
w, ok := resolver.cgroupResolver.GetWorkload(ctrID)
279+
w, ok := resolver.cgroupResolver.GetContainerWorkload(ctrID)
280280
if ok {
281281
rootPIDs = w.GetPIDs()
282282
}

pkg/security/resolvers/usergroup/resolver_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (r *Resolver) getFilesystem(containerID containerutils.ContainerID) (fs.FS,
8080
var fsys fs.FS
8181

8282
if containerID != "" {
83-
cgroupEntry, found := r.cgroupResolver.GetWorkload(containerID)
83+
cgroupEntry, found := r.cgroupResolver.GetContainerWorkload(containerID)
8484
if !found {
8585
return nil, fmt.Errorf("failed to resolve container %s", containerID)
8686
}

pkg/security/security_profile/ad.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,12 @@ func (m *Manager) cleanupTracedPids(ad *dump.ActivityDump) {
367367
// Try to get workload from cgroup resolver
368368
if ad.Profile.Metadata.ContainerID != "" {
369369
// Container workload
370-
if workload, found := m.resolvers.CGroupResolver.GetWorkload(ad.Profile.Metadata.ContainerID); found {
370+
if workload, found := m.resolvers.CGroupResolver.GetContainerWorkload(ad.Profile.Metadata.ContainerID); found {
371371
pids = workload.GetPIDs()
372372
}
373373
} else if ad.Profile.Metadata.CGroupContext.CGroupID != "" {
374374
// Host workload
375-
if workload, found := m.resolvers.CGroupResolver.GetWorkloadByCGroupID(ad.Profile.Metadata.CGroupContext.CGroupID); found {
375+
if workload, found := m.resolvers.CGroupResolver.GetHostWorkload(ad.Profile.Metadata.CGroupContext.CGroupID); found {
376376
pids = workload.GetPIDs()
377377
}
378378
}

0 commit comments

Comments
 (0)