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

refactor: replace k8s.io/utils/pointer with k8s.io/utils/ptr

Signed-off-by: Emin Aktas <eminaktas34@gmail.com>
This commit is contained in:
Emin Aktas
2024-07-11 11:17:13 +03:00
parent b614c8bc7c
commit f8e128d862
23 changed files with 309 additions and 120 deletions

View File

@@ -19,7 +19,7 @@ import (
"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/utils/pointer"
utilptr "k8s.io/utils/ptr"
"sigs.k8s.io/descheduler/pkg/api"
)
@@ -55,7 +55,7 @@ func TestSetDefaults_DefaultEvictorArgs(t *testing.T) {
EvictFailedBarePods: true,
LabelSelector: nil,
PriorityThreshold: &api.PriorityThreshold{
Value: pointer.Int32(800),
Value: utilptr.To[int32](800),
},
NodeFit: true,
},
@@ -68,7 +68,7 @@ func TestSetDefaults_DefaultEvictorArgs(t *testing.T) {
EvictFailedBarePods: true,
LabelSelector: nil,
PriorityThreshold: &api.PriorityThreshold{
Value: pointer.Int32(800),
Value: utilptr.To[int32](800),
},
NodeFit: true,
},

View File

@@ -20,7 +20,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/utils/pointer"
utilptr "k8s.io/utils/ptr"
"sigs.k8s.io/descheduler/pkg/api"
)
@@ -47,7 +47,7 @@ func TestSetDefaults_PodLifeTimeArgs(t *testing.T) {
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{"foo": "bar"},
},
MaxPodLifeTimeSeconds: pointer.Uint(600),
MaxPodLifeTimeSeconds: utilptr.To[uint](600),
States: []string{"Pending"},
},
want: &PodLifeTimeArgs{
@@ -55,7 +55,7 @@ func TestSetDefaults_PodLifeTimeArgs(t *testing.T) {
LabelSelector: &metav1.LabelSelector{
MatchLabels: map[string]string{"foo": "bar"},
},
MaxPodLifeTimeSeconds: pointer.Uint(600),
MaxPodLifeTimeSeconds: utilptr.To[uint](600),
States: []string{"Pending"},
},
},

View File

