rename v2beta2 to v2

Signed-off-by: wangyysde <net_use@bzhy.com>

Generation swagger.json.

Use v2 path for hpa_cpu_field.

run update-codegen.sh

Signed-off-by: wangyysde <net_use@bzhy.com>
This commit is contained in:
wangyysde
2021-07-06 16:02:42 +08:00
parent f5c75813e3
commit d2abddd909
84 changed files with 6166 additions and 710 deletions

View File

@@ -24,6 +24,7 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/autoscaling/v1"
"k8s.io/kubernetes/pkg/apis/autoscaling/v2"
"k8s.io/kubernetes/pkg/apis/autoscaling/v2beta1"
"k8s.io/kubernetes/pkg/apis/autoscaling/v2beta2"
)
@@ -36,7 +37,9 @@ func init() {
func Install(scheme *runtime.Scheme) {
utilruntime.Must(autoscaling.AddToScheme(scheme))
utilruntime.Must(v2beta2.AddToScheme(scheme))
utilruntime.Must(v2.AddToScheme(scheme))
utilruntime.Must(v2beta1.AddToScheme(scheme))
utilruntime.Must(v1.AddToScheme(scheme))
utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v2beta1.SchemeGroupVersion, v2beta2.SchemeGroupVersion))
// TODO: move v2 to the front of the list in 1.24
utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion, v2.SchemeGroupVersion, v2beta1.SchemeGroupVersion, v2beta2.SchemeGroupVersion))
}

View File

