mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-20 09:33:52 +00:00
42
pkg/apis/autoscaling/v2/conversion.go
Normal file
42
pkg/apis/autoscaling/v2/conversion.go
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
Copyright 2020 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v2beta2
|
||||
|
||||
import (
|
||||
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
|
||||
|
||||
"k8s.io/apimachinery/pkg/conversion"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
)
|
||||
|
||||
func Convert_autoscaling_HorizontalPodAutoscaler_To_v2beta2_HorizontalPodAutoscaler(in *autoscaling.HorizontalPodAutoscaler, out *autoscalingv2beta2.HorizontalPodAutoscaler, s conversion.Scope) error {
|
||||
if err := autoConvert_autoscaling_HorizontalPodAutoscaler_To_v2beta2_HorizontalPodAutoscaler(in, out, s); err != nil {
|
||||
return err
|
||||
}
|
||||
// v2beta2 round-trips to internal without any serialized annotations, make sure any from other versions don't get serialized
|
||||
out.Annotations, _ = autoscaling.DropRoundTripHorizontalPodAutoscalerAnnotations(out.Annotations)
|
||||
return nil
|
||||
}
|
||||
|
||||
func Convert_v2beta2_HorizontalPodAutoscaler_To_autoscaling_HorizontalPodAutoscaler(in *autoscalingv2beta2.HorizontalPodAutoscaler, out *autoscaling.HorizontalPodAutoscaler, s conversion.Scope) error {
|
||||
if err := autoConvert_v2beta2_HorizontalPodAutoscaler_To_autoscaling_HorizontalPodAutoscaler(in, out, s); err != nil {
|
||||
return err
|
||||
}
|
||||
// v2beta2 round-trips to internal without any serialized annotations, make sure any from other versions don't get serialized
|
||||
out.Annotations, _ = autoscaling.DropRoundTripHorizontalPodAutoscalerAnnotations(out.Annotations)
|
||||
return nil
|
||||
}
|
134
pkg/apis/autoscaling/v2/defaults.go
Normal file
134
pkg/apis/autoscaling/v2/defaults.go
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v2beta2
|
||||
|
||||
import (
|
||||
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
)
|
||||
|
||||
var (
|
||||
// These constants repeats previous HPA behavior
|
||||
scaleUpLimitPercent int32 = 100
|
||||
scaleUpLimitMinimumPods int32 = 4
|
||||
scaleUpPeriod int32 = 15
|
||||
scaleUpStabilizationSeconds int32
|
||||
maxPolicy = autoscalingv2beta2.MaxPolicySelect
|
||||
defaultHPAScaleUpRules = autoscalingv2beta2.HPAScalingRules{
|
||||
StabilizationWindowSeconds: &scaleUpStabilizationSeconds,
|
||||
SelectPolicy: &maxPolicy,
|
||||
Policies: []autoscalingv2beta2.HPAScalingPolicy{
|
||||
{
|
||||
Type: autoscalingv2beta2.PodsScalingPolicy,
|
||||
Value: scaleUpLimitMinimumPods,
|
||||
PeriodSeconds: scaleUpPeriod,
|
||||
},
|
||||
{
|
||||
Type: autoscalingv2beta2.PercentScalingPolicy,
|
||||
Value: scaleUpLimitPercent,
|
||||
PeriodSeconds: scaleUpPeriod,
|
||||
},
|
||||
},
|
||||
}
|
||||
scaleDownPeriod int32 = 15
|
||||
// Currently we can set the downscaleStabilizationWindow from the command line
|
||||
// So we can not rewrite the command line option from here
|
||||
scaleDownStabilizationSeconds *int32 = nil
|
||||
scaleDownLimitPercent int32 = 100
|
||||
defaultHPAScaleDownRules = autoscalingv2beta2.HPAScalingRules{
|
||||
StabilizationWindowSeconds: scaleDownStabilizationSeconds,
|
||||
SelectPolicy: &maxPolicy,
|
||||
Policies: []autoscalingv2beta2.HPAScalingPolicy{
|
||||
{
|
||||
Type: autoscalingv2beta2.PercentScalingPolicy,
|
||||
Value: scaleDownLimitPercent,
|
||||
PeriodSeconds: scaleDownPeriod,
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func addDefaultingFuncs(scheme *runtime.Scheme) error {
|
||||
return RegisterDefaults(scheme)
|
||||
}
|
||||
|
||||
func SetDefaults_HorizontalPodAutoscaler(obj *autoscalingv2beta2.HorizontalPodAutoscaler) {
|
||||
if obj.Spec.MinReplicas == nil {
|
||||
minReplicas := int32(1)
|
||||
obj.Spec.MinReplicas = &minReplicas
|
||||
}
|
||||
|
||||
if len(obj.Spec.Metrics) == 0 {
|
||||
utilizationDefaultVal := int32(autoscaling.DefaultCPUUtilization)
|
||||
obj.Spec.Metrics = []autoscalingv2beta2.MetricSpec{
|
||||
{
|
||||
Type: autoscalingv2beta2.ResourceMetricSourceType,
|
||||
Resource: &autoscalingv2beta2.ResourceMetricSource{
|
||||
Name: v1.ResourceCPU,
|
||||
Target: autoscalingv2beta2.MetricTarget{
|
||||
Type: autoscalingv2beta2.UtilizationMetricType,
|
||||
AverageUtilization: &utilizationDefaultVal,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
SetDefaults_HorizontalPodAutoscalerBehavior(obj)
|
||||
}
|
||||
|
||||
// SetDefaults_HorizontalPodAutoscalerBehavior fills the behavior if it is not null
|
||||
func SetDefaults_HorizontalPodAutoscalerBehavior(obj *autoscalingv2beta2.HorizontalPodAutoscaler) {
|
||||
// if behavior is specified, we should fill all the 'nil' values with the default ones
|
||||
if obj.Spec.Behavior != nil {
|
||||
obj.Spec.Behavior.ScaleUp = GenerateHPAScaleUpRules(obj.Spec.Behavior.ScaleUp)
|
||||
obj.Spec.Behavior.ScaleDown = GenerateHPAScaleDownRules(obj.Spec.Behavior.ScaleDown)
|
||||
}
|
||||
}
|
||||
|
||||
// GenerateHPAScaleUpRules returns a fully-initialized HPAScalingRules value
|
||||
// We guarantee that no pointer in the structure will have the 'nil' value
|
||||
func GenerateHPAScaleUpRules(scalingRules *autoscalingv2beta2.HPAScalingRules) *autoscalingv2beta2.HPAScalingRules {
|
||||
defaultScalingRules := defaultHPAScaleUpRules.DeepCopy()
|
||||
return copyHPAScalingRules(scalingRules, defaultScalingRules)
|
||||
}
|
||||
|
||||
// GenerateHPAScaleDownRules returns a fully-initialized HPAScalingRules value
|
||||
// We guarantee that no pointer in the structure will have the 'nil' value
|
||||
// EXCEPT StabilizationWindowSeconds, for reasoning check the comment for defaultHPAScaleDownRules
|
||||
func GenerateHPAScaleDownRules(scalingRules *autoscalingv2beta2.HPAScalingRules) *autoscalingv2beta2.HPAScalingRules {
|
||||
defaultScalingRules := defaultHPAScaleDownRules.DeepCopy()
|
||||
return copyHPAScalingRules(scalingRules, defaultScalingRules)
|
||||
}
|
||||
|
||||
// copyHPAScalingRules copies all non-`nil` fields in HPA constraint structure
|
||||
func copyHPAScalingRules(from, to *autoscalingv2beta2.HPAScalingRules) *autoscalingv2beta2.HPAScalingRules {
|
||||
if from == nil {
|
||||
return to
|
||||
}
|
||||
if from.SelectPolicy != nil {
|
||||
to.SelectPolicy = from.SelectPolicy
|
||||
}
|
||||
if from.StabilizationWindowSeconds != nil {
|
||||
to.StabilizationWindowSeconds = from.StabilizationWindowSeconds
|
||||
}
|
||||
if from.Policies != nil {
|
||||
to.Policies = from.Policies
|
||||
}
|
||||
return to
|
||||
}
|
324
pkg/apis/autoscaling/v2/defaults_test.go
Normal file
324
pkg/apis/autoscaling/v2/defaults_test.go
Normal file
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v2beta2_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/diff"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/autoscaling"
|
||||
_ "k8s.io/kubernetes/pkg/apis/autoscaling/install"
|
||||
. "k8s.io/kubernetes/pkg/apis/autoscaling/v2beta2"
|
||||
_ "k8s.io/kubernetes/pkg/apis/core/install"
|
||||
utilpointer "k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
func TestGenerateScaleDownRules(t *testing.T) {
|
||||
type TestCase struct {
|
||||
rateDownPods int32
|
||||
rateDownPodsPeriodSeconds int32
|
||||
rateDownPercent int32
|
||||
rateDownPercentPeriodSeconds int32
|
||||
stabilizationSeconds *int32
|
||||
selectPolicy *autoscalingv2.ScalingPolicySelect
|
||||
|
||||
expectedPolicies []autoscalingv2.HPAScalingPolicy
|
||||
expectedStabilization *int32
|
||||
expectedSelectPolicy string
|
||||
annotation string
|
||||
}
|
||||
maxPolicy := autoscalingv2.MaxPolicySelect
|
||||
minPolicy := autoscalingv2.MinPolicySelect
|
||||
tests := []TestCase{
|
||||
{
|
||||
annotation: "Default values",
|
||||
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
|
||||
{Type: autoscalingv2.PercentScalingPolicy, Value: 100, PeriodSeconds: 15},
|
||||
},
|
||||
expectedStabilization: nil,
|
||||
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
|
||||
},
|
||||
{
|
||||
annotation: "All parameters are specified",
|
||||
rateDownPods: 1,
|
||||
rateDownPodsPeriodSeconds: 2,
|
||||
rateDownPercent: 3,
|
||||
rateDownPercentPeriodSeconds: 4,
|
||||
stabilizationSeconds: utilpointer.Int32Ptr(25),
|
||||
selectPolicy: &maxPolicy,
|
||||
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
|
||||
{Type: autoscalingv2.PodsScalingPolicy, Value: 1, PeriodSeconds: 2},
|
||||
{Type: autoscalingv2.PercentScalingPolicy, Value: 3, PeriodSeconds: 4},
|
||||
},
|
||||
expectedStabilization: utilpointer.Int32Ptr(25),
|
||||
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
|
||||
},
|
||||
{
|
||||
annotation: "Percent policy is specified",
|
||||
rateDownPercent: 1,
|
||||
rateDownPercentPeriodSeconds: 2,
|
||||
selectPolicy: &minPolicy,
|
||||
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
|
||||
{Type: autoscalingv2.PercentScalingPolicy, Value: 1, PeriodSeconds: 2},
|
||||
},
|
||||
expectedStabilization: nil,
|
||||
expectedSelectPolicy: string(autoscalingv2.MinPolicySelect),
|
||||
},
|
||||
{
|
||||
annotation: "Pods policy is specified",
|
||||
rateDownPods: 3,
|
||||
rateDownPodsPeriodSeconds: 4,
|
||||
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
|
||||
{Type: autoscalingv2.PodsScalingPolicy, Value: 3, PeriodSeconds: 4},
|
||||
},
|
||||
expectedStabilization: nil,
|
||||
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.annotation, func(t *testing.T) {
|
||||
scaleDownRules := &autoscalingv2.HPAScalingRules{
|
||||
StabilizationWindowSeconds: tc.stabilizationSeconds,
|
||||
SelectPolicy: tc.selectPolicy,
|
||||
}
|
||||
if tc.rateDownPods != 0 || tc.rateDownPodsPeriodSeconds != 0 {
|
||||
scaleDownRules.Policies = append(scaleDownRules.Policies, autoscalingv2.HPAScalingPolicy{
|
||||
Type: autoscalingv2.PodsScalingPolicy, Value: tc.rateDownPods, PeriodSeconds: tc.rateDownPodsPeriodSeconds,
|
||||
})
|
||||
}
|
||||
if tc.rateDownPercent != 0 || tc.rateDownPercentPeriodSeconds != 0 {
|
||||
scaleDownRules.Policies = append(scaleDownRules.Policies, autoscalingv2.HPAScalingPolicy{
|
||||
Type: autoscalingv2.PercentScalingPolicy, Value: tc.rateDownPercent, PeriodSeconds: tc.rateDownPercentPeriodSeconds,
|
||||
})
|
||||
}
|
||||
down := GenerateHPAScaleDownRules(scaleDownRules)
|
||||
assert.EqualValues(t, tc.expectedPolicies, down.Policies)
|
||||
if tc.expectedStabilization != nil {
|
||||
assert.Equal(t, *tc.expectedStabilization, *down.StabilizationWindowSeconds)
|
||||
} else {
|
||||
assert.Equal(t, tc.expectedStabilization, down.StabilizationWindowSeconds)
|
||||
}
|
||||
assert.Equal(t, autoscalingv2.ScalingPolicySelect(tc.expectedSelectPolicy), *down.SelectPolicy)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateScaleUpRules(t *testing.T) {
|
||||
type TestCase struct {
|
||||
rateUpPods int32
|
||||
rateUpPodsPeriodSeconds int32
|
||||
rateUpPercent int32
|
||||
rateUpPercentPeriodSeconds int32
|
||||
stabilizationSeconds *int32
|
||||
selectPolicy *autoscalingv2.ScalingPolicySelect
|
||||
|
||||
expectedPolicies []autoscalingv2.HPAScalingPolicy
|
||||
expectedStabilization *int32
|
||||
expectedSelectPolicy string
|
||||
annotation string
|
||||
}
|
||||
maxPolicy := autoscalingv2.MaxPolicySelect
|
||||
minPolicy := autoscalingv2.MinPolicySelect
|
||||
tests := []TestCase{
|
||||
{
|
||||
annotation: "Default values",
|
||||
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
|
||||
{Type: autoscalingv2.PodsScalingPolicy, Value: 4, PeriodSeconds: 15},
|
||||
{Type: autoscalingv2.PercentScalingPolicy, Value: 100, PeriodSeconds: 15},
|
||||
},
|
||||
expectedStabilization: utilpointer.Int32Ptr(0),
|
||||
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
|
||||
},
|
||||
{
|
||||
annotation: "All parameters are specified",
|
||||
rateUpPods: 1,
|
||||
rateUpPodsPeriodSeconds: 2,
|
||||
rateUpPercent: 3,
|
||||
rateUpPercentPeriodSeconds: 4,
|
||||
stabilizationSeconds: utilpointer.Int32Ptr(25),
|
||||
selectPolicy: &maxPolicy,
|
||||
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
|
||||
{Type: autoscalingv2.PodsScalingPolicy, Value: 1, PeriodSeconds: 2},
|
||||
{Type: autoscalingv2.PercentScalingPolicy, Value: 3, PeriodSeconds: 4},
|
||||
},
|
||||
expectedStabilization: utilpointer.Int32Ptr(25),
|
||||
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
|
||||
},
|
||||
{
|
||||
annotation: "Pod policy is specified",
|
||||
rateUpPods: 1,
|
||||
rateUpPodsPeriodSeconds: 2,
|
||||
selectPolicy: &minPolicy,
|
||||
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
|
||||
{Type: autoscalingv2.PodsScalingPolicy, Value: 1, PeriodSeconds: 2},
|
||||
},
|
||||
expectedStabilization: utilpointer.Int32Ptr(0),
|
||||
expectedSelectPolicy: string(autoscalingv2.MinPolicySelect),
|
||||
},
|
||||
{
|
||||
annotation: "Percent policy is specified",
|
||||
rateUpPercent: 7,
|
||||
rateUpPercentPeriodSeconds: 10,
|
||||
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
|
||||
{Type: autoscalingv2.PercentScalingPolicy, Value: 7, PeriodSeconds: 10},
|
||||
},
|
||||
expectedStabilization: utilpointer.Int32Ptr(0),
|
||||
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
|
||||
},
|
||||
{
|
||||
annotation: "Pod policy and stabilization window are specified",
|
||||
rateUpPodsPeriodSeconds: 2,
|
||||
stabilizationSeconds: utilpointer.Int32Ptr(25),
|
||||
rateUpPods: 4,
|
||||
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
|
||||
{Type: autoscalingv2.PodsScalingPolicy, Value: 4, PeriodSeconds: 2},
|
||||
},
|
||||
expectedStabilization: utilpointer.Int32Ptr(25),
|
||||
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
|
||||
},
|
||||
{
|
||||
annotation: "Percent policy and stabilization window are specified",
|
||||
rateUpPercent: 7,
|
||||
rateUpPercentPeriodSeconds: 60,
|
||||
stabilizationSeconds: utilpointer.Int32Ptr(25),
|
||||
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
|
||||
{Type: autoscalingv2.PercentScalingPolicy, Value: 7, PeriodSeconds: 60},
|
||||
},
|
||||
expectedStabilization: utilpointer.Int32Ptr(25),
|
||||
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.annotation, func(t *testing.T) {
|
||||
scaleUpRules := &autoscalingv2.HPAScalingRules{
|
||||
StabilizationWindowSeconds: tc.stabilizationSeconds,
|
||||
SelectPolicy: tc.selectPolicy,
|
||||
}
|
||||
if tc.rateUpPods != 0 || tc.rateUpPodsPeriodSeconds != 0 {
|
||||
scaleUpRules.Policies = append(scaleUpRules.Policies, autoscalingv2.HPAScalingPolicy{
|
||||
Type: autoscalingv2.PodsScalingPolicy, Value: tc.rateUpPods, PeriodSeconds: tc.rateUpPodsPeriodSeconds,
|
||||
})
|
||||
}
|
||||
if tc.rateUpPercent != 0 || tc.rateUpPercentPeriodSeconds != 0 {
|
||||
scaleUpRules.Policies = append(scaleUpRules.Policies, autoscalingv2.HPAScalingPolicy{
|
||||
Type: autoscalingv2.PercentScalingPolicy, Value: tc.rateUpPercent, PeriodSeconds: tc.rateUpPercentPeriodSeconds,
|
||||
})
|
||||
}
|
||||
up := GenerateHPAScaleUpRules(scaleUpRules)
|
||||
assert.Equal(t, tc.expectedPolicies, up.Policies)
|
||||
if tc.expectedStabilization != nil {
|
||||
assert.Equal(t, *tc.expectedStabilization, *up.StabilizationWindowSeconds)
|
||||
} else {
|
||||
assert.Equal(t, tc.expectedStabilization, up.StabilizationWindowSeconds)
|
||||
}
|
||||
|
||||
assert.Equal(t, autoscalingv2.ScalingPolicySelect(tc.expectedSelectPolicy), *up.SelectPolicy)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHorizontalPodAutoscalerAnnotations(t *testing.T) {
|
||||
tests := []struct {
|
||||
hpa autoscalingv2.HorizontalPodAutoscaler
|
||||
test string
|
||||
}{
|
||||
{
|
||||
hpa: autoscalingv2.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "",
|
||||
autoscaling.MetricSpecsAnnotation: "",
|
||||
autoscaling.BehaviorSpecsAnnotation: "",
|
||||
autoscaling.MetricStatusesAnnotation: "",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test empty value for Annotations",
|
||||
},
|
||||
{
|
||||
hpa: autoscalingv2.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "abc",
|
||||
autoscaling.MetricSpecsAnnotation: "abc",
|
||||
autoscaling.BehaviorSpecsAnnotation: "abc",
|
||||
autoscaling.MetricStatusesAnnotation: "abc",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test random value for Annotations",
|
||||
},
|
||||
{
|
||||
hpa: autoscalingv2.HorizontalPodAutoscaler{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: map[string]string{
|
||||
autoscaling.HorizontalPodAutoscalerConditionsAnnotation: "[]",
|
||||
autoscaling.MetricSpecsAnnotation: "[]",
|
||||
autoscaling.BehaviorSpecsAnnotation: "[]",
|
||||
autoscaling.MetricStatusesAnnotation: "[]",
|
||||
},
|
||||
},
|
||||
},
|
||||
test: "test empty array value for Annotations",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
hpa := &test.hpa
|
||||
hpaBeforeMuatate := *hpa.DeepCopy()
|
||||
obj := roundTrip(t, runtime.Object(hpa))
|
||||
final_obj, ok := obj.(*autoscalingv2.HorizontalPodAutoscaler)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected object: %v", obj)
|
||||
}
|
||||
if !reflect.DeepEqual(*hpa, hpaBeforeMuatate) {
|
||||
t.Errorf("diff: %v", diff.ObjectDiff(*hpa, hpaBeforeMuatate))
|
||||
t.Errorf("expected: %#v\n actual: %#v", *hpa, hpaBeforeMuatate)
|
||||
}
|
||||
|
||||
if len(final_obj.ObjectMeta.Annotations) != 0 {
|
||||
t.Fatalf("unexpected annotations: %v", final_obj.ObjectMeta.Annotations)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
|
||||
data, err := runtime.Encode(legacyscheme.Codecs.LegacyCodec(SchemeGroupVersion), obj)
|
||||
if err != nil {
|
||||
t.Errorf("%v\n %#v", err, obj)
|
||||
return nil
|
||||
}
|
||||
obj2, err := runtime.Decode(legacyscheme.Codecs.UniversalDecoder(), data)
|
||||
if err != nil {
|
||||
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
|
||||
return nil
|
||||
}
|
||||
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
|
||||
err = legacyscheme.Scheme.Convert(obj2, obj3, nil)
|
||||
if err != nil {
|
||||
t.Errorf("%v\nSource: %#v", err, obj2)
|
||||
return nil
|
||||
}
|
||||
return obj3
|
||||
}
|
22
pkg/apis/autoscaling/v2/doc.go
Normal file
22
pkg/apis/autoscaling/v2/doc.go
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/autoscaling
|
||||
// +k8s:conversion-gen-external-types=k8s.io/api/autoscaling/v2beta2
|
||||
// +k8s:defaulter-gen=TypeMeta
|
||||
// +k8s:defaulter-gen-input=../../../../vendor/k8s.io/api/autoscaling/v2beta2
|
||||
|
||||
package v2beta2 // import "k8s.io/kubernetes/pkg/apis/autoscaling/v2beta2"
|
45
pkg/apis/autoscaling/v2/register.go
Normal file
45
pkg/apis/autoscaling/v2/register.go
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package v2beta2
|
||||
|
||||
import (
|
||||
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
// GroupName is the group name use in this package
|
||||
const GroupName = "autoscaling"
|
||||
|
||||
// SchemeGroupVersion is group version used to register these objects
|
||||
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v2beta2"}
|
||||
|
||||
// Resource takes an unqualified resource and returns a Group qualified GroupResource
|
||||
func Resource(resource string) schema.GroupResource {
|
||||
return SchemeGroupVersion.WithResource(resource).GroupResource()
|
||||
}
|
||||
|
||||
var (
|
||||
localSchemeBuilder = &autoscalingv2beta2.SchemeBuilder
|
||||
AddToScheme = localSchemeBuilder.AddToScheme
|
||||
)
|
||||
|
||||
func init() {
|
||||
// We only register manually written functions here. The registration of the
|
||||
// generated functions takes place in the generated files. The separation
|
||||
// makes the code compile even when the generated files are missing.
|
||||
localSchemeBuilder.Register(addDefaultingFuncs)
|
||||
}
|
1036
pkg/apis/autoscaling/v2/zz_generated.conversion.go
generated
Normal file
1036
pkg/apis/autoscaling/v2/zz_generated.conversion.go
generated
Normal file
File diff suppressed because it is too large
Load Diff
50
pkg/apis/autoscaling/v2/zz_generated.defaults.go
generated
Normal file
50
pkg/apis/autoscaling/v2/zz_generated.defaults.go
generated
Normal file
@@ -0,0 +1,50 @@
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
/*
|
||||
Copyright The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Code generated by defaulter-gen. DO NOT EDIT.
|
||||
|
||||
package v2beta2
|
||||
|
||||
import (
|
||||
v2beta2 "k8s.io/api/autoscaling/v2beta2"
|
||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
// RegisterDefaults adds defaulters functions to the given scheme.
|
||||
// Public to allow building arbitrary schemes.
|
||||
// All generated defaulters are covering - they call all nested defaulters.
|
||||
func RegisterDefaults(scheme *runtime.Scheme) error {
|
||||
scheme.AddTypeDefaultingFunc(&v2beta2.HorizontalPodAutoscaler{}, func(obj interface{}) {
|
||||
SetObjectDefaults_HorizontalPodAutoscaler(obj.(*v2beta2.HorizontalPodAutoscaler))
|
||||
})
|
||||
scheme.AddTypeDefaultingFunc(&v2beta2.HorizontalPodAutoscalerList{}, func(obj interface{}) {
|
||||
SetObjectDefaults_HorizontalPodAutoscalerList(obj.(*v2beta2.HorizontalPodAutoscalerList))
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetObjectDefaults_HorizontalPodAutoscaler(in *v2beta2.HorizontalPodAutoscaler) {
|
||||
SetDefaults_HorizontalPodAutoscaler(in)
|
||||
}
|
||||
|
||||
func SetObjectDefaults_HorizontalPodAutoscalerList(in *v2beta2.HorizontalPodAutoscalerList) {
|
||||
for i := range in.Items {
|
||||
a := &in.Items[i]
|
||||
SetObjectDefaults_HorizontalPodAutoscaler(a)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user