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

update deprecated sets.String to generic sets

This commit is contained in:
Amir Alavi
2023-05-11 22:35:44 -04:00
parent 8cbbe5501b
commit 359b38a34c
16 changed files with 64 additions and 64 deletions

View File

@@ -53,8 +53,8 @@ func WrapFilterFuncs(filters ...FilterFunc) FilterFunc {
type Options struct {
filter FilterFunc
includedNamespaces sets.String
excludedNamespaces sets.String
includedNamespaces sets.Set[string]
excludedNamespaces sets.Set[string]
labelSelector *metav1.LabelSelector
}
@@ -71,13 +71,13 @@ func (o *Options) WithFilter(filter FilterFunc) *Options {
}
// WithNamespaces sets included namespaces
func (o *Options) WithNamespaces(namespaces sets.String) *Options {
func (o *Options) WithNamespaces(namespaces sets.Set[string]) *Options {
o.includedNamespaces = namespaces
return o
}
// WithoutNamespaces sets excluded namespaces
func (o *Options) WithoutNamespaces(namespaces sets.String) *Options {
func (o *Options) WithoutNamespaces(namespaces sets.Set[string]) *Options {
o.excludedNamespaces = namespaces
return o
}

View File

@@ -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) {

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"))
}
}

View File

@@ -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

View File

@@ -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().

View File

@@ -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

View File

@@ -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)))

View File

@@ -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...

View File

@@ -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,
)
}

View File

