mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Remove use of deprecated functions
Removes use of deprecated functions in k8s.io/utils/pointer and k8s.io/apimachinery/pkg/util/sets
This commit is contained in:
parent
9fc9ddc7bc
commit
6168143386
@ -54,7 +54,7 @@ import (
|
|||||||
metricsfake "k8s.io/metrics/pkg/client/clientset/versioned/fake"
|
metricsfake "k8s.io/metrics/pkg/client/clientset/versioned/fake"
|
||||||
cmfake "k8s.io/metrics/pkg/client/custom_metrics/fake"
|
cmfake "k8s.io/metrics/pkg/client/custom_metrics/fake"
|
||||||
emfake "k8s.io/metrics/pkg/client/external_metrics/fake"
|
emfake "k8s.io/metrics/pkg/client/external_metrics/fake"
|
||||||
"k8s.io/utils/pointer"
|
"k8s.io/utils/ptr"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
@ -876,7 +876,7 @@ func (m *mockMonitor) ObserveMetricComputationResult(action monitor.ActionLabel,
|
|||||||
|
|
||||||
// waitUntilRecorded waits for the HPA controller to reconcile at least once.
|
// waitUntilRecorded waits for the HPA controller to reconcile at least once.
|
||||||
func (m *mockMonitor) waitUntilRecorded(t *testing.T) {
|
func (m *mockMonitor) waitUntilRecorded(t *testing.T) {
|
||||||
if err := wait.Poll(20*time.Millisecond, 100*time.Millisecond, func() (done bool, err error) {
|
if err := wait.PollUntilContextTimeout(context.Background(), 20*time.Millisecond, 100*time.Millisecond, true, func(ctx context.Context) (done bool, err error) {
|
||||||
m.RWMutex.RLock()
|
m.RWMutex.RLock()
|
||||||
defer m.RWMutex.RUnlock()
|
defer m.RWMutex.RUnlock()
|
||||||
if len(m.reconciliationActionLabels) == 0 || len(m.reconciliationErrorLabels) == 0 {
|
if len(m.reconciliationActionLabels) == 0 || len(m.reconciliationErrorLabels) == 0 {
|
||||||
@ -925,7 +925,7 @@ func TestScaleUpContainer(t *testing.T) {
|
|||||||
Name: v1.ResourceCPU,
|
Name: v1.ResourceCPU,
|
||||||
Target: autoscalingv2.MetricTarget{
|
Target: autoscalingv2.MetricTarget{
|
||||||
Type: autoscalingv2.UtilizationMetricType,
|
Type: autoscalingv2.UtilizationMetricType,
|
||||||
AverageUtilization: pointer.Int32(30),
|
AverageUtilization: ptr.To(int32(30)),
|
||||||
},
|
},
|
||||||
Container: "container1",
|
Container: "container1",
|
||||||
},
|
},
|
||||||
@ -1619,7 +1619,7 @@ func TestScaleDownContainerResource(t *testing.T) {
|
|||||||
Name: v1.ResourceCPU,
|
Name: v1.ResourceCPU,
|
||||||
Target: autoscalingv2.MetricTarget{
|
Target: autoscalingv2.MetricTarget{
|
||||||
Type: autoscalingv2.UtilizationMetricType,
|
Type: autoscalingv2.UtilizationMetricType,
|
||||||
AverageUtilization: pointer.Int32(50),
|
AverageUtilization: ptr.To(int32(50)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
@ -3848,7 +3848,7 @@ func TestCalculateScaleUpLimitWithScalingRules(t *testing.T) {
|
|||||||
policy := autoscalingv2.MinChangePolicySelect
|
policy := autoscalingv2.MinChangePolicySelect
|
||||||
|
|
||||||
calculated := calculateScaleUpLimitWithScalingRules(1, []timestampedScaleEvent{}, []timestampedScaleEvent{}, &autoscalingv2.HPAScalingRules{
|
calculated := calculateScaleUpLimitWithScalingRules(1, []timestampedScaleEvent{}, []timestampedScaleEvent{}, &autoscalingv2.HPAScalingRules{
|
||||||
StabilizationWindowSeconds: pointer.Int32(300),
|
StabilizationWindowSeconds: ptr.To(int32(300)),
|
||||||
SelectPolicy: &policy,
|
SelectPolicy: &policy,
|
||||||
Policies: []autoscalingv2.HPAScalingPolicy{
|
Policies: []autoscalingv2.HPAScalingPolicy{
|
||||||
{
|
{
|
||||||
@ -3870,7 +3870,7 @@ func TestCalculateScaleDownLimitWithBehaviors(t *testing.T) {
|
|||||||
policy := autoscalingv2.MinChangePolicySelect
|
policy := autoscalingv2.MinChangePolicySelect
|
||||||
|
|
||||||
calculated := calculateScaleDownLimitWithBehaviors(5, []timestampedScaleEvent{}, []timestampedScaleEvent{}, &autoscalingv2.HPAScalingRules{
|
calculated := calculateScaleDownLimitWithBehaviors(5, []timestampedScaleEvent{}, []timestampedScaleEvent{}, &autoscalingv2.HPAScalingRules{
|
||||||
StabilizationWindowSeconds: pointer.Int32(300),
|
StabilizationWindowSeconds: ptr.To(int32(300)),
|
||||||
SelectPolicy: &policy,
|
SelectPolicy: &policy,
|
||||||
Policies: []autoscalingv2.HPAScalingPolicy{
|
Policies: []autoscalingv2.HPAScalingPolicy{
|
||||||
{
|
{
|
||||||
@ -3891,7 +3891,7 @@ func TestCalculateScaleDownLimitWithBehaviors(t *testing.T) {
|
|||||||
func generateScalingRules(pods, podsPeriod, percent, percentPeriod, stabilizationWindow int32) *autoscalingv2.HPAScalingRules {
|
func generateScalingRules(pods, podsPeriod, percent, percentPeriod, stabilizationWindow int32) *autoscalingv2.HPAScalingRules {
|
||||||
policy := autoscalingv2.MaxChangePolicySelect
|
policy := autoscalingv2.MaxChangePolicySelect
|
||||||
directionBehavior := autoscalingv2.HPAScalingRules{
|
directionBehavior := autoscalingv2.HPAScalingRules{
|
||||||
StabilizationWindowSeconds: pointer.Int32(stabilizationWindow),
|
StabilizationWindowSeconds: ptr.To(int32(stabilizationWindow)),
|
||||||
SelectPolicy: &policy,
|
SelectPolicy: &policy,
|
||||||
}
|
}
|
||||||
if pods != 0 {
|
if pods != 0 {
|
||||||
|
@ -375,10 +375,10 @@ func (c *ReplicaCalculator) GetExternalPerPodMetricReplicas(statusReplicas int32
|
|||||||
return replicaCount, usage, timestamp, nil
|
return replicaCount, usage, timestamp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func groupPods(pods []*v1.Pod, metrics metricsclient.PodMetricsInfo, resource v1.ResourceName, cpuInitializationPeriod, delayOfInitialReadinessStatus time.Duration) (readyPodCount int, unreadyPods, missingPods, ignoredPods sets.String) {
|
func groupPods(pods []*v1.Pod, metrics metricsclient.PodMetricsInfo, resource v1.ResourceName, cpuInitializationPeriod, delayOfInitialReadinessStatus time.Duration) (readyPodCount int, unreadyPods, missingPods, ignoredPods sets.Set[string]) {
|
||||||
missingPods = sets.NewString()
|
missingPods = sets.New[string]()
|
||||||
unreadyPods = sets.NewString()
|
unreadyPods = sets.New[string]()
|
||||||
ignoredPods = sets.NewString()
|
ignoredPods = sets.New[string]()
|
||||||
for _, pod := range pods {
|
for _, pod := range pods {
|
||||||
if pod.DeletionTimestamp != nil || pod.Status.Phase == v1.PodFailed {
|
if pod.DeletionTimestamp != nil || pod.Status.Phase == v1.PodFailed {
|
||||||
ignoredPods.Insert(pod.Name)
|
ignoredPods.Insert(pod.Name)
|
||||||
@ -446,7 +446,7 @@ func calculatePodRequests(pods []*v1.Pod, container string, resource v1.Resource
|
|||||||
return requests, nil
|
return requests, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeMetricsForPods(metrics metricsclient.PodMetricsInfo, pods sets.String) {
|
func removeMetricsForPods(metrics metricsclient.PodMetricsInfo, pods sets.Set[string]) {
|
||||||
for _, pod := range pods.UnsortedList() {
|
for _, pod := range pods.UnsortedList() {
|
||||||
delete(metrics, pod)
|
delete(metrics, pod)
|
||||||
}
|
}
|
||||||
|
@ -1614,9 +1614,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
metrics metricsclient.PodMetricsInfo
|
metrics metricsclient.PodMetricsInfo
|
||||||
resource v1.ResourceName
|
resource v1.ResourceName
|
||||||
expectReadyPodCount int
|
expectReadyPodCount int
|
||||||
expectUnreadyPods sets.String
|
expectUnreadyPods sets.Set[string]
|
||||||
expectMissingPods sets.String
|
expectMissingPods sets.Set[string]
|
||||||
expectIgnoredPods sets.String
|
expectIgnoredPods sets.Set[string]
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "void",
|
name: "void",
|
||||||
@ -1624,9 +1624,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
metrics: metricsclient.PodMetricsInfo{},
|
metrics: metricsclient.PodMetricsInfo{},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 0,
|
expectReadyPodCount: 0,
|
||||||
expectUnreadyPods: sets.NewString(),
|
expectUnreadyPods: sets.New[string](),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "count in a ready pod - memory",
|
name: "count in a ready pod - memory",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1644,9 +1644,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceMemory,
|
resource: v1.ResourceMemory,
|
||||||
expectReadyPodCount: 1,
|
expectReadyPodCount: 1,
|
||||||
expectUnreadyPods: sets.NewString(),
|
expectUnreadyPods: sets.New[string](),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "unready a pod without ready condition - CPU",
|
name: "unready a pod without ready condition - CPU",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1667,9 +1667,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 0,
|
expectReadyPodCount: 0,
|
||||||
expectUnreadyPods: sets.NewString("lucretius"),
|
expectUnreadyPods: sets.New[string]("lucretius"),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "count in a ready pod with fresh metrics during initialization period - CPU",
|
name: "count in a ready pod with fresh metrics during initialization period - CPU",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1697,9 +1697,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 1,
|
expectReadyPodCount: 1,
|
||||||
expectUnreadyPods: sets.NewString(),
|
expectUnreadyPods: sets.New[string](),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "unready a ready pod without fresh metrics during initialization period - CPU",
|
name: "unready a ready pod without fresh metrics during initialization period - CPU",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1727,9 +1727,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 0,
|
expectReadyPodCount: 0,
|
||||||
expectUnreadyPods: sets.NewString("bentham"),
|
expectUnreadyPods: sets.New[string]("bentham"),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "unready an unready pod during initialization period - CPU",
|
name: "unready an unready pod during initialization period - CPU",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1757,9 +1757,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 0,
|
expectReadyPodCount: 0,
|
||||||
expectUnreadyPods: sets.NewString("lucretius"),
|
expectUnreadyPods: sets.New[string]("lucretius"),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "count in a ready pod without fresh metrics after initialization period - CPU",
|
name: "count in a ready pod without fresh metrics after initialization period - CPU",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1787,9 +1787,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 1,
|
expectReadyPodCount: 1,
|
||||||
expectUnreadyPods: sets.NewString(),
|
expectUnreadyPods: sets.New[string](),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "count in an unready pod that was ready after initialization period - CPU",
|
name: "count in an unready pod that was ready after initialization period - CPU",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1817,9 +1817,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 1,
|
expectReadyPodCount: 1,
|
||||||
expectUnreadyPods: sets.NewString(),
|
expectUnreadyPods: sets.New[string](),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "unready pod that has never been ready after initialization period - CPU",
|
name: "unready pod that has never been ready after initialization period - CPU",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1847,9 +1847,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 1,
|
expectReadyPodCount: 1,
|
||||||
expectUnreadyPods: sets.NewString(),
|
expectUnreadyPods: sets.New[string](),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "a missing pod",
|
name: "a missing pod",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1868,9 +1868,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
metrics: metricsclient.PodMetricsInfo{},
|
metrics: metricsclient.PodMetricsInfo{},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 0,
|
expectReadyPodCount: 0,
|
||||||
expectUnreadyPods: sets.NewString(),
|
expectUnreadyPods: sets.New[string](),
|
||||||
expectMissingPods: sets.NewString("epicurus"),
|
expectMissingPods: sets.New[string]("epicurus"),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "several pods",
|
name: "several pods",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1921,9 +1921,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 1,
|
expectReadyPodCount: 1,
|
||||||
expectUnreadyPods: sets.NewString("lucretius"),
|
expectUnreadyPods: sets.New[string]("lucretius"),
|
||||||
expectMissingPods: sets.NewString("epicurus"),
|
expectMissingPods: sets.New[string]("epicurus"),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "pending pods are unreadied",
|
name: "pending pods are unreadied",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1939,9 +1939,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
metrics: metricsclient.PodMetricsInfo{},
|
metrics: metricsclient.PodMetricsInfo{},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 0,
|
expectReadyPodCount: 0,
|
||||||
expectUnreadyPods: sets.NewString("unscheduled"),
|
expectUnreadyPods: sets.New[string]("unscheduled"),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString(),
|
expectIgnoredPods: sets.New[string](),
|
||||||
}, {
|
}, {
|
||||||
name: "ignore pods with deletion timestamps",
|
name: "ignore pods with deletion timestamps",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1960,9 +1960,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 0,
|
expectReadyPodCount: 0,
|
||||||
expectUnreadyPods: sets.NewString(),
|
expectUnreadyPods: sets.New[string](),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString("deleted"),
|
expectIgnoredPods: sets.New[string]("deleted"),
|
||||||
}, {
|
}, {
|
||||||
name: "ignore pods in a failed state",
|
name: "ignore pods in a failed state",
|
||||||
pods: []*v1.Pod{
|
pods: []*v1.Pod{
|
||||||
@ -1980,9 +1980,9 @@ func TestGroupPods(t *testing.T) {
|
|||||||
},
|
},
|
||||||
resource: v1.ResourceCPU,
|
resource: v1.ResourceCPU,
|
||||||
expectReadyPodCount: 0,
|
expectReadyPodCount: 0,
|
||||||
expectUnreadyPods: sets.NewString(),
|
expectUnreadyPods: sets.New[string](),
|
||||||
expectMissingPods: sets.NewString(),
|
expectMissingPods: sets.New[string](),
|
||||||
expectIgnoredPods: sets.NewString("failed"),
|
expectIgnoredPods: sets.New[string]("failed"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user