Skip to content

Commit

Permalink
Removed HPA objects from extensions api group
Browse files Browse the repository at this point in the history
  • Loading branch information
piosz committed Feb 2, 2017
1 parent 4ecd52b commit a35ad8f
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 315 deletions.
3 changes: 0 additions & 3 deletions cmd/kube-apiserver/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ import (
"k8s.io/apiserver/pkg/server/filters"
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/batch"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/capabilities"
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/cloudprovider"
Expand Down Expand Up @@ -202,7 +200,6 @@ func Run(s *options.ServerRunOptions) error {
if err != nil {
return fmt.Errorf("error in initializing storage factory: %s", err)
}
storageFactory.AddCohabitatingResources(autoscaling.Resource("horizontalpodautoscalers"), extensions.Resource("horizontalpodautoscalers"))
for _, override := range s.Etcd.EtcdServersOverrides {
tokens := strings.Split(override, "#")
if len(tokens) != 2 {
Expand Down
14 changes: 2 additions & 12 deletions hack/make-rules/test-cmd-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1015,12 +1015,10 @@ run_save_config_tests() {
# Command: autoscale rc "frontend"
kubectl autoscale -f hack/testdata/frontend-controller.yaml --save-config "${kube_flags[@]}" --max=2
# Post-Condition: hpa "frontend" has configuration annotation
[[ "$(kubectl get hpa.v1beta1.extensions frontend -o yaml "${kube_flags[@]}" | grep kubectl.kubernetes.io/last-applied-configuration)" ]]
# Ensure we can interact with HPA objects in lists through both the extensions/v1beta1 and autoscaling/v1 APIs
[[ "$(kubectl get hpa frontend -o yaml "${kube_flags[@]}" | grep kubectl.kubernetes.io/last-applied-configuration)" ]]
# Ensure we can interact with HPA objects in lists through autoscaling/v1 APIs
output_message=$(kubectl get hpa -o=jsonpath='{.items[0].apiVersion}' 2>&1 "${kube_flags[@]}")
kube::test::if_has_string "${output_message}" 'autoscaling/v1'
output_message=$(kubectl get hpa.extensions -o=jsonpath='{.items[0].apiVersion}' 2>&1 "${kube_flags[@]}")
kube::test::if_has_string "${output_message}" 'extensions/v1beta1'
output_message=$(kubectl get hpa.autoscaling -o=jsonpath='{.items[0].apiVersion}' 2>&1 "${kube_flags[@]}")
kube::test::if_has_string "${output_message}" 'autoscaling/v1'
# tests kubectl group prefix matching
Expand Down Expand Up @@ -2111,18 +2109,10 @@ run_rc_tests() {
kubectl autoscale -f hack/testdata/frontend-controller.yaml "${kube_flags[@]}" --max=2 --cpu-percent=70
kube::test::get_object_assert 'hpa frontend' "{{$hpa_min_field}} {{$hpa_max_field}} {{$hpa_cpu_field}}" '1 2 70'
kubectl delete hpa frontend "${kube_flags[@]}"
# autoscale 1~2 pods, CPU utilization 70%, rc specified by file, using old generator
kubectl autoscale -f hack/testdata/frontend-controller.yaml "${kube_flags[@]}" --max=2 --cpu-percent=70 --generator=horizontalpodautoscaler/v1beta1
kube::test::get_object_assert 'hpa frontend' "{{$hpa_min_field}} {{$hpa_max_field}} {{$hpa_cpu_field}}" '1 2 70'
kubectl delete hpa frontend "${kube_flags[@]}"
# autoscale 2~3 pods, no CPU utilization specified, rc specified by name
kubectl autoscale rc frontend "${kube_flags[@]}" --min=2 --max=3
kube::test::get_object_assert 'hpa frontend' "{{$hpa_min_field}} {{$hpa_max_field}} {{$hpa_cpu_field}}" '2 3 <no value>'
kubectl delete hpa frontend "${kube_flags[@]}"
# autoscale 2~3 pods, no CPU utilization specified, rc specified by name, using old generator
kubectl autoscale rc frontend "${kube_flags[@]}" --min=2 --max=3 --generator=horizontalpodautoscaler/v1beta1
kube::test::get_object_assert 'hpa frontend' "{{$hpa_min_field}} {{$hpa_max_field}} {{$hpa_cpu_field}}" '2 3 <no value>'
kubectl delete hpa frontend "${kube_flags[@]}"
# autoscale without specifying --max should fail
! kubectl autoscale rc frontend "${kube_flags[@]}"
# Clean up
Expand Down
11 changes: 6 additions & 5 deletions hack/test-update-storage-objects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,17 @@ echo "${ETCD_VERSION}/${STORAGE_BACKEND_ETCD2}" > "${ETCD_DIR}/version.txt"

### BEGIN TEST DEFINITION CUSTOMIZATION ###

# After removing HPA in v1beta1 there is basically no resource which has
# two versions. In the future we may want to extend it.
# source_file,resource,namespace,name,old_version,new_version
tests=(
test/fixtures/doc-yaml/user-guide/horizontal-pod-autoscaling/hpa-php-apache.yaml,horizontalpodautoscalers,default,php-apache,extensions/v1beta1,autoscaling/v1
test/fixtures/doc-yaml/user-guide/pod.yaml,pods,default,nginx,v1,v1
)

# need to include extensions/v1beta1 in new api version because its internal types are used by hpas
KUBE_OLD_API_VERSION="v1,extensions/v1beta1"
KUBE_NEW_API_VERSION="v1,extensions/v1beta1,autoscaling/v1"
KUBE_OLD_STORAGE_VERSIONS="autoscaling=extensions/v1beta1"
KUBE_NEW_STORAGE_VERSIONS="autoscaling/v1"
KUBE_NEW_API_VERSION="v1,extensions/v1beta1"
KUBE_OLD_STORAGE_VERSIONS="v1"
KUBE_NEW_STORAGE_VERSIONS="v1"

### END TEST DEFINITION CUSTOMIZATION ###

Expand Down
2 changes: 0 additions & 2 deletions pkg/api/defaulting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ func TestDefaulting(t *testing.T) {
{Group: "extensions", Version: "v1beta1", Kind: "DaemonSetList"}: {},
{Group: "extensions", Version: "v1beta1", Kind: "Deployment"}: {},
{Group: "extensions", Version: "v1beta1", Kind: "DeploymentList"}: {},
{Group: "extensions", Version: "v1beta1", Kind: "HorizontalPodAutoscaler"}: {},
{Group: "extensions", Version: "v1beta1", Kind: "HorizontalPodAutoscalerList"}: {},
{Group: "extensions", Version: "v1beta1", Kind: "ReplicaSet"}: {},
{Group: "extensions", Version: "v1beta1", Kind: "ReplicaSetList"}: {},
{Group: "rbac.authorization.k8s.io", Version: "v1alpha1", Kind: "ClusterRoleBinding"}: {},
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/extensions/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package extensions
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/apis/autoscaling"
)

// GroupName is the group name use in this package
Expand Down Expand Up @@ -50,8 +49,6 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&Deployment{},
&DeploymentList{},
&DeploymentRollback{},
&autoscaling.HorizontalPodAutoscaler{},
&autoscaling.HorizontalPodAutoscalerList{},
&ReplicationControllerDummy{},
&Scale{},
&ThirdPartyResource{},
Expand Down
56 changes: 0 additions & 56 deletions pkg/apis/extensions/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/kubernetes/pkg/api"
v1 "k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/extensions"
)

Expand All @@ -42,11 +41,6 @@ func addConversionFuncs(scheme *runtime.Scheme) error {
Convert_v1beta1_RollingUpdateDeployment_To_extensions_RollingUpdateDeployment,
Convert_extensions_ReplicaSetSpec_To_v1beta1_ReplicaSetSpec,
Convert_v1beta1_ReplicaSetSpec_To_extensions_ReplicaSetSpec,
// autoscaling
Convert_autoscaling_CrossVersionObjectReference_To_v1beta1_SubresourceReference,
Convert_v1beta1_SubresourceReference_To_autoscaling_CrossVersionObjectReference,
Convert_autoscaling_HorizontalPodAutoscalerSpec_To_v1beta1_HorizontalPodAutoscalerSpec,
Convert_v1beta1_HorizontalPodAutoscalerSpec_To_autoscaling_HorizontalPodAutoscalerSpec,
)
if err != nil {
return err
Expand Down Expand Up @@ -248,53 +242,3 @@ func Convert_v1beta1_ReplicaSetSpec_To_extensions_ReplicaSetSpec(in *ReplicaSetS
}
return nil
}

func Convert_autoscaling_CrossVersionObjectReference_To_v1beta1_SubresourceReference(in *autoscaling.CrossVersionObjectReference, out *SubresourceReference, s conversion.Scope) error {
out.Kind = in.Kind
out.Name = in.Name
out.APIVersion = in.APIVersion
out.Subresource = "scale"
return nil
}

func Convert_v1beta1_SubresourceReference_To_autoscaling_CrossVersionObjectReference(in *SubresourceReference, out *autoscaling.CrossVersionObjectReference, s conversion.Scope) error {
out.Kind = in.Kind
out.Name = in.Name
out.APIVersion = in.APIVersion
return nil
}

func Convert_autoscaling_HorizontalPodAutoscalerSpec_To_v1beta1_HorizontalPodAutoscalerSpec(in *autoscaling.HorizontalPodAutoscalerSpec, out *HorizontalPodAutoscalerSpec, s conversion.Scope) error {
if err := Convert_autoscaling_CrossVersionObjectReference_To_v1beta1_SubresourceReference(&in.ScaleTargetRef, &out.ScaleRef, s); err != nil {
return err
}
if in.MinReplicas != nil {
out.MinReplicas = new(int32)
*out.MinReplicas = *in.MinReplicas
} else {
out.MinReplicas = nil
}
out.MaxReplicas = in.MaxReplicas
if in.TargetCPUUtilizationPercentage != nil {
out.CPUUtilization = &CPUTargetUtilization{TargetPercentage: *in.TargetCPUUtilizationPercentage}
}
return nil
}

func Convert_v1beta1_HorizontalPodAutoscalerSpec_To_autoscaling_HorizontalPodAutoscalerSpec(in *HorizontalPodAutoscalerSpec, out *autoscaling.HorizontalPodAutoscalerSpec, s conversion.Scope) error {
if err := Convert_v1beta1_SubresourceReference_To_autoscaling_CrossVersionObjectReference(&in.ScaleRef, &out.ScaleTargetRef, s); err != nil {
return err
}
if in.MinReplicas != nil {
out.MinReplicas = new(int32)
*out.MinReplicas = int32(*in.MinReplicas)
} else {
out.MinReplicas = nil
}
out.MaxReplicas = int32(in.MaxReplicas)
if in.CPUUtilization != nil {
out.TargetCPUUtilizationPercentage = new(int32)
*out.TargetCPUUtilizationPercentage = int32(in.CPUUtilization.TargetPercentage)
}
return nil
}
11 changes: 0 additions & 11 deletions pkg/apis/extensions/v1beta1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
return scheme.AddDefaultingFuncs(
SetDefaults_DaemonSet,
SetDefaults_Deployment,
SetDefaults_HorizontalPodAutoscaler,
SetDefaults_ReplicaSet,
SetDefaults_NetworkPolicy,
)
Expand Down Expand Up @@ -90,16 +89,6 @@ func SetDefaults_Deployment(obj *Deployment) {
}
}

func SetDefaults_HorizontalPodAutoscaler(obj *HorizontalPodAutoscaler) {
if obj.Spec.MinReplicas == nil {
minReplicas := int32(1)
obj.Spec.MinReplicas = &minReplicas
}
if obj.Spec.CPUUtilization == nil {
obj.Spec.CPUUtilization = &CPUTargetUtilization{TargetPercentage: 80}
}
}

func SetDefaults_ReplicaSet(obj *ReplicaSet) {
labels := obj.Spec.Template.Labels

Expand Down
72 changes: 0 additions & 72 deletions pkg/apis/extensions/v1beta1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,78 +499,6 @@ func TestDefaultRequestIsNotSetForReplicaSet(t *testing.T) {
}
}

func TestSetDefaultHorizontalPodAutoscalerMinReplicas(t *testing.T) {
tests := []struct {
hpa HorizontalPodAutoscaler
expectReplicas int32
}{
{
hpa: HorizontalPodAutoscaler{},
expectReplicas: 1,
},
{
hpa: HorizontalPodAutoscaler{
Spec: HorizontalPodAutoscalerSpec{
MinReplicas: newInt32(3),
},
},
expectReplicas: 3,
},
}

for _, test := range tests {
hpa := &test.hpa
obj2 := roundTrip(t, runtime.Object(hpa))
hpa2, ok := obj2.(*HorizontalPodAutoscaler)
if !ok {
t.Errorf("unexpected object: %v", hpa2)
t.FailNow()
}
if hpa2.Spec.MinReplicas == nil {
t.Errorf("unexpected nil MinReplicas")
} else if test.expectReplicas != *hpa2.Spec.MinReplicas {
t.Errorf("expected: %d MinReplicas, got: %d", test.expectReplicas, *hpa2.Spec.MinReplicas)
}
}
}

func TestSetDefaultHorizontalPodAutoscalerCpuUtilization(t *testing.T) {
tests := []struct {
hpa HorizontalPodAutoscaler
expectUtilization int32
}{
{
hpa: HorizontalPodAutoscaler{},
expectUtilization: 80,
},
{
hpa: HorizontalPodAutoscaler{
Spec: HorizontalPodAutoscalerSpec{
CPUUtilization: &CPUTargetUtilization{
TargetPercentage: int32(50),
},
},
},
expectUtilization: 50,
},
}

for _, test := range tests {
hpa := &test.hpa
obj2 := roundTrip(t, runtime.Object(hpa))
hpa2, ok := obj2.(*HorizontalPodAutoscaler)
if !ok {
t.Errorf("unexpected object: %v", hpa2)
t.FailNow()
}
if hpa2.Spec.CPUUtilization == nil {
t.Errorf("unexpected nil CPUUtilization")
} else if test.expectUtilization != hpa2.Spec.CPUUtilization.TargetPercentage {
t.Errorf("expected: %d CPUUtilization, got: %d", test.expectUtilization, hpa2.Spec.CPUUtilization.TargetPercentage)
}
}
}

func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
data, err := runtime.Encode(api.Codecs.LegacyCodec(SchemeGroupVersion), obj)
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions pkg/apis/extensions/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&Deployment{},
&DeploymentList{},
&DeploymentRollback{},
&HorizontalPodAutoscaler{},
&HorizontalPodAutoscalerList{},
&ReplicationControllerDummy{},
&Scale{},
&ThirdPartyResource{},
Expand Down
88 changes: 0 additions & 88 deletions pkg/apis/extensions/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,6 @@ type ReplicationControllerDummy struct {
metav1.TypeMeta `json:",inline"`
}

// SubresourceReference contains enough information to let you inspect or modify the referred subresource.
type SubresourceReference struct {
// Kind of the referent; More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#types-kinds
// +optional
Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"`
// Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
// +optional
Name string `json:"name,omitempty" protobuf:"bytes,2,opt,name=name"`
// API version of the referent
// +optional
APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,3,opt,name=apiVersion"`
// Subresource name of the referent
// +optional
Subresource string `json:"subresource,omitempty" protobuf:"bytes,4,opt,name=subresource"`
}

type CPUTargetUtilization struct {
// fraction of the requested CPU that should be utilized/used,
// e.g. 70 means that 70% of the requested CPU should be in use.
TargetPercentage int32 `json:"targetPercentage" protobuf:"varint,1,opt,name=targetPercentage"`
}

// Alpha-level support for Custom Metrics in HPA (as annotations).
type CustomMetricTarget struct {
// Custom Metric name.
Expand All @@ -118,72 +96,6 @@ type CustomMetricCurrentStatusList struct {
Items []CustomMetricCurrentStatus `json:"items" protobuf:"bytes,1,rep,name=items"`
}

// specification of a horizontal pod autoscaler.
type HorizontalPodAutoscalerSpec struct {
// reference to Scale subresource; horizontal pod autoscaler will learn the current resource consumption from its status,
// and will set the desired number of pods by modifying its spec.
ScaleRef SubresourceReference `json:"scaleRef" protobuf:"bytes,1,opt,name=scaleRef"`
// lower limit for the number of pods that can be set by the autoscaler, default 1.
// +optional
MinReplicas *int32 `json:"minReplicas,omitempty" protobuf:"varint,2,opt,name=minReplicas"`
// upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.
MaxReplicas int32 `json:"maxReplicas" protobuf:"varint,3,opt,name=maxReplicas"`
// target average CPU utilization (represented as a percentage of requested CPU) over all the pods;
// if not specified it defaults to the target CPU utilization at 80% of the requested resources.
// +optional
CPUUtilization *CPUTargetUtilization `json:"cpuUtilization,omitempty" protobuf:"bytes,4,opt,name=cpuUtilization"`
}

// current status of a horizontal pod autoscaler
type HorizontalPodAutoscalerStatus struct {
// most recent generation observed by this autoscaler.
// +optional
ObservedGeneration *int64 `json:"observedGeneration,omitempty" protobuf:"varint,1,opt,name=observedGeneration"`

// last time the HorizontalPodAutoscaler scaled the number of pods;
// used by the autoscaler to control how often the number of pods is changed.
// +optional
LastScaleTime *metav1.Time `json:"lastScaleTime,omitempty" protobuf:"bytes,2,opt,name=lastScaleTime"`

// current number of replicas of pods managed by this autoscaler.
CurrentReplicas int32 `json:"currentReplicas" protobuf:"varint,3,opt,name=currentReplicas"`

// desired number of replicas of pods managed by this autoscaler.
DesiredReplicas int32 `json:"desiredReplicas" protobuf:"varint,4,opt,name=desiredReplicas"`

// current average CPU utilization over all pods, represented as a percentage of requested CPU,
// e.g. 70 means that an average pod is using now 70% of its requested CPU.
// +optional
CurrentCPUUtilizationPercentage *int32 `json:"currentCPUUtilizationPercentage,omitempty" protobuf:"varint,5,opt,name=currentCPUUtilizationPercentage"`
}

// configuration of a horizontal pod autoscaler.
type HorizontalPodAutoscaler struct {
metav1.TypeMeta `json:",inline"`
// Standard object metadata. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
// +optional
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// behaviour of autoscaler. More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status.
// +optional
Spec HorizontalPodAutoscalerSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`

// current information about the autoscaler.
// +optional
Status HorizontalPodAutoscalerStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

// list of horizontal pod autoscaler objects.
type HorizontalPodAutoscalerList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata.
// +optional
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// list of horizontal pod autoscaler objects.
Items []HorizontalPodAutoscaler `json:"items" protobuf:"bytes,2,rep,name=items"`
}

// +genclient=true
// +nonNamespaced=true

Expand Down
Loading

0 comments on commit a35ad8f

Please sign in to comment.