Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
damemi committed Mar 31, 2020
1 parent 1eb3c52 commit 99bcf5b
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 1,561 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ strategies:
enabled: true
params:
podsHavingTooManyRestarts:
podeRestartThresholds: 100
podRestartThresholds: 100
includingInitContainers: true
```

Expand Down
2 changes: 1 addition & 1 deletion examples/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ strategies:
enabled: true
params:
podsHavingTooManyRestarts:
podeRestartThresholds: 100
podRestartThresholds: 100
includingInitContainers: true
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.13

require (
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
k8s.io/api v0.17.0
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ type NodeResourceUtilizationThresholds struct {
}

type PodsHavingTooManyRestarts struct {
PodeRestartThresholds int32
PodRestartThresholds int32
IncludingInitContainers bool
}
2 changes: 1 addition & 1 deletion pkg/api/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ type NodeResourceUtilizationThresholds struct {
}

type PodsHavingTooManyRestarts struct {
PodeRestartThresholds int32 `json:"podeRestartThresholds,omitempty"`
PodRestartThresholds int32 `json:"podRestartThresholds,omitempty"`
IncludingInitContainers bool `json:"includingInitContainers,omitempty"`
}
4 changes: 2 additions & 2 deletions pkg/api/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 11 additions & 12 deletions pkg/descheduler/strategies/toomanyrestarts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ limitations under the License.
package strategies

import (
"github.com/golang/glog"

"k8s.io/api/core/v1"
"k8s.io/klog"

"sigs.k8s.io/descheduler/cmd/descheduler/app/options"
"sigs.k8s.io/descheduler/pkg/api"
Expand All @@ -33,23 +32,23 @@ import (
// As of now, this strategy won't evict daemonsets, mirror pods, critical pods and pods with local storages.
func RemovePodsHavingTooManyRestarts(ds *options.DeschedulerServer, strategy api.DeschedulerStrategy, policyGroupVersion string, nodes []*v1.Node, nodePodCount utils.NodePodEvictedCount) {
evictionCount := removePodsHavingTooManyRestarts(ds, strategy, policyGroupVersion, nodes, nodePodCount, ds.EvictLocalStoragePods)
glog.V(1).Infof("RemovePodsHavingTooManyRestarts evicted %v pods", evictionCount)
klog.V(1).Infof("RemovePodsHavingTooManyRestarts evicted %v pods", evictionCount)
}

func removePodsHavingTooManyRestarts(ds *options.DeschedulerServer, strategy api.DeschedulerStrategy, policyGroupVersion string, nodes []*v1.Node, nodePodCount utils.NodePodEvictedCount, evictLocalStoragePods bool) int {
podsEvicted := 0

if !strategy.Enabled || strategy.Params.PodsHavingTooManyRestarts.PodeRestartThresholds < 1 {
glog.Info("RemovePodsHavingTooManyRestarts policy is disabled.")
if !strategy.Enabled || strategy.Params.PodsHavingTooManyRestarts.PodRestartThresholds < 1 {
klog.Info("RemovePodsHavingTooManyRestarts policy is disabled.")
return podsEvicted
}

for _, node := range nodes {
glog.V(1).Infof("RemovePodsHavingTooManyRestarts Processing node: %#v", node.Name)
klog.V(1).Infof("RemovePodsHavingTooManyRestarts Processing node: %#v", node.Name)
pods, err := podutil.ListEvictablePodsOnNode(ds.Client, node, evictLocalStoragePods)

if err != nil {
glog.Errorf("RemovePodsHavingTooManyRestarts Error when list pods at node %s", node.Name)
klog.Errorf("RemovePodsHavingTooManyRestarts Error when list pods at node %s", node.Name)
continue
}
for _, pod := range pods {
Expand All @@ -59,20 +58,20 @@ func removePodsHavingTooManyRestarts(ds *options.DeschedulerServer, strategy api

restarts, initRestarts := calcContainerRestarts(pod)
if strategy.Params.PodsHavingTooManyRestarts.IncludingInitContainers {
if restarts+initRestarts <= strategy.Params.PodsHavingTooManyRestarts.PodeRestartThresholds {
if restarts+initRestarts <= strategy.Params.PodsHavingTooManyRestarts.PodRestartThresholds {
continue
}
} else if restarts <= strategy.Params.PodsHavingTooManyRestarts.PodeRestartThresholds {
} else if restarts <= strategy.Params.PodsHavingTooManyRestarts.PodRestartThresholds {
continue
}

glog.V(1).Infof("RemovePodsHavingTooManyRestarts will evicted pod: %#v, container restarts: %d, initContainer restarts: %d", pod.Name, restarts, initRestarts)
klog.V(1).Infof("RemovePodsHavingTooManyRestarts will evicted pod: %#v, container restarts: %d, initContainer restarts: %d", pod.Name, restarts, initRestarts)
success, err := evictions.EvictPod(ds.Client, pod, policyGroupVersion, ds.DryRun)
if !success {
glog.Infof("RemovePodsHavingTooManyRestarts Error when evicting pod: %#v (%#v)", pod.Name, err)
klog.Infof("RemovePodsHavingTooManyRestarts Error when evicting pod: %#v (%#v)", pod.Name, err)
} else {
nodePodCount[node]++
glog.V(1).Infof("RemovePodsHavingTooManyRestarts Evicted pod: %#v (%#v)", pod.Name, err)
klog.V(1).Infof("RemovePodsHavingTooManyRestarts Evicted pod: %#v (%#v)", pod.Name, err)
}
}
podsEvicted += nodePodCount[node]
Expand Down
2 changes: 1 addition & 1 deletion pkg/descheduler/strategies/toomanyrestarts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) {
Enabled: enabled,
Params: api.StrategyParameters{
PodsHavingTooManyRestarts: api.PodsHavingTooManyRestarts{
PodeRestartThresholds: restartThresholds,
PodRestartThresholds: restartThresholds,
IncludingInitContainers: includingInitContainers,
},
},
Expand Down
191 changes: 0 additions & 191 deletions vendor/github.com/golang/glog/LICENSE

This file was deleted.

44 changes: 0 additions & 44 deletions vendor/github.com/golang/glog/README

This file was deleted.

Loading

0 comments on commit 99bcf5b

Please sign in to comment.