@@ -1,5 +1,5 @@
/*
Copyright 2020 The Kubernetes Authors.
Copyright 2021 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.
@@ -14,29 +14,29 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package v2beta2
package v2
import (
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
autoscalingv2 "k8s.io/api/autoscaling/v2"
"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 {
func Convert_autoscaling_HorizontalPodAutoscaler_To_v2_HorizontalPodAutoscaler(in *autoscaling.HorizontalPodAutoscaler, out *autoscalingv2.HorizontalPodAutoscaler, s conversion.Scope) error {
if err := autoConvert_autoscaling_HorizontalPodAutoscaler_To_v2_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
// v2 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 {
func Convert_v2_HorizontalPodAutoscaler_To_autoscaling_HorizontalPodAutoscaler(in *autoscalingv2.HorizontalPodAutoscaler, out *autoscaling.HorizontalPodAutoscaler, s conversion.Scope) error {
if err := autoConvert_v2_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
// v2 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
}

View File

@@ -1,5 +1,5 @@
/*
Copyright 2018 The Kubernetes Authors.
Copyright 2021 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.
@@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package v2beta2
package v2
import (
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
autoscalingv2 "k8s.io/api/autoscaling/v2"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/apis/autoscaling"
@@ -29,18 +29,18 @@ var (
scaleUpLimitMinimumPods int32 = 4
scaleUpPeriod int32 = 15
scaleUpStabilizationSeconds int32
maxPolicy = autoscalingv2beta2.MaxPolicySelect
defaultHPAScaleUpRules = autoscalingv2beta2.HPAScalingRules{
maxPolicy = autoscalingv2.MaxChangePolicySelect
defaultHPAScaleUpRules = autoscalingv2.HPAScalingRules{
StabilizationWindowSeconds: &scaleUpStabilizationSeconds,
SelectPolicy: &maxPolicy,
Policies: []autoscalingv2beta2.HPAScalingPolicy{
Policies: []autoscalingv2.HPAScalingPolicy{
{
Type: autoscalingv2beta2.PodsScalingPolicy,
Type: autoscalingv2.PodsScalingPolicy,
Value: scaleUpLimitMinimumPods,
PeriodSeconds: scaleUpPeriod,
},
{
Type: autoscalingv2beta2.PercentScalingPolicy,
Type: autoscalingv2.PercentScalingPolicy,
Value: scaleUpLimitPercent,
PeriodSeconds: scaleUpPeriod,
},
@@ -49,14 +49,13 @@ var (
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,
scaleDownLimitPercent int32 = 100
defaultHPAScaleDownRules = autoscalingv2.HPAScalingRules{
StabilizationWindowSeconds: nil,
SelectPolicy: &maxPolicy,
Policies: []autoscalingv2beta2.HPAScalingPolicy{
Policies: []autoscalingv2.HPAScalingPolicy{
{
Type: autoscalingv2beta2.PercentScalingPolicy,
Type: autoscalingv2.PercentScalingPolicy,
Value: scaleDownLimitPercent,
PeriodSeconds: scaleDownPeriod,
},
@@ -68,7 +67,7 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}
func SetDefaults_HorizontalPodAutoscaler(obj *autoscalingv2beta2.HorizontalPodAutoscaler) {
func SetDefaults_HorizontalPodAutoscaler(obj *autoscalingv2.HorizontalPodAutoscaler) {
if obj.Spec.MinReplicas == nil {
minReplicas := int32(1)
obj.Spec.MinReplicas = &minReplicas
@@ -76,13 +75,13 @@ func SetDefaults_HorizontalPodAutoscaler(obj *autoscalingv2beta2.HorizontalPodAu
if len(obj.Spec.Metrics) == 0 {
utilizationDefaultVal := int32(autoscaling.DefaultCPUUtilization)
obj.Spec.Metrics = []autoscalingv2beta2.MetricSpec{
obj.Spec.Metrics = []autoscalingv2.MetricSpec{
{
Type: autoscalingv2beta2.ResourceMetricSourceType,
Resource: &autoscalingv2beta2.ResourceMetricSource{
Type: autoscalingv2.ResourceMetricSourceType,
Resource: &autoscalingv2.ResourceMetricSource{
Name: v1.ResourceCPU,
Target: autoscalingv2beta2.MetricTarget{
Type: autoscalingv2beta2.UtilizationMetricType,
Target: autoscalingv2.MetricTarget{
Type: autoscalingv2.UtilizationMetricType,
AverageUtilization: &utilizationDefaultVal,
},
},
@@ -93,7 +92,7 @@ func SetDefaults_HorizontalPodAutoscaler(obj *autoscalingv2beta2.HorizontalPodAu
}
// SetDefaults_HorizontalPodAutoscalerBehavior fills the behavior if it is not null
func SetDefaults_HorizontalPodAutoscalerBehavior(obj *autoscalingv2beta2.HorizontalPodAutoscaler) {
func SetDefaults_HorizontalPodAutoscalerBehavior(obj *autoscalingv2.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)
@@ -103,7 +102,7 @@ func SetDefaults_HorizontalPodAutoscalerBehavior(obj *autoscalingv2beta2.Horizon
// 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 {
func GenerateHPAScaleUpRules(scalingRules *autoscalingv2.HPAScalingRules) *autoscalingv2.HPAScalingRules {
defaultScalingRules := defaultHPAScaleUpRules.DeepCopy()
return copyHPAScalingRules(scalingRules, defaultScalingRules)
}
@@ -111,13 +110,13 @@ func GenerateHPAScaleUpRules(scalingRules *autoscalingv2beta2.HPAScalingRules) *
// 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 {
func GenerateHPAScaleDownRules(scalingRules *autoscalingv2.HPAScalingRules) *autoscalingv2.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 {
func copyHPAScalingRules(from, to *autoscalingv2.HPAScalingRules) *autoscalingv2.HPAScalingRules {
if from == nil {
return to
}

View File

@@ -1,5 +1,5 @@
/*
Copyright 2017 The Kubernetes Authors.
Copyright 2021 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.
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package v2beta2_test
package v2_test
import (
"reflect"
@@ -25,11 +25,11 @@ import (
"k8s.io/kubernetes/pkg/api/legacyscheme"
"github.com/stretchr/testify/assert"
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
autoscalingv2 "k8s.io/api/autoscaling/v2"
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/autoscaling/v2"
_ "k8s.io/kubernetes/pkg/apis/core/install"
utilpointer "k8s.io/utils/pointer"
)
@@ -48,8 +48,8 @@ func TestGenerateScaleDownRules(t *testing.T) {
expectedSelectPolicy string
annotation string
}
maxPolicy := autoscalingv2.MaxPolicySelect
minPolicy := autoscalingv2.MinPolicySelect
maxPolicy := autoscalingv2.MaxChangePolicySelect
minPolicy := autoscalingv2.MinChangePolicySelect
tests := []TestCase{
{
annotation: "Default values",
@@ -57,7 +57,7 @@ func TestGenerateScaleDownRules(t *testing.T) {
{Type: autoscalingv2.PercentScalingPolicy, Value: 100, PeriodSeconds: 15},
},
expectedStabilization: nil,
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MaxChangePolicySelect),
},
{
annotation: "All parameters are specified",
@@ -72,7 +72,7 @@ func TestGenerateScaleDownRules(t *testing.T) {
{Type: autoscalingv2.PercentScalingPolicy, Value: 3, PeriodSeconds: 4},
},
expectedStabilization: utilpointer.Int32Ptr(25),
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MaxChangePolicySelect),
},
{
annotation: "Percent policy is specified",
@@ -83,7 +83,7 @@ func TestGenerateScaleDownRules(t *testing.T) {
{Type: autoscalingv2.PercentScalingPolicy, Value: 1, PeriodSeconds: 2},
},
expectedStabilization: nil,
expectedSelectPolicy: string(autoscalingv2.MinPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MinChangePolicySelect),
},
{
annotation: "Pods policy is specified",
@@ -93,7 +93,7 @@ func TestGenerateScaleDownRules(t *testing.T) {
{Type: autoscalingv2.PodsScalingPolicy, Value: 3, PeriodSeconds: 4},
},
expectedStabilization: nil,
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MaxChangePolicySelect),
},
}
for _, tc := range tests {
@@ -138,8 +138,8 @@ func TestGenerateScaleUpRules(t *testing.T) {
expectedSelectPolicy string
annotation string
}
maxPolicy := autoscalingv2.MaxPolicySelect
minPolicy := autoscalingv2.MinPolicySelect
maxPolicy := autoscalingv2.MaxChangePolicySelect
minPolicy := autoscalingv2.MinChangePolicySelect
tests := []TestCase{
{
annotation: "Default values",
@@ -148,7 +148,7 @@ func TestGenerateScaleUpRules(t *testing.T) {
{Type: autoscalingv2.PercentScalingPolicy, Value: 100, PeriodSeconds: 15},
},
expectedStabilization: utilpointer.Int32Ptr(0),
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MaxChangePolicySelect),
},
{
annotation: "All parameters are specified",
@@ -163,7 +163,7 @@ func TestGenerateScaleUpRules(t *testing.T) {
{Type: autoscalingv2.PercentScalingPolicy, Value: 3, PeriodSeconds: 4},
},
expectedStabilization: utilpointer.Int32Ptr(25),
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MaxChangePolicySelect),
},
{
annotation: "Pod policy is specified",
@@ -174,7 +174,7 @@ func TestGenerateScaleUpRules(t *testing.T) {
{Type: autoscalingv2.PodsScalingPolicy, Value: 1, PeriodSeconds: 2},
},
expectedStabilization: utilpointer.Int32Ptr(0),
expectedSelectPolicy: string(autoscalingv2.MinPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MinChangePolicySelect),
},
{
annotation: "Percent policy is specified",
@@ -184,7 +184,7 @@ func TestGenerateScaleUpRules(t *testing.T) {
{Type: autoscalingv2.PercentScalingPolicy, Value: 7, PeriodSeconds: 10},
},
expectedStabilization: utilpointer.Int32Ptr(0),
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MaxChangePolicySelect),
},
{
annotation: "Pod policy and stabilization window are specified",
@@ -195,7 +195,7 @@ func TestGenerateScaleUpRules(t *testing.T) {
{Type: autoscalingv2.PodsScalingPolicy, Value: 4, PeriodSeconds: 2},
},
expectedStabilization: utilpointer.Int32Ptr(25),
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MaxChangePolicySelect),
},
{
annotation: "Percent policy and stabilization window are specified",
@@ -206,7 +206,7 @@ func TestGenerateScaleUpRules(t *testing.T) {
{Type: autoscalingv2.PercentScalingPolicy, Value: 7, PeriodSeconds: 60},
},
expectedStabilization: utilpointer.Int32Ptr(25),
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MaxChangePolicySelect),
},
}
for _, tc := range tests {

View File

@@ -1,5 +1,5 @@
/*
Copyright 2018 The Kubernetes Authors.
Copyright 2021 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.
@@ -15,8 +15,8 @@ limitations under the License.
*/
// +k8s:conversion-gen=k8s.io/kubernetes/pkg/apis/autoscaling
// +k8s:conversion-gen-external-types=k8s.io/api/autoscaling/v2beta2
// +k8s:conversion-gen-external-types=k8s.io/api/autoscaling/v2
// +k8s:defaulter-gen=TypeMeta
// +k8s:defaulter-gen-input=../../../../vendor/k8s.io/api/autoscaling/v2beta2
// +k8s:defaulter-gen-input=k8s.io/api/autoscaling/v2
package v2beta2 // import "k8s.io/kubernetes/pkg/apis/autoscaling/v2beta2"
package v2 // import "k8s.io/kubernetes/pkg/apis/autoscaling/v2"

