Skip to content

Commit

Permalink
f - check for invalid sorting strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
brianberzins committed Apr 27, 2022
1 parent 975637b commit b7eb80a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion reaper/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
v1 "k8s.io/api/core/v1"
"os"
Expand Down Expand Up @@ -166,7 +167,14 @@ func maxPods() (int, error) {
}

func podSortingStrategy() (func([]v1.Pod), error) {
return func(pods []v1.Pod) {}, nil
sortingStrategy, present := os.LookupEnv(envPodSortingStrategy)
if !present {
return func(pods []v1.Pod) {}, nil
}
switch sortingStrategy {
default:
return nil, errors.New("unknown pod sorting strategy")
}
}

func evict() (bool, error) {
Expand Down
6 changes: 6 additions & 0 deletions reaper/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ func TestOptions(t *testing.T) {
sorter(subject)
assert.Equal(t, testPodList(), subject)
})
t.Run("invalid", func(t *testing.T) {
os.Clearenv()
os.Setenv(envPodSortingStrategy, "not a valid sorting strategy")
_, err := podSortingStrategy()
assert.Error(t, err)
})
})
}

Expand Down

0 comments on commit b7eb80a

Please sign in to comment.