Added HorizontalPodAutoscaler object to experimental API.
Added HorizontalPodAutoscaler object to experimental API. Related to #12087.
This commit is contained in:
@@ -21,10 +21,18 @@ import (
|
||||
time "time"
|
||||
|
||||
api "k8s.io/kubernetes/pkg/api"
|
||||
resource "k8s.io/kubernetes/pkg/api/resource"
|
||||
conversion "k8s.io/kubernetes/pkg/conversion"
|
||||
util "k8s.io/kubernetes/pkg/util"
|
||||
inf "speter.net/go/exp/math/dec/inf"
|
||||
)
|
||||
|
||||
func deepCopy_api_ListMeta(in api.ListMeta, out *api.ListMeta, c *conversion.Cloner) error {
|
||||
out.SelfLink = in.SelfLink
|
||||
out.ResourceVersion = in.ResourceVersion
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_api_ObjectMeta(in api.ObjectMeta, out *api.ObjectMeta, c *conversion.Cloner) error {
|
||||
out.Name = in.Name
|
||||
out.GenerateName = in.GenerateName
|
||||
@@ -69,6 +77,72 @@ func deepCopy_api_TypeMeta(in api.TypeMeta, out *api.TypeMeta, c *conversion.Clo
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_resource_Quantity(in resource.Quantity, out *resource.Quantity, c *conversion.Cloner) error {
|
||||
if in.Amount != nil {
|
||||
if newVal, err := c.DeepCopy(in.Amount); err != nil {
|
||||
return err
|
||||
} else if newVal == nil {
|
||||
out.Amount = nil
|
||||
} else {
|
||||
out.Amount = newVal.(*inf.Dec)
|
||||
}
|
||||
} else {
|
||||
out.Amount = nil
|
||||
}
|
||||
out.Format = in.Format
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_expapi_HorizontalPodAutoscaler(in HorizontalPodAutoscaler, out *HorizontalPodAutoscaler, c *conversion.Cloner) error {
|
||||
if err := deepCopy_api_TypeMeta(in.TypeMeta, &out.TypeMeta, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deepCopy_api_ObjectMeta(in.ObjectMeta, &out.ObjectMeta, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deepCopy_expapi_HorizontalPodAutoscalerSpec(in.Spec, &out.Spec, c); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_expapi_HorizontalPodAutoscalerList(in HorizontalPodAutoscalerList, out *HorizontalPodAutoscalerList, c *conversion.Cloner) error {
|
||||
if err := deepCopy_api_TypeMeta(in.TypeMeta, &out.TypeMeta, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deepCopy_api_ListMeta(in.ListMeta, &out.ListMeta, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if in.Items != nil {
|
||||
out.Items = make([]HorizontalPodAutoscaler, len(in.Items))
|
||||
for i := range in.Items {
|
||||
if err := deepCopy_expapi_HorizontalPodAutoscaler(in.Items[i], &out.Items[i], c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Items = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_expapi_HorizontalPodAutoscalerSpec(in HorizontalPodAutoscalerSpec, out *HorizontalPodAutoscalerSpec, c *conversion.Cloner) error {
|
||||
if in.ScaleRef != nil {
|
||||
out.ScaleRef = new(SubresourceReference)
|
||||
if err := deepCopy_expapi_SubresourceReference(*in.ScaleRef, out.ScaleRef, c); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.ScaleRef = nil
|
||||
}
|
||||
out.MinCount = in.MinCount
|
||||
out.MaxCount = in.MaxCount
|
||||
if err := deepCopy_expapi_TargetConsumption(in.Target, &out.Target, c); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_expapi_ReplicationControllerDummy(in ReplicationControllerDummy, out *ReplicationControllerDummy, c *conversion.Cloner) error {
|
||||
if err := deepCopy_api_TypeMeta(in.TypeMeta, &out.TypeMeta, c); err != nil {
|
||||
return err
|
||||
@@ -110,6 +184,23 @@ func deepCopy_expapi_ScaleStatus(in ScaleStatus, out *ScaleStatus, c *conversion
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_expapi_SubresourceReference(in SubresourceReference, out *SubresourceReference, c *conversion.Cloner) error {
|
||||
out.Kind = in.Kind
|
||||
out.Namespace = in.Namespace
|
||||
out.Name = in.Name
|
||||
out.APIVersion = in.APIVersion
|
||||
out.Subresource = in.Subresource
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_expapi_TargetConsumption(in TargetConsumption, out *TargetConsumption, c *conversion.Cloner) error {
|
||||
out.Resource = in.Resource
|
||||
if err := deepCopy_resource_Quantity(in.Quantity, &out.Quantity, c); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_util_Time(in util.Time, out *util.Time, c *conversion.Cloner) error {
|
||||
if newVal, err := c.DeepCopy(in.Time); err != nil {
|
||||
return err
|
||||
@@ -121,12 +212,19 @@ func deepCopy_util_Time(in util.Time, out *util.Time, c *conversion.Cloner) erro
|
||||
|
||||
func init() {
|
||||
err := api.Scheme.AddGeneratedDeepCopyFuncs(
|
||||
deepCopy_api_ListMeta,
|
||||
deepCopy_api_ObjectMeta,
|
||||
deepCopy_api_TypeMeta,
|
||||
deepCopy_resource_Quantity,
|
||||
deepCopy_expapi_HorizontalPodAutoscaler,
|
||||
deepCopy_expapi_HorizontalPodAutoscalerList,
|
||||
deepCopy_expapi_HorizontalPodAutoscalerSpec,
|
||||
deepCopy_expapi_ReplicationControllerDummy,
|
||||
deepCopy_expapi_Scale,
|
||||
deepCopy_expapi_ScaleSpec,
|
||||
deepCopy_expapi_ScaleStatus,
|
||||
deepCopy_expapi_SubresourceReference,
|
||||
deepCopy_expapi_TargetConsumption,
|
||||
deepCopy_util_Time,
|
||||
)
|
||||
if err != nil {
|
||||
|
@@ -27,8 +27,15 @@ func init() {
|
||||
|
||||
// Adds the list of known types to api.Scheme.
|
||||
func addKnownTypes() {
|
||||
api.Scheme.AddKnownTypes("", &Scale{}, &ReplicationControllerDummy{})
|
||||
api.Scheme.AddKnownTypes("",
|
||||
&HorizontalPodAutoscaler{},
|
||||
&HorizontalPodAutoscalerList{},
|
||||
&ReplicationControllerDummy{},
|
||||
&Scale{},
|
||||
)
|
||||
}
|
||||
|
||||
func (*Scale) IsAnAPIObject() {}
|
||||
func (*ReplicationControllerDummy) IsAnAPIObject() {}
|
||||
func (*HorizontalPodAutoscaler) IsAnAPIObject() {}
|
||||
func (*HorizontalPodAutoscalerList) IsAnAPIObject() {}
|
||||
func (*ReplicationControllerDummy) IsAnAPIObject() {}
|
||||
func (*Scale) IsAnAPIObject() {}
|
||||
|
@@ -28,7 +28,10 @@ support is experimental.
|
||||
|
||||
package expapi
|
||||
|
||||
import "k8s.io/kubernetes/pkg/api"
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
)
|
||||
|
||||
// ScaleSpec describes the attributes a Scale subresource
|
||||
type ScaleSpec struct {
|
||||
@@ -61,3 +64,49 @@ type Scale struct {
|
||||
type ReplicationControllerDummy struct {
|
||||
api.TypeMeta `json:",inline"`
|
||||
}
|
||||
|
||||
// SubresourceReference contains enough information to let you inspect or modify the referred subresource.
|
||||
type SubresourceReference struct {
|
||||
Kind string `json:"kind,omitempty"`
|
||||
Namespace string `json:"namespace,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
APIVersion string `json:"apiVersion,omitempty"`
|
||||
Subresource string `json:"subresource,omitempty"`
|
||||
}
|
||||
|
||||
// TargetConsumption is an object for specifying target average resource consumption of a particular resource.
|
||||
type TargetConsumption struct {
|
||||
Resource api.ResourceName `json:"resource,omitempty"`
|
||||
Quantity resource.Quantity `json:"quantity,omitempty"`
|
||||
}
|
||||
|
||||
// HorizontalPodAutoscalerSpec is the specification of a horizontal pod autoscaler.
|
||||
type HorizontalPodAutoscalerSpec struct {
|
||||
// ScaleRef is a reference to Scale subresource. HorizontalPodAutoscaler will learn the current resource consumption from its status,
|
||||
// and will set the desired number of pods by modyfying its spec.
|
||||
ScaleRef *SubresourceReference `json:"scaleRef"`
|
||||
// MinCount is the lower limit for the number of pods that can be set by the autoscaler.
|
||||
MinCount int `json:"minCount"`
|
||||
// MaxCount is the upper limit for the number of pods that can be set by the autoscaler. It cannot be smaller than MinCount.
|
||||
MaxCount int `json:"maxCount"`
|
||||
// Target is the target average consumption of the given resource that the autoscaler will try to maintain by adjusting the desired number of pods.
|
||||
// Currently two types of resources are supported: "cpu" and "memory".
|
||||
Target TargetConsumption `json:"target"`
|
||||
}
|
||||
|
||||
// HorizontalPodAutoscaler represents the configuration of a horizontal pod autoscaler.
|
||||
type HorizontalPodAutoscaler struct {
|
||||
api.TypeMeta `json:",inline"`
|
||||
api.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
// Spec defines the behaviour of autoscaler.
|
||||
Spec HorizontalPodAutoscalerSpec `json:"spec,omitempty"`
|
||||
}
|
||||
|
||||
// HorizontalPodAutoscaler is a collection of pod autoscalers.
|
||||
type HorizontalPodAutoscalerList struct {
|
||||
api.TypeMeta `json:",inline"`
|
||||
api.ListMeta `json:"metadata,omitempty"`
|
||||
|
||||
Items []HorizontalPodAutoscaler `json:"items"`
|
||||
}
|
||||
|
@@ -21,11 +21,79 @@ import (
|
||||
time "time"
|
||||
|
||||
api "k8s.io/kubernetes/pkg/api"
|
||||
resource "k8s.io/kubernetes/pkg/api/resource"
|
||||
v1 "k8s.io/kubernetes/pkg/api/v1"
|
||||
conversion "k8s.io/kubernetes/pkg/conversion"
|
||||
util "k8s.io/kubernetes/pkg/util"
|
||||
inf "speter.net/go/exp/math/dec/inf"
|
||||
)
|
||||
|
||||
func deepCopy_api_ListMeta(in api.ListMeta, out *api.ListMeta, c *conversion.Cloner) error {
|
||||
out.SelfLink = in.SelfLink
|
||||
out.ResourceVersion = in.ResourceVersion
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_api_ObjectMeta(in api.ObjectMeta, out *api.ObjectMeta, c *conversion.Cloner) error {
|
||||
out.Name = in.Name
|
||||
out.GenerateName = in.GenerateName
|
||||
out.Namespace = in.Namespace
|
||||
out.SelfLink = in.SelfLink
|
||||
out.UID = in.UID
|
||||
out.ResourceVersion = in.ResourceVersion
|
||||
out.Generation = in.Generation
|
||||
if err := deepCopy_util_Time(in.CreationTimestamp, &out.CreationTimestamp, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if in.DeletionTimestamp != nil {
|
||||
out.DeletionTimestamp = new(util.Time)
|
||||
if err := deepCopy_util_Time(*in.DeletionTimestamp, out.DeletionTimestamp, c); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.DeletionTimestamp = nil
|
||||
}
|
||||
if in.Labels != nil {
|
||||
out.Labels = make(map[string]string)
|
||||
for key, val := range in.Labels {
|
||||
out.Labels[key] = val
|
||||
}
|
||||
} else {
|
||||
out.Labels = nil
|
||||
}
|
||||
if in.Annotations != nil {
|
||||
out.Annotations = make(map[string]string)
|
||||
for key, val := range in.Annotations {
|
||||
out.Annotations[key] = val
|
||||
}
|
||||
} else {
|
||||
out.Annotations = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_api_TypeMeta(in api.TypeMeta, out *api.TypeMeta, c *conversion.Cloner) error {
|
||||
out.Kind = in.Kind
|
||||
out.APIVersion = in.APIVersion
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_resource_Quantity(in resource.Quantity, out *resource.Quantity, c *conversion.Cloner) error {
|
||||
if in.Amount != nil {
|
||||
if newVal, err := c.DeepCopy(in.Amount); err != nil {
|
||||
return err
|
||||
} else if newVal == nil {
|
||||
out.Amount = nil
|
||||
} else {
|
||||
out.Amount = newVal.(*inf.Dec)
|
||||
}
|
||||
} else {
|
||||
out.Amount = nil
|
||||
}
|
||||
out.Format = in.Format
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_v1_ObjectMeta(in v1.ObjectMeta, out *v1.ObjectMeta, c *conversion.Cloner) error {
|
||||
out.Name = in.Name
|
||||
out.GenerateName = in.GenerateName
|
||||
@@ -70,6 +138,56 @@ func deepCopy_v1_TypeMeta(in v1.TypeMeta, out *v1.TypeMeta, c *conversion.Cloner
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_v1_HorizontalPodAutoscaler(in HorizontalPodAutoscaler, out *HorizontalPodAutoscaler, c *conversion.Cloner) error {
|
||||
if err := deepCopy_api_TypeMeta(in.TypeMeta, &out.TypeMeta, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deepCopy_api_ObjectMeta(in.ObjectMeta, &out.ObjectMeta, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deepCopy_v1_HorizontalPodAutoscalerSpec(in.Spec, &out.Spec, c); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_v1_HorizontalPodAutoscalerList(in HorizontalPodAutoscalerList, out *HorizontalPodAutoscalerList, c *conversion.Cloner) error {
|
||||
if err := deepCopy_api_TypeMeta(in.TypeMeta, &out.TypeMeta, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := deepCopy_api_ListMeta(in.ListMeta, &out.ListMeta, c); err != nil {
|
||||
return err
|
||||
}
|
||||
if in.Items != nil {
|
||||
out.Items = make([]HorizontalPodAutoscaler, len(in.Items))
|
||||
for i := range in.Items {
|
||||
if err := deepCopy_v1_HorizontalPodAutoscaler(in.Items[i], &out.Items[i], c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.Items = nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_v1_HorizontalPodAutoscalerSpec(in HorizontalPodAutoscalerSpec, out *HorizontalPodAutoscalerSpec, c *conversion.Cloner) error {
|
||||
if in.ScaleRef != nil {
|
||||
out.ScaleRef = new(SubresourceReference)
|
||||
if err := deepCopy_v1_SubresourceReference(*in.ScaleRef, out.ScaleRef, c); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
out.ScaleRef = nil
|
||||
}
|
||||
out.MinCount = in.MinCount
|
||||
out.MaxCount = in.MaxCount
|
||||
if err := deepCopy_v1_TargetConsumption(in.Target, &out.Target, c); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_v1_ReplicationControllerDummy(in ReplicationControllerDummy, out *ReplicationControllerDummy, c *conversion.Cloner) error {
|
||||
if err := deepCopy_v1_TypeMeta(in.TypeMeta, &out.TypeMeta, c); err != nil {
|
||||
return err
|
||||
@@ -111,6 +229,23 @@ func deepCopy_v1_ScaleStatus(in ScaleStatus, out *ScaleStatus, c *conversion.Clo
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_v1_SubresourceReference(in SubresourceReference, out *SubresourceReference, c *conversion.Cloner) error {
|
||||
out.Kind = in.Kind
|
||||
out.Namespace = in.Namespace
|
||||
out.Name = in.Name
|
||||
out.APIVersion = in.APIVersion
|
||||
out.Subresource = in.Subresource
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_v1_TargetConsumption(in TargetConsumption, out *TargetConsumption, c *conversion.Cloner) error {
|
||||
out.Resource = in.Resource
|
||||
if err := deepCopy_resource_Quantity(in.Quantity, &out.Quantity, c); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deepCopy_util_Time(in util.Time, out *util.Time, c *conversion.Cloner) error {
|
||||
if newVal, err := c.DeepCopy(in.Time); err != nil {
|
||||
return err
|
||||
@@ -122,12 +257,21 @@ func deepCopy_util_Time(in util.Time, out *util.Time, c *conversion.Cloner) erro
|
||||
|
||||
func init() {
|
||||
err := api.Scheme.AddGeneratedDeepCopyFuncs(
|
||||
deepCopy_api_ListMeta,
|
||||
deepCopy_api_ObjectMeta,
|
||||
deepCopy_api_TypeMeta,
|
||||
deepCopy_resource_Quantity,
|
||||
deepCopy_v1_ObjectMeta,
|
||||
deepCopy_v1_TypeMeta,
|
||||
deepCopy_v1_HorizontalPodAutoscaler,
|
||||
deepCopy_v1_HorizontalPodAutoscalerList,
|
||||
deepCopy_v1_HorizontalPodAutoscalerSpec,
|
||||
deepCopy_v1_ReplicationControllerDummy,
|
||||
deepCopy_v1_Scale,
|
||||
deepCopy_v1_ScaleSpec,
|
||||
deepCopy_v1_ScaleStatus,
|
||||
deepCopy_v1_SubresourceReference,
|
||||
deepCopy_v1_TargetConsumption,
|
||||
deepCopy_util_Time,
|
||||
)
|
||||
if err != nil {
|
||||
|
@@ -24,15 +24,22 @@ import (
|
||||
var Codec = runtime.CodecFor(api.Scheme, "v1")
|
||||
|
||||
func init() {
|
||||
addConversionFuncs()
|
||||
addDefaultingFuncs()
|
||||
addKnownTypes()
|
||||
addDefaultingFuncs()
|
||||
addConversionFuncs()
|
||||
}
|
||||
|
||||
// Adds the list of known types to api.Scheme.
|
||||
func addKnownTypes() {
|
||||
api.Scheme.AddKnownTypes("v1", &Scale{}, &ReplicationControllerDummy{})
|
||||
api.Scheme.AddKnownTypes("v1",
|
||||
&HorizontalPodAutoscaler{},
|
||||
&HorizontalPodAutoscalerList{},
|
||||
&ReplicationControllerDummy{},
|
||||
&Scale{},
|
||||
)
|
||||
}
|
||||
|
||||
func (*Scale) IsAnAPIObject() {}
|
||||
func (*ReplicationControllerDummy) IsAnAPIObject() {}
|
||||
func (*HorizontalPodAutoscaler) IsAnAPIObject() {}
|
||||
func (*HorizontalPodAutoscalerList) IsAnAPIObject() {}
|
||||
func (*ReplicationControllerDummy) IsAnAPIObject() {}
|
||||
func (*Scale) IsAnAPIObject() {}
|
||||
|
@@ -16,7 +16,11 @@ limitations under the License.
|
||||
|
||||
package v1
|
||||
|
||||
import "k8s.io/kubernetes/pkg/api/v1"
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/api/v1"
|
||||
)
|
||||
|
||||
// ScaleSpec describes the attributes a Scale subresource
|
||||
type ScaleSpec struct {
|
||||
@@ -49,3 +53,49 @@ type Scale struct {
|
||||
type ReplicationControllerDummy struct {
|
||||
v1.TypeMeta `json:",inline"`
|
||||
}
|
||||
|
||||
// SubresourceReference contains enough information to let you inspect or modify the referred subresource.
|
||||
type SubresourceReference struct {
|
||||
Kind string `json:"kind,omitempty" description:"kind of the referent; see http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds"`
|
||||
Namespace string `json:"namespace,omitempty" description:"namespace of the referent; see http://releases.k8s.io/HEAD/docs/user-guide/namespaces.md"`
|
||||
Name string `json:"name,omitempty" description:"name of the referent; see http://releases.k8s.io/HEAD/docs/user-guide/identifiers.md#names"`
|
||||
APIVersion string `json:"apiVersion,omitempty" description:"API version of the referent"`
|
||||
Subresource string `json:"subresource,omitempty" decription:"subresource name of the referent"`
|
||||
}
|
||||
|
||||
// TargetConsumption is an object for specifying target average resource consumption of a particular resource.
|
||||
type TargetConsumption struct {
|
||||
Resource api.ResourceName `json:"resource,omitempty"`
|
||||
Quantity resource.Quantity `json:"quantity,omitempty"`
|
||||
}
|
||||
|
||||
// HorizontalPodAutoscalerSpec is the specification of a horizontal pod autoscaler.
|
||||
type HorizontalPodAutoscalerSpec struct {
|
||||
// ScaleRef is a reference to Scale subresource. HorizontalPodAutoscaler will learn the current resource consumption from its status,
|
||||
// and will set the desired number of pods by modyfying its spec.
|
||||
ScaleRef *SubresourceReference `json:"scaleRef" description:"reference to scale subresource for quering the current resource cosumption and for setting the desired number of pods"`
|
||||
// MinCount is the lower limit for the number of pods that can be set by the autoscaler.
|
||||
MinCount int `json:"minCount" description:"lower limit for the number of pods"`
|
||||
// MaxCount is the upper limit for the number of pods that can be set by the autoscaler. It cannot be smaller than MinCount.
|
||||
MaxCount int `json:"maxCount" description:"upper limit for the number of pods"`
|
||||
// Target is the target average consumption of the given resource that the autoscaler will try to maintain by adjusting the desired number of pods.
|
||||
// Currently two types of resources are supported: "cpu" and "memory".
|
||||
Target TargetConsumption `json:"target" description:"target average consumption of resource that the autoscaler will try to maintain by adjusting the desired number of pods"`
|
||||
}
|
||||
|
||||
// HorizontalPodAutoscaler represents the configuration of a horizontal pod autoscaler.
|
||||
type HorizontalPodAutoscaler struct {
|
||||
api.TypeMeta `json:",inline"`
|
||||
api.ObjectMeta `json:"metadata,omitempty"`
|
||||
|
||||
// Spec defines the behaviour of autoscaler.
|
||||
Spec HorizontalPodAutoscalerSpec `json:"spec,omitempty" description:"specification of the desired behavior of the autoscaler; http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status"`
|
||||
}
|
||||
|
||||
// HorizontalPodAutoscaler is a collection of pod autoscalers.
|
||||
type HorizontalPodAutoscalerList struct {
|
||||
api.TypeMeta `json:",inline"`
|
||||
api.ListMeta `json:"metadata,omitempty"`
|
||||
|
||||
Items []HorizontalPodAutoscaler `json:"items" description:"list of horizontal pod autoscalers"`
|
||||
}
|
||||
|
67
pkg/expapi/validation/validation.go
Normal file
67
pkg/expapi/validation/validation.go
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 validation
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
apivalidation "k8s.io/kubernetes/pkg/api/validation"
|
||||
"k8s.io/kubernetes/pkg/expapi"
|
||||
errs "k8s.io/kubernetes/pkg/util/fielderrors"
|
||||
)
|
||||
|
||||
// ValidateHorizontalPodAutoscaler can be used to check whether the given autoscaler name is valid.
|
||||
// Prefix indicates this name will be used as part of generation, in which case trailing dashes are allowed.
|
||||
func ValidateHorizontalPodAutoscalerName(name string, prefix bool) (bool, string) {
|
||||
// TODO: finally move it to pkg/api/validation and use nameIsDNSSubdomain function
|
||||
return apivalidation.ValidateReplicationControllerName(name, prefix)
|
||||
}
|
||||
|
||||
func validateHorizontalPodAutoscalerSpec(autoscaler expapi.HorizontalPodAutoscalerSpec) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
if autoscaler.MinCount < 0 {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("minCount", autoscaler.MinCount, `must be non-negative`))
|
||||
}
|
||||
if autoscaler.MaxCount < autoscaler.MinCount {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("maxCount", autoscaler.MaxCount, `must be bigger or equal to minCount`))
|
||||
}
|
||||
if autoscaler.ScaleRef == nil {
|
||||
allErrs = append(allErrs, errs.NewFieldRequired("scaleRef"))
|
||||
}
|
||||
resource := autoscaler.Target.Resource.String()
|
||||
if resource != string(api.ResourceMemory) && resource != string(api.ResourceCPU) {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("target.resource", resource, "resource not supported by autoscaler"))
|
||||
}
|
||||
quantity := autoscaler.Target.Quantity.Value()
|
||||
if quantity < 0 {
|
||||
allErrs = append(allErrs, errs.NewFieldInvalid("target.quantity", quantity, "must be non-negative"))
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidateHorizontalPodAutoscaler(autoscaler *expapi.HorizontalPodAutoscaler) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&autoscaler.ObjectMeta, true, ValidateHorizontalPodAutoscalerName).Prefix("metadata")...)
|
||||
allErrs = append(allErrs, validateHorizontalPodAutoscalerSpec(autoscaler.Spec)...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func ValidateHorizontalPodAutoscalerUpdate(newAutoscler, oldAutoscaler *expapi.HorizontalPodAutoscaler) errs.ValidationErrorList {
|
||||
allErrs := errs.ValidationErrorList{}
|
||||
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&newAutoscler.ObjectMeta, &oldAutoscaler.ObjectMeta).Prefix("metadata")...)
|
||||
allErrs = append(allErrs, validateHorizontalPodAutoscalerSpec(newAutoscler.Spec)...)
|
||||
return allErrs
|
||||
}
|
129
pkg/expapi/validation/validation_test.go
Normal file
129
pkg/expapi/validation/validation_test.go
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
Copyright 2014 The Kubernetes Authors All rights reserved.
|
||||
|
||||
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 validation
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/resource"
|
||||
"k8s.io/kubernetes/pkg/expapi"
|
||||
)
|
||||
|
||||
func TestValidateHorizontalPodAutoscaler(t *testing.T) {
|
||||
successCases := []expapi.HorizontalPodAutoscaler{
|
||||
{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: expapi.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: &expapi.SubresourceReference{
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinCount: 1,
|
||||
MaxCount: 5,
|
||||
Target: expapi.TargetConsumption{api.ResourceCPU, resource.MustParse("0.8")},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, successCase := range successCases {
|
||||
if errs := ValidateHorizontalPodAutoscaler(&successCase); len(errs) != 0 {
|
||||
t.Errorf("expected success: %v", errs)
|
||||
}
|
||||
}
|
||||
|
||||
errorCases := map[string]expapi.HorizontalPodAutoscaler{
|
||||
"must be non-negative": {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: expapi.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: &expapi.SubresourceReference{
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinCount: -1,
|
||||
MaxCount: 5,
|
||||
Target: expapi.TargetConsumption{api.ResourceCPU, resource.MustParse("0.8")},
|
||||
},
|
||||
},
|
||||
"must be bigger or equal to minCount": {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: expapi.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: &expapi.SubresourceReference{
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinCount: 7,
|
||||
MaxCount: 5,
|
||||
Target: expapi.TargetConsumption{api.ResourceCPU, resource.MustParse("0.8")},
|
||||
},
|
||||
},
|
||||
"invalid value": {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: expapi.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: &expapi.SubresourceReference{
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinCount: 1,
|
||||
MaxCount: 5,
|
||||
Target: expapi.TargetConsumption{api.ResourceCPU, resource.MustParse("-0.8")},
|
||||
},
|
||||
},
|
||||
"resource not supported": {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: expapi.HorizontalPodAutoscalerSpec{
|
||||
ScaleRef: &expapi.SubresourceReference{
|
||||
Subresource: "scale",
|
||||
},
|
||||
MinCount: 1,
|
||||
MaxCount: 5,
|
||||
Target: expapi.TargetConsumption{api.ResourceName("NotSupportedResource"), resource.MustParse("0.8")},
|
||||
},
|
||||
},
|
||||
"required value": {
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "myautoscaler",
|
||||
Namespace: api.NamespaceDefault,
|
||||
},
|
||||
Spec: expapi.HorizontalPodAutoscalerSpec{
|
||||
MinCount: 1,
|
||||
MaxCount: 5,
|
||||
Target: expapi.TargetConsumption{api.ResourceCPU, resource.MustParse("0.8")},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for k, v := range errorCases {
|
||||
errs := ValidateHorizontalPodAutoscaler(&v)
|
||||
if len(errs) == 0 {
|
||||
t.Errorf("expected failure for %s", k)
|
||||
} else if !strings.Contains(errs[0].Error(), k) {
|
||||
t.Errorf("unexpected error: %v, expected: %s", errs[0], k)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user