@@ -113,10 +113,10 @@ type profileImpl struct {
preEvictionFilterPlugins []preEvictionFilterPlugin
// Each extension point with a list of plugins implementing the extension point.
deschedule sets.String
balance sets.String
filter sets.String
preEvictionFilter sets.String
deschedule sets.Set[string]
balance sets.Set[string]
filter sets.Set[string]
preEvictionFilter sets.Set[string]
}
// Option for the handleImpl.
@@ -184,10 +184,10 @@ func buildPlugin(config api.DeschedulerProfile, pluginName string, handle *handl
}
func (p *profileImpl) registryToExtensionPoints(registry pluginregistry.Registry) {
p.deschedule = sets.NewString()
p.balance = sets.NewString()
p.filter = sets.NewString()
p.preEvictionFilter = sets.NewString()
p.deschedule = sets.New[string]()
p.balance = sets.New[string]()
p.filter = sets.New[string]()
p.preEvictionFilter = sets.New[string]()
for plugin, pluginUtilities := range registry {
if _, ok := pluginUtilities.PluginType.(frameworktypes.DeschedulePlugin); ok {
@@ -232,16 +232,16 @@ func NewProfile(config api.DeschedulerProfile, reg pluginregistry.Registry, opts
pi.registryToExtensionPoints(reg)
if !pi.deschedule.HasAll(config.Plugins.Deschedule.Enabled...) {
return nil, fmt.Errorf("profile %q configures deschedule extension point of non-existing plugins: %v", config.Name, sets.NewString(config.Plugins.Deschedule.Enabled...).Difference(pi.deschedule))
return nil, fmt.Errorf("profile %q configures deschedule extension point of non-existing plugins: %v", config.Name, sets.New(config.Plugins.Deschedule.Enabled...).Difference(pi.deschedule))
}
if !pi.balance.HasAll(config.Plugins.Balance.Enabled...) {
return nil, fmt.Errorf("profile %q configures balance extension point of non-existing plugins: %v", config.Name, sets.NewString(config.Plugins.Balance.Enabled...).Difference(pi.balance))
return nil, fmt.Errorf("profile %q configures balance extension point of non-existing plugins: %v", config.Name, sets.New(config.Plugins.Balance.Enabled...).Difference(pi.balance))
}
if !pi.filter.HasAll(config.Plugins.Filter.Enabled...) {
return nil, fmt.Errorf("profile %q configures filter extension point of non-existing plugins: %v", config.Name, sets.NewString(config.Plugins.Filter.Enabled...).Difference(pi.filter))
return nil, fmt.Errorf("profile %q configures filter extension point of non-existing plugins: %v", config.Name, sets.New(config.Plugins.Filter.Enabled...).Difference(pi.filter))
}
if !pi.preEvictionFilter.HasAll(config.Plugins.PreEvictionFilter.Enabled...) {
return nil, fmt.Errorf("profile %q configures preEvictionFilter extension point of non-existing plugins: %v", config.Name, sets.NewString(config.Plugins.PreEvictionFilter.Enabled...).Difference(pi.preEvictionFilter))
return nil, fmt.Errorf("profile %q configures preEvictionFilter extension point of non-existing plugins: %v", config.Name, sets.New(config.Plugins.PreEvictionFilter.Enabled...).Difference(pi.preEvictionFilter))
}
handle := &handleImpl{
@@ -258,7 +258,7 @@ func NewProfile(config api.DeschedulerProfile, reg pluginregistry.Registry, opts
pluginNames = append(pluginNames, config.Plugins.PreEvictionFilter.Enabled...)
plugins := make(map[string]frameworktypes.Plugin)
for _, plugin := range sets.NewString(pluginNames...).List() {
for _, plugin := range sets.New(pluginNames...).UnsortedList() {
pg, err := buildPlugin(config, plugin, handle, reg)
if err != nil {
return nil, fmt.Errorf("unable to build %v plugin: %v", plugin, err)

View File

@@ -444,19 +444,19 @@ func TestProfileExtensionPoints(t *testing.T) {
// Validate the extension points of all registered plugins are properly detected
diff := cmp.Diff(sets.NewString("DeschedulePlugin_0", "DeschedulePlugin_1", "DeschedulePlugin_2", "FakePlugin_0", "FakePlugin_1", "FakePlugin_2"), prfl.deschedule)
diff := cmp.Diff(sets.New("DeschedulePlugin_0", "DeschedulePlugin_1", "DeschedulePlugin_2", "FakePlugin_0", "FakePlugin_1", "FakePlugin_2"), prfl.deschedule)
if diff != "" {
t.Errorf("check for deschedule failed. Results are not deep equal. mismatch (-want +got):\n%s", diff)
}
diff = cmp.Diff(sets.NewString("BalancePlugin_0", "BalancePlugin_1", "BalancePlugin_2", "FakePlugin_0", "FakePlugin_1", "FakePlugin_2"), prfl.balance)
diff = cmp.Diff(sets.New("BalancePlugin_0", "BalancePlugin_1", "BalancePlugin_2", "FakePlugin_0", "FakePlugin_1", "FakePlugin_2"), prfl.balance)
if diff != "" {
t.Errorf("check for balance failed. Results are not deep equal. mismatch (-want +got):\n%s", diff)
}
diff = cmp.Diff(sets.NewString("DefaultEvictor", "FakePlugin_0", "FakePlugin_1", "FakePlugin_2", "FilterPlugin_0", "FilterPlugin_1", "FilterPlugin_2"), prfl.filter)
diff = cmp.Diff(sets.New("DefaultEvictor", "FakePlugin_0", "FakePlugin_1", "FakePlugin_2", "FilterPlugin_0", "FilterPlugin_1", "FilterPlugin_2"), prfl.filter)
if diff != "" {
t.Errorf("check for filter failed. Results are not deep equal. mismatch (-want +got):\n%s", diff)
}
diff = cmp.Diff(sets.NewString("DefaultEvictor", "FakePlugin_0", "FakePlugin_1", "FakePlugin_2", "FilterPlugin_0", "FilterPlugin_1", "FilterPlugin_2"), prfl.preEvictionFilter)
diff = cmp.Diff(sets.New("DefaultEvictor", "FakePlugin_0", "FakePlugin_1", "FakePlugin_2", "FilterPlugin_0", "FilterPlugin_1", "FilterPlugin_2"), prfl.preEvictionFilter)
if diff != "" {
t.Errorf("check for preEvictionFilter failed. Results are not deep equal. mismatch (-want +got):\n%s", diff)
}
@@ -467,7 +467,7 @@ func TestProfileExtensionPoints(t *testing.T) {
names = append(names, pl.Name())
}
sort.Strings(names)
diff = cmp.Diff(sets.NewString("FakePlugin_0"), sets.NewString(names...))
diff = cmp.Diff(sets.New("FakePlugin_0"), sets.New(names...))
if diff != "" {
t.Errorf("check for deschedule failed. Results are not deep equal. mismatch (-want +got):\n%s", diff)
}
@@ -478,7 +478,7 @@ func TestProfileExtensionPoints(t *testing.T) {
names = append(names, pl.Name())
}
sort.Strings(names)
diff = cmp.Diff(sets.NewString(), sets.NewString(names...))
diff = cmp.Diff(sets.New[string](), sets.New(names...))
if diff != "" {
t.Errorf("check for balance failed. Results are not deep equal. mismatch (-want +got):\n%s", diff)
}
@@ -489,7 +489,7 @@ func TestProfileExtensionPoints(t *testing.T) {
names = append(names, pl.Name())
}
sort.Strings(names)
diff = cmp.Diff(sets.NewString("DefaultEvictor", "FilterPlugin_0", "FilterPlugin_1"), sets.NewString(names...))
diff = cmp.Diff(sets.New("DefaultEvictor", "FilterPlugin_0", "FilterPlugin_1"), sets.New(names...))
if diff != "" {
t.Errorf("check for filter failed. Results are not deep equal. mismatch (-want +got):\n%s", diff)
}

View File

@@ -17,8 +17,8 @@ const SystemCriticalPriority = 2 * int32(1000000000)
// GetNamespacesFromPodAffinityTerm returns a set of names
// according to the namespaces indicated in podAffinityTerm.
// If namespaces is empty it considers the given pod's namespace.
func GetNamespacesFromPodAffinityTerm(pod *v1.Pod, podAffinityTerm *v1.PodAffinityTerm) sets.String {
names := sets.String{}
func GetNamespacesFromPodAffinityTerm(pod *v1.Pod, podAffinityTerm *v1.PodAffinityTerm) sets.Set[string] {
names := sets.New[string]()
if len(podAffinityTerm.Namespaces) == 0 {
names.Insert(pod.Namespace)
} else {
@@ -29,7 +29,7 @@ func GetNamespacesFromPodAffinityTerm(pod *v1.Pod, podAffinityTerm *v1.PodAffini
// PodMatchesTermsNamespaceAndSelector returns true if the given <pod>
// matches the namespace and selector defined by <affinityPod>`s <term>.
func PodMatchesTermsNamespaceAndSelector(pod *v1.Pod, namespaces sets.String, selector labels.Selector) bool {
func PodMatchesTermsNamespaceAndSelector(pod *v1.Pod, namespaces sets.Set[string], selector labels.Selector) bool {
if !namespaces.Has(pod.Namespace) {
return false
}

View File

@@ -6,7 +6,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
)
var supportedQoSComputeResources = sets.NewString(string(v1.ResourceCPU), string(v1.ResourceMemory))
var supportedQoSComputeResources = sets.New(string(v1.ResourceCPU), string(v1.ResourceMemory))
// QOSList is a set of (resource name, QoS class) pairs.
type QOSList map[v1.ResourceName]v1.PodQOSClass
@@ -44,7 +44,7 @@ func GetPodQOS(pod *v1.Pod) v1.PodQOSClass {
}
}
// process limits
qosLimitsFound := sets.NewString()
qosLimitsFound := sets.New[string]()
for name, quantity := range container.Resources.Limits {
if !isSupportedQoSComputeResource(name) {
continue