mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
requeted changes: fix variables in test cases
This commit is contained in:
parent
01b553145c
commit
dc321b4d2a
@ -78,9 +78,9 @@ type metricInfo struct {
|
||||
selector *metav1.LabelSelector
|
||||
metricType metricType
|
||||
|
||||
targetUtilization int64
|
||||
perPodTargetUtilization int64
|
||||
expectedUtilization int64
|
||||
targetUsage int64
|
||||
perPodTargetUsage int64
|
||||
expectedUsage int64
|
||||
}
|
||||
|
||||
type replicaCalcTestCase struct {
|
||||
@ -376,38 +376,38 @@ func (tc *replicaCalcTestCase) runTest(t *testing.T) {
|
||||
}
|
||||
|
||||
var outReplicas int32
|
||||
var outUtilization int64
|
||||
var outUsage int64
|
||||
var outTimestamp time.Time
|
||||
switch tc.metric.metricType {
|
||||
case objectMetric:
|
||||
if tc.metric.singleObject == nil {
|
||||
t.Fatal("Metric specified as objectMetric but metric.singleObject is nil.")
|
||||
}
|
||||
outReplicas, outUtilization, outTimestamp, err = replicaCalc.GetObjectMetricReplicas(tc.currentReplicas, tc.metric.targetUtilization, tc.metric.name, testNamespace, tc.metric.singleObject, selector, nil)
|
||||
outReplicas, outUsage, outTimestamp, err = replicaCalc.GetObjectMetricReplicas(tc.currentReplicas, tc.metric.targetUsage, tc.metric.name, testNamespace, tc.metric.singleObject, selector, nil)
|
||||
case objectPerPodMetric:
|
||||
if tc.metric.singleObject == nil {
|
||||
t.Fatal("Metric specified as objectMetric but metric.singleObject is nil.")
|
||||
}
|
||||
outReplicas, outUtilization, outTimestamp, err = replicaCalc.GetObjectPerPodMetricReplicas(tc.currentReplicas, tc.metric.perPodTargetUtilization, tc.metric.name, testNamespace, tc.metric.singleObject, nil)
|
||||
outReplicas, outUsage, outTimestamp, err = replicaCalc.GetObjectPerPodMetricReplicas(tc.currentReplicas, tc.metric.perPodTargetUsage, tc.metric.name, testNamespace, tc.metric.singleObject, nil)
|
||||
case externalMetric:
|
||||
if tc.metric.selector == nil {
|
||||
t.Fatal("Metric specified as externalMetric but metric.selector is nil.")
|
||||
}
|
||||
if tc.metric.targetUtilization <= 0 {
|
||||
t.Fatalf("Metric specified as externalMetric but metric.targetUtilization is %d which is <=0.", tc.metric.targetUtilization)
|
||||
if tc.metric.targetUsage <= 0 {
|
||||
t.Fatalf("Metric specified as externalMetric but metric.targetUsage is %d which is <=0.", tc.metric.targetUsage)
|
||||
}
|
||||
outReplicas, outUtilization, outTimestamp, err = replicaCalc.GetExternalMetricReplicas(tc.currentReplicas, tc.metric.targetUtilization, tc.metric.name, testNamespace, tc.metric.selector, selector)
|
||||
outReplicas, outUsage, outTimestamp, err = replicaCalc.GetExternalMetricReplicas(tc.currentReplicas, tc.metric.targetUsage, tc.metric.name, testNamespace, tc.metric.selector, selector)
|
||||
case externalPerPodMetric:
|
||||
if tc.metric.selector == nil {
|
||||
t.Fatal("Metric specified as externalPerPodMetric but metric.selector is nil.")
|
||||
}
|
||||
if tc.metric.perPodTargetUtilization <= 0 {
|
||||
t.Fatalf("Metric specified as externalPerPodMetric but metric.perPodTargetUtilization is %d which is <=0.", tc.metric.perPodTargetUtilization)
|
||||
if tc.metric.perPodTargetUsage <= 0 {
|
||||
t.Fatalf("Metric specified as externalPerPodMetric but metric.perPodTargetUsage is %d which is <=0.", tc.metric.perPodTargetUsage)
|
||||
}
|
||||
|
||||
outReplicas, outUtilization, outTimestamp, err = replicaCalc.GetExternalPerPodMetricReplicas(tc.currentReplicas, tc.metric.perPodTargetUtilization, tc.metric.name, testNamespace, tc.metric.selector)
|
||||
outReplicas, outUsage, outTimestamp, err = replicaCalc.GetExternalPerPodMetricReplicas(tc.currentReplicas, tc.metric.perPodTargetUsage, tc.metric.name, testNamespace, tc.metric.selector)
|
||||
case podMetric:
|
||||
outReplicas, outUtilization, outTimestamp, err = replicaCalc.GetMetricReplicas(tc.currentReplicas, tc.metric.targetUtilization, tc.metric.name, testNamespace, selector, nil)
|
||||
outReplicas, outUsage, outTimestamp, err = replicaCalc.GetMetricReplicas(tc.currentReplicas, tc.metric.targetUsage, tc.metric.name, testNamespace, selector, nil)
|
||||
default:
|
||||
t.Fatalf("Unknown metric type: %d", tc.metric.metricType)
|
||||
}
|
||||
@ -419,7 +419,7 @@ func (tc *replicaCalcTestCase) runTest(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, err, "there should not have been an error calculating the replica count")
|
||||
assert.Equal(t, tc.expectedReplicas, outReplicas, "replicas should be as expected")
|
||||
assert.Equal(t, tc.metric.expectedUtilization, outUtilization, "utilization should be as expected")
|
||||
assert.Equal(t, tc.metric.expectedUsage, outUsage, "usage should be as expected")
|
||||
assert.True(t, tc.timestamp.Equal(outTimestamp), "timestamp should be as expected")
|
||||
}
|
||||
func makePodMetricLevels(containerMetric ...int64) [][]int64 {
|
||||
@ -676,8 +676,8 @@ func TestReplicaCalcScaleUpCM(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{20000, 10000, 30000},
|
||||
targetUtilization: 15000,
|
||||
expectedUtilization: 20000,
|
||||
targetUsage: 15000,
|
||||
expectedUsage: 20000,
|
||||
metricType: podMetric,
|
||||
},
|
||||
}
|
||||
@ -693,8 +693,8 @@ func TestReplicaCalcScaleUpCMUnreadyHotCpuNoLessScale(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{50000, 10000, 30000},
|
||||
targetUtilization: 15000,
|
||||
expectedUtilization: 30000,
|
||||
targetUsage: 15000,
|
||||
expectedUsage: 30000,
|
||||
metricType: podMetric,
|
||||
},
|
||||
}
|
||||
@ -710,8 +710,8 @@ func TestReplicaCalcScaleUpCMUnreadyHotCpuScaleWouldScaleDown(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{50000, 15000, 30000},
|
||||
targetUtilization: 15000,
|
||||
expectedUtilization: 31666,
|
||||
targetUsage: 15000,
|
||||
expectedUsage: 31666,
|
||||
metricType: podMetric,
|
||||
},
|
||||
}
|
||||
@ -725,8 +725,8 @@ func TestReplicaCalcScaleUpCMObject(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{20000},
|
||||
targetUtilization: 15000,
|
||||
expectedUtilization: 20000,
|
||||
targetUsage: 15000,
|
||||
expectedUsage: 20000,
|
||||
singleObject: &autoscalingv2.CrossVersionObjectReference{
|
||||
Kind: "Deployment",
|
||||
APIVersion: "apps/v1",
|
||||
@ -745,8 +745,8 @@ func TestReplicaCalcScaleUpCMPerPodObject(t *testing.T) {
|
||||
metricType: objectPerPodMetric,
|
||||
name: "qps",
|
||||
levels: []int64{20000},
|
||||
perPodTargetUtilization: 5000,
|
||||
expectedUtilization: 6667,
|
||||
perPodTargetUsage: 5000,
|
||||
expectedUsage: 6667,
|
||||
singleObject: &autoscalingv2.CrossVersionObjectReference{
|
||||
Kind: "Deployment",
|
||||
APIVersion: "apps/v1",
|
||||
@ -765,8 +765,8 @@ func TestReplicaCalcScaleUpCMObjectIgnoresUnreadyPods(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{50000},
|
||||
targetUtilization: 10000,
|
||||
expectedUtilization: 50000,
|
||||
targetUsage: 10000,
|
||||
expectedUsage: 50000,
|
||||
singleObject: &autoscalingv2.CrossVersionObjectReference{
|
||||
Kind: "Deployment",
|
||||
APIVersion: "apps/v1",
|
||||
@ -784,8 +784,8 @@ func TestReplicaCalcScaleUpCMExternal(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{8600},
|
||||
targetUtilization: 4400,
|
||||
expectedUtilization: 8600,
|
||||
targetUsage: 4400,
|
||||
expectedUsage: 8600,
|
||||
selector: &metav1.LabelSelector{MatchLabels: map[string]string{"label": "value"}},
|
||||
metricType: podMetric,
|
||||
},
|
||||
@ -801,8 +801,8 @@ func TestReplicaCalcScaleUpCMExternalIgnoresUnreadyPods(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{8600},
|
||||
targetUtilization: 4400,
|
||||
expectedUtilization: 8600,
|
||||
targetUsage: 4400,
|
||||
expectedUsage: 8600,
|
||||
selector: &metav1.LabelSelector{MatchLabels: map[string]string{"label": "value"}},
|
||||
metricType: externalMetric,
|
||||
},
|
||||
@ -817,8 +817,8 @@ func TestReplicaCalcScaleUpCMExternalNoLabels(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{8600},
|
||||
targetUtilization: 4400,
|
||||
expectedUtilization: 8600,
|
||||
targetUsage: 4400,
|
||||
expectedUsage: 8600,
|
||||
metricType: podMetric,
|
||||
},
|
||||
}
|
||||
@ -832,8 +832,8 @@ func TestReplicaCalcScaleUpPerPodCMExternal(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{8600},
|
||||
perPodTargetUtilization: 2150,
|
||||
expectedUtilization: 2867,
|
||||
perPodTargetUsage: 2150,
|
||||
expectedUsage: 2867,
|
||||
selector: &metav1.LabelSelector{MatchLabels: map[string]string{"label": "value"}},
|
||||
metricType: externalPerPodMetric,
|
||||
},
|
||||
@ -883,8 +883,8 @@ func TestReplicaCalcScaleDownCM(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{12000, 12000, 12000, 12000, 12000},
|
||||
targetUtilization: 20000,
|
||||
expectedUtilization: 12000,
|
||||
targetUsage: 20000,
|
||||
expectedUsage: 12000,
|
||||
metricType: podMetric,
|
||||
},
|
||||
}
|
||||
@ -898,8 +898,8 @@ func TestReplicaCalcScaleDownPerPodCMObject(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{6000},
|
||||
perPodTargetUtilization: 2000,
|
||||
expectedUtilization: 1200,
|
||||
perPodTargetUsage: 2000,
|
||||
expectedUsage: 1200,
|
||||
singleObject: &autoscalingv2.CrossVersionObjectReference{
|
||||
Kind: "Deployment",
|
||||
APIVersion: "apps/v1",
|
||||
@ -918,8 +918,8 @@ func TestReplicaCalcScaleDownCMObject(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{12000},
|
||||
targetUtilization: 20000,
|
||||
expectedUtilization: 12000,
|
||||
targetUsage: 20000,
|
||||
expectedUsage: 12000,
|
||||
singleObject: &autoscalingv2.CrossVersionObjectReference{
|
||||
Kind: "Deployment",
|
||||
APIVersion: "apps/v1",
|
||||
@ -937,8 +937,8 @@ func TestReplicaCalcScaleDownCMExternal(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{8600},
|
||||
targetUtilization: 14334,
|
||||
expectedUtilization: 8600,
|
||||
targetUsage: 14334,
|
||||
expectedUsage: 8600,
|
||||
selector: &metav1.LabelSelector{MatchLabels: map[string]string{"label": "value"}},
|
||||
metricType: externalMetric,
|
||||
},
|
||||
@ -953,8 +953,8 @@ func TestReplicaCalcScaleDownPerPodCMExternal(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{8600},
|
||||
perPodTargetUtilization: 2867,
|
||||
expectedUtilization: 1720,
|
||||
perPodTargetUsage: 2867,
|
||||
expectedUsage: 1720,
|
||||
selector: &metav1.LabelSelector{MatchLabels: map[string]string{"label": "value"}},
|
||||
metricType: externalPerPodMetric,
|
||||
},
|
||||
@ -1180,8 +1180,8 @@ func TestReplicaCalcToleranceCM(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{20000, 21000, 21000},
|
||||
targetUtilization: 20000,
|
||||
expectedUtilization: 20666,
|
||||
targetUsage: 20000,
|
||||
expectedUsage: 20666,
|
||||
metricType: podMetric,
|
||||
},
|
||||
}
|
||||
@ -1195,8 +1195,8 @@ func TestReplicaCalcToleranceCMObject(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{20666},
|
||||
targetUtilization: 20000,
|
||||
expectedUtilization: 20666,
|
||||
targetUsage: 20000,
|
||||
expectedUsage: 20666,
|
||||
singleObject: &autoscalingv2.CrossVersionObjectReference{
|
||||
Kind: "Deployment",
|
||||
APIVersion: "apps/v1",
|
||||
@ -1215,8 +1215,8 @@ func TestReplicaCalcTolerancePerPodCMObject(t *testing.T) {
|
||||
metricType: objectPerPodMetric,
|
||||
name: "qps",
|
||||
levels: []int64{20166},
|
||||
perPodTargetUtilization: 5000,
|
||||
expectedUtilization: 5042,
|
||||
perPodTargetUsage: 5000,
|
||||
expectedUsage: 5042,
|
||||
singleObject: &autoscalingv2.CrossVersionObjectReference{
|
||||
Kind: "Deployment",
|
||||
APIVersion: "apps/v1",
|
||||
@ -1234,8 +1234,8 @@ func TestReplicaCalcToleranceCMExternal(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{8600},
|
||||
targetUtilization: 8888,
|
||||
expectedUtilization: 8600,
|
||||
targetUsage: 8888,
|
||||
expectedUsage: 8600,
|
||||
selector: &metav1.LabelSelector{MatchLabels: map[string]string{"label": "value"}},
|
||||
metricType: externalMetric,
|
||||
},
|
||||
@ -1250,8 +1250,8 @@ func TestReplicaCalcTolerancePerPodCMExternal(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{8600},
|
||||
perPodTargetUtilization: 2900,
|
||||
expectedUtilization: 2867,
|
||||
perPodTargetUsage: 2900,
|
||||
expectedUsage: 2867,
|
||||
selector: &metav1.LabelSelector{MatchLabels: map[string]string{"label": "value"}},
|
||||
metricType: externalPerPodMetric,
|
||||
},
|
||||
@ -1508,8 +1508,8 @@ func TestReplicaCalcDuringRollingUpdateWithMaxSurgeCM(t *testing.T) {
|
||||
metric: &metricInfo{
|
||||
name: "qps",
|
||||
levels: []int64{10000, 10000},
|
||||
targetUtilization: 17000,
|
||||
expectedUtilization: 10000,
|
||||
targetUsage: 17000,
|
||||
expectedUsage: 10000,
|
||||
metricType: podMetric,
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user