mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-26 21:31:18 +01:00
update deprecated sets.String to generic sets
This commit is contained in:
@@ -282,9 +282,9 @@ func evictPods(
|
||||
podEvictor frameworktypes.Evictor,
|
||||
continueEviction continueEvictionCond,
|
||||
) {
|
||||
var excludedNamespaces sets.String
|
||||
var excludedNamespaces sets.Set[string]
|
||||
if evictableNamespaces != nil {
|
||||
excludedNamespaces = sets.NewString(evictableNamespaces.Exclude...)
|
||||
excludedNamespaces = sets.New(evictableNamespaces.Exclude...)
|
||||
}
|
||||
|
||||
if continueEviction(nodeInfo, totalAvailableUsage) {
|
||||
|
||||
@@ -49,10 +49,10 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
|
||||
return nil, fmt.Errorf("want args to be of type PodLifeTimeArgs, got %T", args)
|
||||
}
|
||||
|
||||
var includedNamespaces, excludedNamespaces sets.String
|
||||
var includedNamespaces, excludedNamespaces sets.Set[string]
|
||||
if podLifeTimeArgs.Namespaces != nil {
|
||||
includedNamespaces = sets.NewString(podLifeTimeArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.NewString(podLifeTimeArgs.Namespaces.Exclude...)
|
||||
includedNamespaces = sets.New(podLifeTimeArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.New(podLifeTimeArgs.Namespaces.Exclude...)
|
||||
}
|
||||
|
||||
// We can combine Filter and PreEvictionFilter since for this strategy it does not matter where we run PreEvictionFilter
|
||||
@@ -72,7 +72,7 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
|
||||
})
|
||||
|
||||
if len(podLifeTimeArgs.States) > 0 {
|
||||
states := sets.NewString(podLifeTimeArgs.States...)
|
||||
states := sets.New(podLifeTimeArgs.States...)
|
||||
podFilter = podutil.WrapFilterFuncs(podFilter, func(pod *v1.Pod) bool {
|
||||
if states.Has(string(pod.Status.Phase)) {
|
||||
return true
|
||||
|
||||
@@ -43,7 +43,7 @@ func ValidatePodLifeTimeArgs(obj runtime.Object) error {
|
||||
return fmt.Errorf("failed to get label selectors from strategy's params: %+v", err)
|
||||
}
|
||||
}
|
||||
podLifeTimeAllowedStates := sets.NewString(
|
||||
podLifeTimeAllowedStates := sets.New(
|
||||
string(v1.PodRunning),
|
||||
string(v1.PodPending),
|
||||
|
||||
@@ -53,7 +53,7 @@ func ValidatePodLifeTimeArgs(obj runtime.Object) error {
|
||||
)
|
||||
|
||||
if !podLifeTimeAllowedStates.HasAll(args.States...) {
|
||||
return fmt.Errorf("states must be one of %v", podLifeTimeAllowedStates.List())
|
||||
return fmt.Errorf("states must be one of %v", podLifeTimeAllowedStates.UnsortedList())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -64,10 +64,10 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
|
||||
return nil, fmt.Errorf("want args to be of type RemoveDuplicatesArgs, got %T", args)
|
||||
}
|
||||
|
||||
var includedNamespaces, excludedNamespaces sets.String
|
||||
var includedNamespaces, excludedNamespaces sets.Set[string]
|
||||
if removeDuplicatesArgs.Namespaces != nil {
|
||||
includedNamespaces = sets.NewString(removeDuplicatesArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.NewString(removeDuplicatesArgs.Namespaces.Exclude...)
|
||||
includedNamespaces = sets.New(removeDuplicatesArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.New(removeDuplicatesArgs.Namespaces.Exclude...)
|
||||
}
|
||||
|
||||
// We can combine Filter and PreEvictionFilter since for this strategy it does not matter where we run PreEvictionFilter
|
||||
@@ -279,7 +279,7 @@ func hasExcludedOwnerRefKind(ownerRefs []metav1.OwnerReference, excludeOwnerKind
|
||||
return false
|
||||
}
|
||||
|
||||
exclude := sets.NewString(excludeOwnerKinds...)
|
||||
exclude := sets.New(excludeOwnerKinds...)
|
||||
for _, owner := range ownerRefs {
|
||||
if exclude.Has(owner.Kind) {
|
||||
return true
|
||||
|
||||
@@ -50,10 +50,10 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
|
||||
return nil, fmt.Errorf("want args to be of type RemoveFailedPodsArgs, got %T", args)
|
||||
}
|
||||
|
||||
var includedNamespaces, excludedNamespaces sets.String
|
||||
var includedNamespaces, excludedNamespaces sets.Set[string]
|
||||
if failedPodsArgs.Namespaces != nil {
|
||||
includedNamespaces = sets.NewString(failedPodsArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.NewString(failedPodsArgs.Namespaces.Exclude...)
|
||||
includedNamespaces = sets.New(failedPodsArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.New(failedPodsArgs.Namespaces.Exclude...)
|
||||
}
|
||||
|
||||
// We can combine Filter and PreEvictionFilter since for this strategy it does not matter where we run PreEvictionFilter
|
||||
@@ -126,7 +126,7 @@ func validateCanEvict(pod *v1.Pod, failedPodArgs *RemoveFailedPodsArgs) error {
|
||||
if len(failedPodArgs.ExcludeOwnerKinds) > 0 {
|
||||
ownerRefList := podutil.OwnerRef(pod)
|
||||
for _, owner := range ownerRefList {
|
||||
if sets.NewString(failedPodArgs.ExcludeOwnerKinds...).Has(owner.Kind) {
|
||||
if sets.New(failedPodArgs.ExcludeOwnerKinds...).Has(owner.Kind) {
|
||||
errs = append(errs, fmt.Errorf("pod's owner kind of %s is excluded", owner.Kind))
|
||||
}
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func validateCanEvict(pod *v1.Pod, failedPodArgs *RemoveFailedPodsArgs) error {
|
||||
reasons = append(reasons, getFailedContainerStatusReasons(pod.Status.InitContainerStatuses)...)
|
||||
}
|
||||
|
||||
if !sets.NewString(failedPodArgs.Reasons...).HasAny(reasons...) {
|
||||
if !sets.New(failedPodArgs.Reasons...).HasAny(reasons...) {
|
||||
errs = append(errs, fmt.Errorf("pod does not match any of the reasons"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
|
||||
return nil, fmt.Errorf("want args to be of type RemovePodsHavingTooManyRestartsArgs, got %T", args)
|
||||
}
|
||||
|
||||
var includedNamespaces, excludedNamespaces sets.String
|
||||
var includedNamespaces, excludedNamespaces sets.Set[string]
|
||||
if tooManyRestartsArgs.Namespaces != nil {
|
||||
includedNamespaces = sets.NewString(tooManyRestartsArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.NewString(tooManyRestartsArgs.Namespaces.Exclude...)
|
||||
includedNamespaces = sets.New(tooManyRestartsArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.New(tooManyRestartsArgs.Namespaces.Exclude...)
|
||||
}
|
||||
|
||||
// We can combine Filter and PreEvictionFilter since for this strategy it does not matter where we run PreEvictionFilter
|
||||
|
||||
@@ -50,10 +50,10 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
|
||||
return nil, fmt.Errorf("want args to be of type RemovePodsViolatingInterPodAntiAffinityArgs, got %T", args)
|
||||
}
|
||||
|
||||
var includedNamespaces, excludedNamespaces sets.String
|
||||
var includedNamespaces, excludedNamespaces sets.Set[string]
|
||||
if interPodAntiAffinityArgs.Namespaces != nil {
|
||||
includedNamespaces = sets.NewString(interPodAntiAffinityArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.NewString(interPodAntiAffinityArgs.Namespaces.Exclude...)
|
||||
includedNamespaces = sets.New(interPodAntiAffinityArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.New(interPodAntiAffinityArgs.Namespaces.Exclude...)
|
||||
}
|
||||
|
||||
podFilter, err := podutil.NewOptions().
|
||||
|
||||
@@ -46,10 +46,10 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
|
||||
return nil, fmt.Errorf("want args to be of type RemovePodsViolatingNodeAffinityArgs, got %T", args)
|
||||
}
|
||||
|
||||
var includedNamespaces, excludedNamespaces sets.String
|
||||
var includedNamespaces, excludedNamespaces sets.Set[string]
|
||||
if nodeAffinityArgs.Namespaces != nil {
|
||||
includedNamespaces = sets.NewString(nodeAffinityArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.NewString(nodeAffinityArgs.Namespaces.Exclude...)
|
||||
includedNamespaces = sets.New(nodeAffinityArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.New(nodeAffinityArgs.Namespaces.Exclude...)
|
||||
}
|
||||
|
||||
// We can combine Filter and PreEvictionFilter since for this strategy it does not matter where we run PreEvictionFilter
|
||||
|
||||
@@ -50,10 +50,10 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
|
||||
return nil, fmt.Errorf("want args to be of type RemovePodsViolatingNodeTaintsArgs, got %T", args)
|
||||
}
|
||||
|
||||
var includedNamespaces, excludedNamespaces sets.String
|
||||
var includedNamespaces, excludedNamespaces sets.Set[string]
|
||||
if nodeTaintsArgs.Namespaces != nil {
|
||||
includedNamespaces = sets.NewString(nodeTaintsArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.NewString(nodeTaintsArgs.Namespaces.Exclude...)
|
||||
includedNamespaces = sets.New(nodeTaintsArgs.Namespaces.Include...)
|
||||
excludedNamespaces = sets.New(nodeTaintsArgs.Namespaces.Exclude...)
|
||||
}
|
||||
|
||||
// We can combine Filter and PreEvictionFilter since for this strategy it does not matter where we run PreEvictionFilter
|
||||
@@ -67,7 +67,7 @@ func New(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plug
|
||||
return nil, fmt.Errorf("error initializing pod filter function: %v", err)
|
||||
}
|
||||
|
||||
excludedTaints := sets.NewString(nodeTaintsArgs.ExcludedTaints...)
|
||||
excludedTaints := sets.New(nodeTaintsArgs.ExcludedTaints...)
|
||||
excludeTaint := func(taint *v1.Taint) bool {
|
||||
// Exclude taints by key *or* key=value
|
||||
return excludedTaints.Has(taint.Key) || (taint.Value != "" && excludedTaints.Has(fmt.Sprintf("%s=%s", taint.Key, taint.Value)))
|
||||
|
||||
@@ -113,10 +113,10 @@ func (d *RemovePodsViolatingTopologySpreadConstraint) Balance(ctx context.Contex
|
||||
}
|
||||
klog.V(1).InfoS("Processing namespaces for topology spread constraints")
|
||||
podsForEviction := make(map[*v1.Pod]struct{})
|
||||
var includedNamespaces, excludedNamespaces sets.String
|
||||
var includedNamespaces, excludedNamespaces sets.Set[string]
|
||||
if d.args.Namespaces != nil {
|
||||
includedNamespaces = sets.NewString(d.args.Namespaces.Include...)
|
||||
excludedNamespaces = sets.NewString(d.args.Namespaces.Exclude...)
|
||||
includedNamespaces = sets.New(d.args.Namespaces.Include...)
|
||||
excludedNamespaces = sets.New(d.args.Namespaces.Exclude...)
|
||||
}
|
||||
|
||||
// 1. for each namespace...
|
||||
|
||||
@@ -1215,12 +1215,12 @@ func TestTopologySpreadConstraint(t *testing.T) {
|
||||
}
|
||||
|
||||
if tc.expectedEvictedPods != nil {
|
||||
diff := sets.NewString(tc.expectedEvictedPods...).Difference(sets.NewString(evictedPods...))
|
||||
diff := sets.New(tc.expectedEvictedPods...).Difference(sets.New(evictedPods...))
|
||||
if diff.Len() > 0 {
|
||||
t.Errorf(
|
||||
"Expected pods %v to be evicted but %v were not evicted. Actual pods evicted: %v",
|
||||
tc.expectedEvictedPods,
|
||||
diff.List(),
|
||||
diff.UnsortedList(),
|
||||
evictedPods,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user