Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add minimum age check for pods #86

Merged
merged 3 commits into from
Jul 28, 2018
Merged

Add minimum age check for pods #86

merged 3 commits into from
Jul 28, 2018

Conversation

bakins
Copy link
Contributor

@bakins bakins commented Jul 20, 2018

For #85

Optionally filter pods based on age, excluding those that are not older than the passed minimum age.

I added a test specifically for the age check.

if err != nil {
return nil, err
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this function high-level and push most of into the filterBy... functions.

How about changing this to:

pods = filterByMinimumAge(pods, c.MinimumAge) // you can remove the `err`, I accidentally introduced it.

and then in filterByMinimumAge

func filterByMinimumAge(pods []v1.Pod, age time.Time) []v1.Pod {
 if age == 0 {
    return pods // early return unfiltered list
  }

  for _, pod := range pods {
  // ... like you already have

@@ -41,6 +41,8 @@ type Chaoskube struct {
DryRun bool
// a function to retrieve the current time
Now func() time.Time
// minimum age of pods to consider
MinimumAge time.Duration
Copy link
Owner

@linki linki Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's group the fields a little. Can we put this after Timezone and before Logger (you would also change the order of the function args, flags etc.)

@@ -40,6 +41,7 @@ func (suite *Suite) TestNew() {
excludedWeekdays = []time.Weekday{time.Friday}
excludedTimesOfDay = []util.TimePeriod{util.TimePeriod{}}
excludedDaysOfYear = []time.Time{time.Now()}
minimumAge = time.Duration(0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to put a specific value here to ensure it's really tested. I think time.Duration(0) is the default value for this type. How about using time.Duration(42) as the value 😃

},
// minimum age set, but pod is too young
{
time.Hour * 12,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests! For the sake of simplicity can we change the minimumAge values to something smaller like 1h or so? I think it will be easier to understand them then.

@bakins bakins force-pushed the filter-min-age branch 2 times, most recently from 58b4b2a to f242fad Compare July 24, 2018 15:34
@linki linki merged commit aab1e1d into linki:master Jul 28, 2018
@linki
Copy link
Owner

linki commented Jul 28, 2018

@bakins Thanks a lot!

@linki linki mentioned this pull request Aug 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants