Skip to content

Commit 232fb70

Browse files
authored
Merge pull request #1543 from adity1raut/TestCoverage2
Add unit tests for /pkg/controller/netns/netns.go
2 parents 08d75e4 + b85e001 commit 232fb70

File tree

2 files changed

+637
-2
lines changed

2 files changed

+637
-2
lines changed

pkg/controller/netns/netns.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func FindNetnsForPod(pod *corev1.Pod) (string, error) {
7878
return res, nil
7979
}
8080
}
81-
return "", fmt.Errorf("No matching network namespace found")
81+
return "", fmt.Errorf("no matching network namespace found")
8282
}
8383

8484
func isNotNumber(r rune) bool {
@@ -121,7 +121,12 @@ func processEntry(proc fs.FS, netnsObserved sets.Set[uint64], filter types.UID,
121121
if err != nil {
122122
return "", nil
123123
}
124-
defer cgroup.Close()
124+
defer func() {
125+
if err := cgroup.Close(); err != nil {
126+
// Log the error or handle it appropriately
127+
log.Errorf("Failed to close cgroup file: %v", err)
128+
}
129+
}()
125130

126131
var cgroupData bytes.Buffer
127132
_, err = io.Copy(&cgroupData, cgroup)

0 commit comments

Comments
 (0)