@@ -15,7 +15,7 @@ package removefailedpods
import (
"k8s.io/apimachinery/pkg/runtime"
utilpointer "k8s.io/utils/pointer"
utilptr "k8s.io/utils/ptr"
)
func addDefaultingFuncs(scheme *runtime.Scheme) error {
@@ -36,7 +36,7 @@ func SetDefaults_RemoveFailedPodsArgs(obj runtime.Object) {
args.ExcludeOwnerKinds = nil
}
if args.MinPodLifetimeSeconds == nil {
args.MinPodLifetimeSeconds = utilpointer.Uint(3600)
args.MinPodLifetimeSeconds = utilptr.To[uint](3600)
}
if args.Reasons == nil {
args.Reasons = nil

View File

@@ -20,7 +20,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/utils/pointer"
utilptr "k8s.io/utils/ptr"
"sigs.k8s.io/descheduler/pkg/api"
)
@@ -48,7 +48,7 @@ func TestSetDefaults_RemoveFailedPodsArgs(t *testing.T) {
Namespaces: &api.Namespaces{},
LabelSelector: &metav1.LabelSelector{},
ExcludeOwnerKinds: []string{"ReplicaSet"},
MinPodLifetimeSeconds: pointer.Uint(0),
MinPodLifetimeSeconds: utilptr.To[uint](0),
Reasons: []string{"reason"},
IncludingInitContainers: true,
},
@@ -56,7 +56,7 @@ func TestSetDefaults_RemoveFailedPodsArgs(t *testing.T) {
Namespaces: &api.Namespaces{},
LabelSelector: &metav1.LabelSelector{},
ExcludeOwnerKinds: []string{"ReplicaSet"},
MinPodLifetimeSeconds: pointer.Uint(0),
MinPodLifetimeSeconds: utilptr.To[uint](0),
Reasons: []string{"reason"},
IncludingInitContainers: true,
},

View File

@@ -16,7 +16,7 @@ package removepodsviolatingtopologyspreadconstraint
import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilpointer "k8s.io/utils/pointer"
utilptr "k8s.io/utils/ptr"
)
func addDefaultingFuncs(scheme *runtime.Scheme) error {
@@ -34,7 +34,7 @@ func SetDefaults_RemovePodsViolatingTopologySpreadConstraintArgs(obj runtime.Obj
args.LabelSelector = nil
}
if args.TopologyBalanceNodeFit == nil {
args.TopologyBalanceNodeFit = utilpointer.Bool(true)
args.TopologyBalanceNodeFit = utilptr.To(true)
}
if len(args.Constraints) == 0 {
args.Constraints = append(args.Constraints, v1.DoNotSchedule)

View File

@@ -21,7 +21,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
utilpointer "k8s.io/utils/pointer"
utilptr "k8s.io/utils/ptr"
"sigs.k8s.io/descheduler/pkg/api"
)
@@ -48,7 +48,7 @@ func TestSetDefaults_RemovePodsViolatingTopologySpreadConstraintArgs(t *testing.
Namespaces: nil,
LabelSelector: nil,
Constraints: []v1.UnsatisfiableConstraintAction{v1.DoNotSchedule},
TopologyBalanceNodeFit: utilpointer.Bool(true),
TopologyBalanceNodeFit: utilptr.To(true),
},
},
{
@@ -62,7 +62,7 @@ func TestSetDefaults_RemovePodsViolatingTopologySpreadConstraintArgs(t *testing.
Namespaces: &api.Namespaces{},
LabelSelector: &metav1.LabelSelector{},
Constraints: []v1.UnsatisfiableConstraintAction{v1.DoNotSchedule, v1.ScheduleAnyway},
TopologyBalanceNodeFit: utilpointer.Bool(true),
TopologyBalanceNodeFit: utilptr.To(true),
},
},
{
@@ -70,16 +70,16 @@ func TestSetDefaults_RemovePodsViolatingTopologySpreadConstraintArgs(t *testing.
in: &RemovePodsViolatingTopologySpreadConstraintArgs{},
want: &RemovePodsViolatingTopologySpreadConstraintArgs{
Constraints: []v1.UnsatisfiableConstraintAction{v1.DoNotSchedule},
TopologyBalanceNodeFit: utilpointer.Bool(true),
TopologyBalanceNodeFit: utilptr.To(true),
},
},
{
name: "RemovePodsViolatingTopologySpreadConstraintArgs with TopologyBalanceNodeFit=false",
in: &RemovePodsViolatingTopologySpreadConstraintArgs{
TopologyBalanceNodeFit: utilpointer.Bool(false),
TopologyBalanceNodeFit: utilptr.To(false),
},
want: &RemovePodsViolatingTopologySpreadConstraintArgs{
TopologyBalanceNodeFit: utilpointer.Bool(false),
TopologyBalanceNodeFit: utilptr.To(false),
Constraints: []v1.UnsatisfiableConstraintAction{v1.DoNotSchedule},
},
},
@@ -90,7 +90,7 @@ func TestSetDefaults_RemovePodsViolatingTopologySpreadConstraintArgs(t *testing.
},
want: &RemovePodsViolatingTopologySpreadConstraintArgs{
Constraints: []v1.UnsatisfiableConstraintAction{v1.DoNotSchedule},
TopologyBalanceNodeFit: utilpointer.Bool(true),
TopologyBalanceNodeFit: utilptr.To(true),
},
},
}

View File

@@ -26,7 +26,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/klog/v2"
utilpointer "k8s.io/utils/pointer"
utilptr "k8s.io/utils/ptr"
v1helper "k8s.io/component-helpers/scheduling/corev1"
"k8s.io/component-helpers/scheduling/corev1/nodeaffinity"
@@ -313,7 +313,7 @@ func (d *RemovePodsViolatingTopologySpreadConstraint) balanceDomains(
isEvictable := d.handle.Evictor().Filter
sortedDomains := sortDomains(constraintTopologies, isEvictable)
getPodsAssignedToNode := d.handle.GetPodsAssignedToNodeFunc()
topologyBalanceNodeFit := utilpointer.BoolDeref(d.args.TopologyBalanceNodeFit, true)
topologyBalanceNodeFit := utilptr.Deref(d.args.TopologyBalanceNodeFit, true)
eligibleNodes := filterEligibleNodes(nodes, tsc)
nodesBelowIdealAvg := filterNodesBelowIdealAvg(eligibleNodes, sortedDomains, tsc.TopologyKey, idealAvg)

View File

@@ -16,7 +16,7 @@ import (
"k8s.io/client-go/kubernetes/fake"
core "k8s.io/client-go/testing"
"k8s.io/client-go/tools/events"
utilpointer "k8s.io/utils/pointer"
utilptr "k8s.io/utils/ptr"
"sigs.k8s.io/descheduler/pkg/api"
"sigs.k8s.io/descheduler/pkg/descheduler/evictions"
@@ -1205,7 +1205,7 @@ func TestTopologySpreadConstraint(t *testing.T) {
}),
expectedEvictedCount: 1,
namespaces: []string{"ns1"},
args: RemovePodsViolatingTopologySpreadConstraintArgs{TopologyBalanceNodeFit: utilpointer.Bool(false)},
args: RemovePodsViolatingTopologySpreadConstraintArgs{TopologyBalanceNodeFit: utilptr.To(false)},
nodeFit: true,
},
{