1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 05:14:13 +01:00

Merge pull request #296 from ingvagabund/make-Params-a-pointer

Make DeschedulerStrategy.Params a pointer
This commit is contained in:
Kubernetes Prow Robot
2020-05-28 22:53:15 -07:00
committed by GitHub
16 changed files with 32 additions and 24 deletions

View File

@@ -41,7 +41,7 @@ type DeschedulerStrategy struct {
Weight int Weight int
// Strategy parameters // Strategy parameters
Params StrategyParameters Params *StrategyParameters
} }
// Only one of its members may be specified // Only one of its members may be specified

View File

@@ -41,7 +41,7 @@ type DeschedulerStrategy struct {
Weight int `json:"weight,omitempty"` Weight int `json:"weight,omitempty"`
// Strategy parameters // Strategy parameters
Params StrategyParameters `json:"params,omitempty"` Params *StrategyParameters `json:"params,omitempty"`
} }
// Only one of its members may be specified // Only one of its members may be specified

View File

@@ -121,9 +121,7 @@ func Convert_api_DeschedulerPolicy_To_v1alpha1_DeschedulerPolicy(in *api.Desched
func autoConvert_v1alpha1_DeschedulerStrategy_To_api_DeschedulerStrategy(in *DeschedulerStrategy, out *api.DeschedulerStrategy, s conversion.Scope) error { func autoConvert_v1alpha1_DeschedulerStrategy_To_api_DeschedulerStrategy(in *DeschedulerStrategy, out *api.DeschedulerStrategy, s conversion.Scope) error {
out.Enabled = in.Enabled out.Enabled = in.Enabled
out.Weight = in.Weight out.Weight = in.Weight
if err := Convert_v1alpha1_StrategyParameters_To_api_StrategyParameters(&in.Params, &out.Params, s); err != nil { out.Params = (*api.StrategyParameters)(unsafe.Pointer(in.Params))
return err
}
return nil return nil
} }
@@ -135,9 +133,7 @@ func Convert_v1alpha1_DeschedulerStrategy_To_api_DeschedulerStrategy(in *Desched
func autoConvert_api_DeschedulerStrategy_To_v1alpha1_DeschedulerStrategy(in *api.DeschedulerStrategy, out *DeschedulerStrategy, s conversion.Scope) error { func autoConvert_api_DeschedulerStrategy_To_v1alpha1_DeschedulerStrategy(in *api.DeschedulerStrategy, out *DeschedulerStrategy, s conversion.Scope) error {
out.Enabled = in.Enabled out.Enabled = in.Enabled
out.Weight = in.Weight out.Weight = in.Weight
if err := Convert_api_StrategyParameters_To_v1alpha1_StrategyParameters(&in.Params, &out.Params, s); err != nil { out.Params = (*StrategyParameters)(unsafe.Pointer(in.Params))
return err
}
return nil return nil
} }

View File

@@ -59,7 +59,11 @@ func (in *DeschedulerPolicy) DeepCopyObject() runtime.Object {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DeschedulerStrategy) DeepCopyInto(out *DeschedulerStrategy) { func (in *DeschedulerStrategy) DeepCopyInto(out *DeschedulerStrategy) {
*out = *in *out = *in
in.Params.DeepCopyInto(&out.Params) if in.Params != nil {
in, out := &in.Params, &out.Params
*out = new(StrategyParameters)
(*in).DeepCopyInto(*out)
}
return return
} }

View File

@@ -59,7 +59,11 @@ func (in *DeschedulerPolicy) DeepCopyObject() runtime.Object {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DeschedulerStrategy) DeepCopyInto(out *DeschedulerStrategy) { func (in *DeschedulerStrategy) DeepCopyInto(out *DeschedulerStrategy) {
*out = *in *out = *in
in.Params.DeepCopyInto(&out.Params) if in.Params != nil {
in, out := &in.Params, &out.Params
*out = new(StrategyParameters)
(*in).DeepCopyInto(*out)
}
return return
} }

View File

@@ -116,7 +116,7 @@ func listDuplicatePodsOnANode(ctx context.Context, client clientset.Interface, n
} }
func hasExcludedOwnerRefKind(ownerRefs []metav1.OwnerReference, strategy api.DeschedulerStrategy) bool { func hasExcludedOwnerRefKind(ownerRefs []metav1.OwnerReference, strategy api.DeschedulerStrategy) bool {
if strategy.Params.RemoveDuplicates == nil { if strategy.Params == nil || strategy.Params.RemoveDuplicates == nil {
return false return false
} }
exclude := sets.NewString(strategy.Params.RemoveDuplicates.ExcludeOwnerKinds...) exclude := sets.NewString(strategy.Params.RemoveDuplicates.ExcludeOwnerKinds...)

View File

@@ -132,7 +132,7 @@ func TestFindDuplicatePods(t *testing.T) {
maxPodsToEvict: 5, maxPodsToEvict: 5,
pods: []v1.Pod{*p1, *p2, *p3}, pods: []v1.Pod{*p1, *p2, *p3},
expectedEvictedPodCount: 0, expectedEvictedPodCount: 0,
strategy: api.DeschedulerStrategy{Params: api.StrategyParameters{RemoveDuplicates: &api.RemoveDuplicates{ExcludeOwnerKinds: []string{"ReplicaSet"}}}}, strategy: api.DeschedulerStrategy{Params: &api.StrategyParameters{RemoveDuplicates: &api.RemoveDuplicates{ExcludeOwnerKinds: []string{"ReplicaSet"}}}},
}, },
{ {
description: "Three Pods in the `test` Namespace, bound to same ReplicaSet. 2 should be evicted.", description: "Three Pods in the `test` Namespace, bound to same ReplicaSet. 2 should be evicted.",

View File

@@ -49,7 +49,7 @@ const (
func LowNodeUtilization(ctx context.Context, client clientset.Interface, strategy api.DeschedulerStrategy, nodes []*v1.Node, evictLocalStoragePods bool, podEvictor *evictions.PodEvictor) { func LowNodeUtilization(ctx context.Context, client clientset.Interface, strategy api.DeschedulerStrategy, nodes []*v1.Node, evictLocalStoragePods bool, podEvictor *evictions.PodEvictor) {
// todo: move to config validation? // todo: move to config validation?
// TODO: May be create a struct for the strategy as well, so that we don't have to pass along the all the params? // TODO: May be create a struct for the strategy as well, so that we don't have to pass along the all the params?
if strategy.Params.NodeResourceUtilizationThresholds == nil { if strategy.Params == nil || strategy.Params.NodeResourceUtilizationThresholds == nil {
klog.V(1).Infof("NodeResourceUtilizationThresholds not set") klog.V(1).Infof("NodeResourceUtilizationThresholds not set")
return return
} }

View File

@@ -702,7 +702,7 @@ func TestWithTaints(t *testing.T) {
ctx := context.Background() ctx := context.Background()
strategy := api.DeschedulerStrategy{ strategy := api.DeschedulerStrategy{
Enabled: true, Enabled: true,
Params: api.StrategyParameters{ Params: &api.StrategyParameters{
NodeResourceUtilizationThresholds: &api.NodeResourceUtilizationThresholds{ NodeResourceUtilizationThresholds: &api.NodeResourceUtilizationThresholds{
Thresholds: api.ResourceThresholds{ Thresholds: api.ResourceThresholds{
v1.ResourcePods: 20, v1.ResourcePods: 20,

View File

@@ -30,6 +30,10 @@ import (
) )
func RemovePodsViolatingNodeAffinity(ctx context.Context, client clientset.Interface, strategy api.DeschedulerStrategy, nodes []*v1.Node, evictLocalStoragePods bool, podEvictor *evictions.PodEvictor) { func RemovePodsViolatingNodeAffinity(ctx context.Context, client clientset.Interface, strategy api.DeschedulerStrategy, nodes []*v1.Node, evictLocalStoragePods bool, podEvictor *evictions.PodEvictor) {
if strategy.Params == nil {
klog.V(1).Infof("NodeAffinityType not set")
return
}
for _, nodeAffinity := range strategy.Params.NodeAffinityType { for _, nodeAffinity := range strategy.Params.NodeAffinityType {
klog.V(2).Infof("Executing for nodeAffinityType: %v", nodeAffinity) klog.V(2).Infof("Executing for nodeAffinityType: %v", nodeAffinity)

View File

@@ -33,7 +33,7 @@ func TestRemovePodsViolatingNodeAffinity(t *testing.T) {
ctx := context.Background() ctx := context.Background()
requiredDuringSchedulingIgnoredDuringExecutionStrategy := api.DeschedulerStrategy{ requiredDuringSchedulingIgnoredDuringExecutionStrategy := api.DeschedulerStrategy{
Enabled: true, Enabled: true,
Params: api.StrategyParameters{ Params: &api.StrategyParameters{
NodeAffinityType: []string{ NodeAffinityType: []string{
"requiredDuringSchedulingIgnoredDuringExecution", "requiredDuringSchedulingIgnoredDuringExecution",
}, },
@@ -99,7 +99,7 @@ func TestRemovePodsViolatingNodeAffinity(t *testing.T) {
description: "Invalid strategy type, should not evict any pods", description: "Invalid strategy type, should not evict any pods",
strategy: api.DeschedulerStrategy{ strategy: api.DeschedulerStrategy{
Enabled: true, Enabled: true,
Params: api.StrategyParameters{ Params: &api.StrategyParameters{
NodeAffinityType: []string{ NodeAffinityType: []string{
"requiredDuringSchedulingRequiredDuringExecution", "requiredDuringSchedulingRequiredDuringExecution",
}, },

View File

@@ -31,7 +31,7 @@ import (
// PodLifeTime evicts pods on nodes that were created more than strategy.Params.MaxPodLifeTimeSeconds seconds ago. // PodLifeTime evicts pods on nodes that were created more than strategy.Params.MaxPodLifeTimeSeconds seconds ago.
func PodLifeTime(ctx context.Context, client clientset.Interface, strategy api.DeschedulerStrategy, nodes []*v1.Node, evictLocalStoragePods bool, podEvictor *evictions.PodEvictor) { func PodLifeTime(ctx context.Context, client clientset.Interface, strategy api.DeschedulerStrategy, nodes []*v1.Node, evictLocalStoragePods bool, podEvictor *evictions.PodEvictor) {
if strategy.Params.MaxPodLifeTimeSeconds == nil { if strategy.Params == nil || strategy.Params.MaxPodLifeTimeSeconds == nil {
klog.V(1).Infof("MaxPodLifeTimeSeconds not set") klog.V(1).Infof("MaxPodLifeTimeSeconds not set")
return return
} }

View File

@@ -97,7 +97,7 @@ func TestPodLifeTime(t *testing.T) {
description: "Two pods in the `dev` Namespace, 1 is new and 1 very is old. 1 should be evicted.", description: "Two pods in the `dev` Namespace, 1 is new and 1 very is old. 1 should be evicted.",
strategy: api.DeschedulerStrategy{ strategy: api.DeschedulerStrategy{
Enabled: true, Enabled: true,
Params: api.StrategyParameters{ Params: &api.StrategyParameters{
MaxPodLifeTimeSeconds: &maxLifeTime, MaxPodLifeTimeSeconds: &maxLifeTime,
}, },
}, },
@@ -109,7 +109,7 @@ func TestPodLifeTime(t *testing.T) {
description: "Two pods in the `dev` Namespace, 2 are new and 0 are old. 0 should be evicted.", description: "Two pods in the `dev` Namespace, 2 are new and 0 are old. 0 should be evicted.",
strategy: api.DeschedulerStrategy{ strategy: api.DeschedulerStrategy{
Enabled: true, Enabled: true,
Params: api.StrategyParameters{ Params: &api.StrategyParameters{
MaxPodLifeTimeSeconds: &maxLifeTime, MaxPodLifeTimeSeconds: &maxLifeTime,
}, },
}, },
@@ -121,7 +121,7 @@ func TestPodLifeTime(t *testing.T) {
description: "Two pods in the `dev` Namespace, 1 created 605 seconds ago. 1 should be evicted.", description: "Two pods in the `dev` Namespace, 1 created 605 seconds ago. 1 should be evicted.",
strategy: api.DeschedulerStrategy{ strategy: api.DeschedulerStrategy{
Enabled: true, Enabled: true,
Params: api.StrategyParameters{ Params: &api.StrategyParameters{
MaxPodLifeTimeSeconds: &maxLifeTime, MaxPodLifeTimeSeconds: &maxLifeTime,
}, },
}, },
@@ -133,7 +133,7 @@ func TestPodLifeTime(t *testing.T) {
description: "Two pods in the `dev` Namespace, 1 created 595 seconds ago. 0 should be evicted.", description: "Two pods in the `dev` Namespace, 1 created 595 seconds ago. 0 should be evicted.",
strategy: api.DeschedulerStrategy{ strategy: api.DeschedulerStrategy{
Enabled: true, Enabled: true,
Params: api.StrategyParameters{ Params: &api.StrategyParameters{
MaxPodLifeTimeSeconds: &maxLifeTime, MaxPodLifeTimeSeconds: &maxLifeTime,
}, },
}, },

View File

@@ -32,7 +32,7 @@ import (
// There are too many cases leading this issue: Volume mount failed, app error due to nodes' different settings. // There are too many cases leading this issue: Volume mount failed, app error due to nodes' different settings.
// As of now, this strategy won't evict daemonsets, mirror pods, critical pods and pods with local storages. // As of now, this strategy won't evict daemonsets, mirror pods, critical pods and pods with local storages.
func RemovePodsHavingTooManyRestarts(ctx context.Context, client clientset.Interface, strategy api.DeschedulerStrategy, nodes []*v1.Node, evictLocalStoragePods bool, podEvictor *evictions.PodEvictor) { func RemovePodsHavingTooManyRestarts(ctx context.Context, client clientset.Interface, strategy api.DeschedulerStrategy, nodes []*v1.Node, evictLocalStoragePods bool, podEvictor *evictions.PodEvictor) {
if strategy.Params.PodsHavingTooManyRestarts == nil || strategy.Params.PodsHavingTooManyRestarts.PodRestartThreshold < 1 { if strategy.Params == nil || strategy.Params.PodsHavingTooManyRestarts == nil || strategy.Params.PodsHavingTooManyRestarts.PodRestartThreshold < 1 {
klog.V(1).Infof("PodsHavingTooManyRestarts thresholds not set") klog.V(1).Infof("PodsHavingTooManyRestarts thresholds not set")
return return
} }

View File

@@ -84,7 +84,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) {
createStrategy := func(enabled, includingInitContainers bool, restartThresholds int32) api.DeschedulerStrategy { createStrategy := func(enabled, includingInitContainers bool, restartThresholds int32) api.DeschedulerStrategy {
return api.DeschedulerStrategy{ return api.DeschedulerStrategy{
Enabled: enabled, Enabled: enabled,
Params: api.StrategyParameters{ Params: &api.StrategyParameters{
PodsHavingTooManyRestarts: &api.PodsHavingTooManyRestarts{ PodsHavingTooManyRestarts: &api.PodsHavingTooManyRestarts{
PodRestartThreshold: restartThresholds, PodRestartThreshold: restartThresholds,
IncludingInitContainers: includingInitContainers, IncludingInitContainers: includingInitContainers,

View File

@@ -118,7 +118,7 @@ func startEndToEndForLowNodeUtilization(ctx context.Context, clientset clientset
lowNodeUtilizationStrategy := deschedulerapi.DeschedulerStrategy{ lowNodeUtilizationStrategy := deschedulerapi.DeschedulerStrategy{
Enabled: true, Enabled: true,
Params: deschedulerapi.StrategyParameters{ Params: &deschedulerapi.StrategyParameters{
NodeResourceUtilizationThresholds: &deschedulerapi.NodeResourceUtilizationThresholds{ NodeResourceUtilizationThresholds: &deschedulerapi.NodeResourceUtilizationThresholds{
Thresholds: thresholds, Thresholds: thresholds,
TargetThresholds: targetThresholds, TargetThresholds: targetThresholds,