From dfc62b56ccc71ab8d49b7b7c0cebb2881f777b3e Mon Sep 17 00:00:00 2001 From: "Madhusudan.C.S" Date: Thu, 10 Mar 2016 10:45:23 -0800 Subject: [PATCH] Enable kubectl autoscale for replica sets. Also add some tests for it. --- hack/test-cmd.sh | 20 ++++++++++++++++++++ pkg/kubectl/cmd/util/factory.go | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/hack/test-cmd.sh b/hack/test-cmd.sh index f31c28bc560..6c399bca62e 100755 --- a/hack/test-cmd.sh +++ b/hack/test-cmd.sh @@ -1360,6 +1360,26 @@ __EOF__ # Post-condition: no replica set exists kube::test::get_object_assert rs "{{range.items}}{{$id_field}}:{{end}}" '' + ### Auto scale replica set + # Pre-condition: no replica set exists + kube::test::get_object_assert rs "{{range.items}}{{$id_field}}:{{end}}" '' + # Command + kubectl create -f hack/testdata/frontend-replicaset.yaml "${kube_flags[@]}" + kube::test::get_object_assert rs "{{range.items}}{{$id_field}}:{{end}}" 'frontend:' + # autoscale 1~2 pods, CPU utilization 70%, replica set specified by file + kubectl autoscale -f hack/testdata/frontend-replicaset.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 2~3 pods, default CPU utilization (80%), replica set specified by name + kubectl autoscale rs 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 80' + kubectl delete hpa frontend "${kube_flags[@]}" + # autoscale without specifying --max should fail + ! kubectl autoscale rs frontend "${kube_flags[@]}" + # Clean up + kubectl delete rs frontend "${kube_flags[@]}" + + ###################### # Multiple Resources # ###################### diff --git a/pkg/kubectl/cmd/util/factory.go b/pkg/kubectl/cmd/util/factory.go index 326697ce0fa..78b2503b40b 100644 --- a/pkg/kubectl/cmd/util/factory.go +++ b/pkg/kubectl/cmd/util/factory.go @@ -550,7 +550,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory { }, CanBeAutoscaled: func(kind unversioned.GroupKind) error { switch kind { - case api.Kind("ReplicationController"), extensions.Kind("Deployment"): + case api.Kind("ReplicationController"), extensions.Kind("Deployment"), extensions.Kind("ReplicaSet"): // nothing to do here default: return fmt.Errorf("cannot autoscale a %v", kind)