Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: fluxcd/helm-controller
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 65415243287142e6e6f3206abff45ed987ff88f5
Choose a base ref
..
head repository: fluxcd/helm-controller
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f2f51c03fcdb883da152e94795adbe01e760de63
Choose a head ref
Showing with 16 additions and 16 deletions.
  1. +16 −16 internal/oomwatch/watch.go
32 changes: 16 additions & 16 deletions internal/oomwatch/watch.go
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ type Watcher struct {
// paths are empty, it will attempt to discover the paths to the cgroup files.
// It returns an error if the paths cannot be discovered or if the provided
// configuration is invalid.
func New(maxMemoryPath, currentMemoryPath string, memoryUsagePercentThreshold uint8, interval time.Duration, logger logr.Logger) (_ *Watcher, err error) {
func New(memoryMaxPath, memoryCurrentPath string, memoryUsagePercentThreshold uint8, interval time.Duration, logger logr.Logger) (_ *Watcher, err error) {
if memoryUsagePercentThreshold < 1 || memoryUsagePercentThreshold > 100 {
return nil, fmt.Errorf("memory usage percent threshold must be between 1 and 100, got %d", memoryUsagePercentThreshold)
}
@@ -88,23 +88,23 @@ func New(maxMemoryPath, currentMemoryPath string, memoryUsagePercentThreshold ui
return nil, fmt.Errorf("interval must be at least %s, got %s", minInterval, interval)
}

maxMemoryPath, currentMemoryPath, err = discoverCgroupPaths(maxMemoryPath, currentMemoryPath)
memoryMaxPath, memoryCurrentPath, err = discoverCgroupPaths(memoryMaxPath, memoryCurrentPath)
if err != nil {
return nil, err
}

if _, err := os.Lstat(currentMemoryPath); err != nil {
if _, err = os.Lstat(memoryCurrentPath); err != nil {
return nil, fmt.Errorf("failed to confirm existence of current memory usage path: %w", err)
}

memoryMax, err := readUintFromFile(maxMemoryPath)
memoryMax, err := readUintFromFile(memoryMaxPath)
if err != nil {
return nil, fmt.Errorf("failed to read maximum memory usage: %w", err)
}

return &Watcher{
memoryMax: memoryMax,
memoryCurrentPath: currentMemoryPath,
memoryCurrentPath: memoryCurrentPath,
memoryUsagePercentThreshold: memoryUsagePercentThreshold,
interval: interval,
logger: logger,
@@ -159,39 +159,39 @@ func (w *Watcher) watchForNearOOM(ctx context.Context) {
// paths for the max and current memory files when they are not provided. It
// returns the discovered and/or provided max and current paths.
// When a path is not provided and cannot be discovered, an error is returned.
func discoverCgroupPaths(maxMemoryPath, currentMemoryPath string) (string, string, error) {
if maxMemoryPath == "" {
func discoverCgroupPaths(memoryMaxPath, memoryCurrentPath string) (string, string, error) {
if memoryMaxPath == "" {
maxPathV1 := filepath.Join(DefaultCgroupPath, MemoryLimitFile)
maxPathV2 := filepath.Join(DefaultCgroupPath, MemoryMaxFile)

if _, err := os.Lstat(maxPathV2); err == nil {
maxMemoryPath = maxPathV2
memoryMaxPath = maxPathV2
} else if _, err = os.Lstat(maxPathV1); err == nil {
maxMemoryPath = maxPathV1
memoryMaxPath = maxPathV1
}
}
if currentMemoryPath == "" {
if memoryCurrentPath == "" {
currentPathV1 := filepath.Join(DefaultCgroupPath, MemoryUsageFile)
currentPathV2 := filepath.Join(DefaultCgroupPath, MemoryCurrentFile)

if _, err := os.Lstat(currentPathV2); err == nil {
currentMemoryPath = currentPathV2
memoryCurrentPath = currentPathV2
} else if _, err = os.Lstat(currentPathV1); err == nil {
currentMemoryPath = currentPathV1
memoryCurrentPath = currentPathV1
}
}

if maxMemoryPath == "" && currentMemoryPath == "" {
if memoryMaxPath == "" && memoryCurrentPath == "" {
return "", "", fmt.Errorf("failed to discover cgroup paths, please specify them manually")
}
if maxMemoryPath == "" {
if memoryMaxPath == "" {
return "", "", fmt.Errorf("failed to discover max memory path, please specify it manually")
}
if currentMemoryPath == "" {
if memoryCurrentPath == "" {
return "", "", fmt.Errorf("failed to discover current memory path, please specify it manually")
}

return maxMemoryPath, currentMemoryPath, nil
return memoryMaxPath, memoryCurrentPath, nil
}

// readUintFromFile reads an uint64 from the file at the given path.