mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
Revert "kubectl: Make scaling smarter"
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
@@ -82,6 +83,30 @@ func ReaperForReplicationController(c client.Interface, timeout time.Duration) (
|
||||
return &ReplicationControllerReaper{c, Interval, timeout}, nil
|
||||
}
|
||||
|
||||
type ReplicationControllerReaper struct {
|
||||
client.Interface
|
||||
pollInterval, timeout time.Duration
|
||||
}
|
||||
type DaemonSetReaper struct {
|
||||
client.Interface
|
||||
pollInterval, timeout time.Duration
|
||||
}
|
||||
type JobReaper struct {
|
||||
client.Interface
|
||||
pollInterval, timeout time.Duration
|
||||
}
|
||||
type PodReaper struct {
|
||||
client.Interface
|
||||
}
|
||||
type ServiceReaper struct {
|
||||
client.Interface
|
||||
}
|
||||
|
||||
type objInterface interface {
|
||||
Delete(name string) error
|
||||
Get(name string) (meta.Object, error)
|
||||
}
|
||||
|
||||
// getOverlappingControllers finds rcs that this controller overlaps, as well as rcs overlapping this controller.
|
||||
func getOverlappingControllers(c client.ReplicationControllerInterface, rc *api.ReplicationController) ([]api.ReplicationController, error) {
|
||||
rcs, err := c.List(api.ListOptions{})
|
||||
@@ -99,11 +124,6 @@ func getOverlappingControllers(c client.ReplicationControllerInterface, rc *api.
|
||||
return matchingRCs, nil
|
||||
}
|
||||
|
||||
type ReplicationControllerReaper struct {
|
||||
client.Interface
|
||||
pollInterval, timeout time.Duration
|
||||
}
|
||||
|
||||
func (reaper *ReplicationControllerReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) error {
|
||||
rc := reaper.ReplicationControllers(namespace)
|
||||
scaler, err := ScalerFor(api.Kind("ReplicationController"), *reaper)
|
||||
@@ -161,9 +181,7 @@ func (reaper *ReplicationControllerReaper) Stop(namespace, name string, timeout
|
||||
retry := NewRetryParams(reaper.pollInterval, reaper.timeout)
|
||||
waitForReplicas := NewRetryParams(reaper.pollInterval, timeout)
|
||||
if err = scaler.Scale(namespace, name, 0, nil, retry, waitForReplicas); err != nil {
|
||||
if scaleErr, ok := err.(ScaleError); !ok || scaleErr.FailureType != AlreadyScaled {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := rc.Delete(name); err != nil {
|
||||
@@ -172,11 +190,6 @@ func (reaper *ReplicationControllerReaper) Stop(namespace, name string, timeout
|
||||
return nil
|
||||
}
|
||||
|
||||
type DaemonSetReaper struct {
|
||||
client.Interface
|
||||
pollInterval, timeout time.Duration
|
||||
}
|
||||
|
||||
func (reaper *DaemonSetReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) error {
|
||||
ds, err := reaper.Extensions().DaemonSets(namespace).Get(name)
|
||||
if err != nil {
|
||||
@@ -214,11 +227,6 @@ func (reaper *DaemonSetReaper) Stop(namespace, name string, timeout time.Duratio
|
||||
return nil
|
||||
}
|
||||
|
||||
type JobReaper struct {
|
||||
client.Interface
|
||||
pollInterval, timeout time.Duration
|
||||
}
|
||||
|
||||
func (reaper *JobReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) error {
|
||||
jobs := reaper.Extensions().Jobs(namespace)
|
||||
pods := reaper.Pods(namespace)
|
||||
@@ -240,9 +248,7 @@ func (reaper *JobReaper) Stop(namespace, name string, timeout time.Duration, gra
|
||||
retry := NewRetryParams(reaper.pollInterval, reaper.timeout)
|
||||
waitForJobs := NewRetryParams(reaper.pollInterval, timeout)
|
||||
if err = scaler.Scale(namespace, name, 0, nil, retry, waitForJobs); err != nil {
|
||||
if scaleErr, ok := err.(ScaleError); !ok || scaleErr.FailureType != AlreadyScaled {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
// at this point only dead pods are left, that should be removed
|
||||
selector, _ := extensions.LabelSelectorAsSelector(job.Spec.Selector)
|
||||
@@ -270,10 +276,6 @@ func (reaper *JobReaper) Stop(namespace, name string, timeout time.Duration, gra
|
||||
return nil
|
||||
}
|
||||
|
||||
type PodReaper struct {
|
||||
client.Interface
|
||||
}
|
||||
|
||||
func (reaper *PodReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) error {
|
||||
pods := reaper.Pods(namespace)
|
||||
_, err := pods.Get(name)
|
||||
@@ -287,10 +289,6 @@ func (reaper *PodReaper) Stop(namespace, name string, timeout time.Duration, gra
|
||||
return nil
|
||||
}
|
||||
|
||||
type ServiceReaper struct {
|
||||
client.Interface
|
||||
}
|
||||
|
||||
func (reaper *ServiceReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) error {
|
||||
services := reaper.Services(namespace)
|
||||
_, err := services.Get(name)
|
||||
|
||||
Reference in New Issue
Block a user