Add a custom timeout flag for stop/delete. Also try to be smarter about setting the timeout.
This commit is contained in:
@@ -26,13 +26,15 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Interval = time.Millisecond * 100
|
||||
Interval = time.Second * 1
|
||||
Timeout = time.Minute * 5
|
||||
)
|
||||
|
||||
// A Reaper handles terminating an object as gracefully as possible.
|
||||
// timeout is how long we'll wait for the termination to be successful
|
||||
// gracePeriod is time given to an API object for it to delete itself cleanly (e.g. pod shutdown)
|
||||
type Reaper interface {
|
||||
Stop(namespace, name string, gracePeriod *api.DeleteOptions) (string, error)
|
||||
Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) (string, error)
|
||||
}
|
||||
|
||||
type NoSuchReaperError struct {
|
||||
@@ -80,14 +82,21 @@ type objInterface interface {
|
||||
Get(name string) (meta.Interface, error)
|
||||
}
|
||||
|
||||
func (reaper *ReplicationControllerReaper) Stop(namespace, name string, gracePeriod *api.DeleteOptions) (string, error) {
|
||||
func (reaper *ReplicationControllerReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) (string, error) {
|
||||
rc := reaper.ReplicationControllers(namespace)
|
||||
scaler, err := ScalerFor("ReplicationController", NewScalerClient(*reaper))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if timeout == 0 {
|
||||
rc, err := rc.Get(name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
timeout = Timeout + time.Duration(10*rc.Spec.Replicas)*time.Second
|
||||
}
|
||||
retry := NewRetryParams(reaper.pollInterval, reaper.timeout)
|
||||
waitForReplicas := NewRetryParams(reaper.pollInterval, reaper.timeout)
|
||||
waitForReplicas := NewRetryParams(reaper.pollInterval, timeout)
|
||||
if err = scaler.Scale(namespace, name, 0, nil, retry, waitForReplicas); err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -97,7 +106,7 @@ func (reaper *ReplicationControllerReaper) Stop(namespace, name string, gracePer
|
||||
return fmt.Sprintf("%s stopped", name), nil
|
||||
}
|
||||
|
||||
func (reaper *PodReaper) Stop(namespace, name string, gracePeriod *api.DeleteOptions) (string, error) {
|
||||
func (reaper *PodReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) (string, error) {
|
||||
pods := reaper.Pods(namespace)
|
||||
_, err := pods.Get(name)
|
||||
if err != nil {
|
||||
@@ -110,7 +119,7 @@ func (reaper *PodReaper) Stop(namespace, name string, gracePeriod *api.DeleteOpt
|
||||
return fmt.Sprintf("%s stopped", name), nil
|
||||
}
|
||||
|
||||
func (reaper *ServiceReaper) Stop(namespace, name string, gracePeriod *api.DeleteOptions) (string, error) {
|
||||
func (reaper *ServiceReaper) Stop(namespace, name string, timeout time.Duration, gracePeriod *api.DeleteOptions) (string, error) {
|
||||
services := reaper.Services(namespace)
|
||||
_, err := services.Get(name)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user