Skip to content

Commit

Permalink
Merge pull request kubernetes#910 from pierewoj/master
Browse files Browse the repository at this point in the history
Allow changing default allowed restart count
  • Loading branch information
k8s-ci-robot authored Nov 27, 2019
2 parents 268813e + bb7a1e9 commit ab51d13
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
10 changes: 8 additions & 2 deletions clusterloader2/pkg/measurement/common/system_pod_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
systemPodMetricsEnabledFlagName = "systemPodMetricsEnabled"
restartThresholdOverridesFlagName = "restartCountThresholdOverrides"
enableRestartCountCheckFlagName = "enableRestartCountCheck"
defaultRestartCountThresholdKey = "default"
)

func init() {
Expand Down Expand Up @@ -194,9 +195,14 @@ func validateRestartCounts(metrics *systemPodsMetrics, config *measurement.Measu

func getMaxAllowedRestarts(containerName string, thresholdOverrides map[string]int) int {
if override, ok := thresholdOverrides[containerName]; ok {
return int(override)
return override
}
return 0 // default if no overrides specified
// This allows setting default threshold, which will be used for containers
// not present in the thresholdOverrides map.
if override, ok := thresholdOverrides[defaultRestartCountThresholdKey]; ok {
return override
}
return 0 // do not allow any restarts if no override and no default specified
}

/*
Expand Down
15 changes: 15 additions & 0 deletions clusterloader2/pkg/measurement/common/system_pod_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ func Test_validateRestartCounts(t *testing.T) {
config: buildConfig(t, true, map[string]int{"c": 3}),
wantErr: false,
},
{
name: "override-default-used",
metrics: generatePodMetrics("p", "c", 3),
config: buildConfig(t, true, map[string]int{"default": 3}),
wantErr: false,
},
{
name: "override-default-not-used",
metrics: generatePodMetrics("p", "c", 3),
config: buildConfig(t, true, map[string]int{
"default": 5,
"c": 0,
}),
wantErr: true,
},
{
name: "override-below-actual-count",
metrics: generatePodMetrics("p", "c", 3),
Expand Down

0 comments on commit ab51d13

Please sign in to comment.