Skip to content

Commit

Permalink
rename v2beta2 to v2
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
wangyysde committed Nov 9, 2021
1 parent f5c7581 commit d2abddd
Show file tree
Hide file tree
Showing 84 changed files with 7,117 additions and 1,661 deletions.
3,799 changes: 2,850 additions & 949 deletions api/openapi-spec/swagger.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cmd/kube-apiserver/app/aggregator.go
Expand Up @@ -251,6 +251,7 @@ var apiVersionPriorities = map[schema.GroupVersion]priority{
{Group: "authentication.k8s.io", Version: "v1"}: {group: 17700, version: 15},
{Group: "authorization.k8s.io", Version: "v1"}: {group: 17600, version: 15},
{Group: "autoscaling", Version: "v1"}: {group: 17500, version: 15},
{Group: "autoscaling", Version: "v2"}: {group: 17500, version: 30},
{Group: "autoscaling", Version: "v2beta1"}: {group: 17500, version: 9},
{Group: "autoscaling", Version: "v2beta2"}: {group: 17500, version: 1},
{Group: "batch", Version: "v1"}: {group: 17400, version: 15},
Expand Down
1 change: 1 addition & 0 deletions hack/lib/init.sh
Expand Up @@ -76,6 +76,7 @@ authentication.k8s.io/v1beta1 \
authorization.k8s.io/v1 \
authorization.k8s.io/v1beta1 \
autoscaling/v1 \
autoscaling/v2 \
autoscaling/v2beta1 \
autoscaling/v2beta2 \
batch/v1 \
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/testing/defaulting_test.go
Expand Up @@ -77,6 +77,8 @@ func TestDefaulting(t *testing.T) {
{Group: "apps", Version: "v1", Kind: "StatefulSetList"}: {},
{Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscaler"}: {},
{Group: "autoscaling", Version: "v1", Kind: "HorizontalPodAutoscalerList"}: {},
{Group: "autoscaling", Version: "v2", Kind: "HorizontalPodAutoscaler"}: {},
{Group: "autoscaling", Version: "v2", Kind: "HorizontalPodAutoscalerList"}: {},
{Group: "autoscaling", Version: "v2beta1", Kind: "HorizontalPodAutoscaler"}: {},
{Group: "autoscaling", Version: "v2beta1", Kind: "HorizontalPodAutoscalerList"}: {},
{Group: "autoscaling", Version: "v2beta2", Kind: "HorizontalPodAutoscaler"}: {},
Expand Down
5 changes: 4 additions & 1 deletion pkg/apis/autoscaling/install/install.go
Expand Up @@ -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"
)
Expand All @@ -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))
}
18 changes: 9 additions & 9 deletions pkg/apis/autoscaling/v2/conversion.go
@@ -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.
Expand All @@ -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
}
47 changes: 23 additions & 24 deletions pkg/apis/autoscaling/v2/defaults.go
@@ -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.
Expand All @@ -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"
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -68,21 +67,21 @@ 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
}

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,
},
},
Expand All @@ -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)
Expand All @@ -103,21 +102,21 @@ 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)
}

// 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
}
Expand Down
36 changes: 18 additions & 18 deletions pkg/apis/autoscaling/v2/defaults_test.go
@@ -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.
Expand All @@ -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"
Expand All @@ -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"
)
Expand All @@ -48,16 +48,16 @@ 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",
expectedPolicies: []autoscalingv2.HPAScalingPolicy{
{Type: autoscalingv2.PercentScalingPolicy, Value: 100, PeriodSeconds: 15},
},
expectedStabilization: nil,
expectedSelectPolicy: string(autoscalingv2.MaxPolicySelect),
expectedSelectPolicy: string(autoscalingv2.MaxChangePolicySelect),
},
{
annotation: "All parameters are specified",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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 {
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/autoscaling/v2/doc.go
@@ -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.
Expand All @@ -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"

0 comments on commit d2abddd

Please sign in to comment.