mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Enable kubectl autoscale for replica sets.
Also add some tests for it.
This commit is contained in:
parent
c9b3b007cd
commit
dfc62b56cc
@ -1360,6 +1360,26 @@ __EOF__
|
|||||||
# Post-condition: no replica set exists
|
# Post-condition: no replica set exists
|
||||||
kube::test::get_object_assert rs "{{range.items}}{{$id_field}}:{{end}}" ''
|
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 #
|
# Multiple Resources #
|
||||||
######################
|
######################
|
||||||
|
@ -550,7 +550,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
|
|||||||
},
|
},
|
||||||
CanBeAutoscaled: func(kind unversioned.GroupKind) error {
|
CanBeAutoscaled: func(kind unversioned.GroupKind) error {
|
||||||
switch kind {
|
switch kind {
|
||||||
case api.Kind("ReplicationController"), extensions.Kind("Deployment"):
|
case api.Kind("ReplicationController"), extensions.Kind("Deployment"), extensions.Kind("ReplicaSet"):
|
||||||
// nothing to do here
|
// nothing to do here
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("cannot autoscale a %v", kind)
|
return fmt.Errorf("cannot autoscale a %v", kind)
|
||||||
|
Loading…
Reference in New Issue
Block a user