View File

@@ -1,5 +1,5 @@
/*
Copyright 2018 The Kubernetes Authors.
Copyright 2021 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.
@@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package v2beta2
package v2
import (
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
autoscalingv2 "k8s.io/api/autoscaling/v2"
"k8s.io/apimachinery/pkg/runtime/schema"
)
@@ -25,7 +25,7 @@ import (
const GroupName = "autoscaling"
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v2beta2"}
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v2"}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
@@ -33,7 +33,7 @@ func Resource(resource string) schema.GroupResource {
}
var (
localSchemeBuilder = &autoscalingv2beta2.SchemeBuilder
localSchemeBuilder = &autoscalingv2.SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,4 @@
//go:build !ignore_autogenerated
// +build !ignore_autogenerated
/*
@@ -18,10 +19,10 @@ limitations under the License.
// Code generated by defaulter-gen. DO NOT EDIT.
package v2beta2
package v2
import (
v2beta2 "k8s.io/api/autoscaling/v2beta2"
v2 "k8s.io/api/autoscaling/v2"
runtime "k8s.io/apimachinery/pkg/runtime"
)
@@ -29,20 +30,18 @@ import (
// 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))
scheme.AddTypeDefaultingFunc(&v2.HorizontalPodAutoscaler{}, func(obj interface{}) { SetObjectDefaults_HorizontalPodAutoscaler(obj.(*v2.HorizontalPodAutoscaler)) })
scheme.AddTypeDefaultingFunc(&v2.HorizontalPodAutoscalerList{}, func(obj interface{}) {
SetObjectDefaults_HorizontalPodAutoscalerList(obj.(*v2.HorizontalPodAutoscalerList))
})
return nil
}
func SetObjectDefaults_HorizontalPodAutoscaler(in *v2beta2.HorizontalPodAutoscaler) {
func SetObjectDefaults_HorizontalPodAutoscaler(in *v2.HorizontalPodAutoscaler) {
SetDefaults_HorizontalPodAutoscaler(in)
}
func SetObjectDefaults_HorizontalPodAutoscalerList(in *v2beta2.HorizontalPodAutoscalerList) {
func SetObjectDefaults_HorizontalPodAutoscalerList(in *v2.HorizontalPodAutoscalerList) {
for i := range in.Items {
a := &in.Items[i]
SetObjectDefaults_HorizontalPodAutoscaler(a)