Merge pull request #8057 from kargakis/rework-resize

resize: Use Resize method
This commit is contained in:
Derek Carr 2015-05-12 10:17:31 -04:00
commit a11819e4a6
2 changed files with 9 additions and 16 deletions

View File

@ -26,7 +26,6 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl"
cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util" cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource" "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
) )
const ( const (
@ -105,15 +104,11 @@ func RunResize(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []str
resourceVersion := cmdutil.GetFlagString(cmd, "resource-version") resourceVersion := cmdutil.GetFlagString(cmd, "resource-version")
currentSize := cmdutil.GetFlagInt(cmd, "current-replicas") currentSize := cmdutil.GetFlagInt(cmd, "current-replicas")
precondition := &kubectl.ResizePrecondition{currentSize, resourceVersion} precondition := &kubectl.ResizePrecondition{currentSize, resourceVersion}
cond := kubectl.ResizeCondition(resizer, precondition, info.Namespace, info.Name, uint(count)) retry := &kubectl.RetryParams{Interval: retryFrequency, Timeout: retryTimeout}
msg := "resized" if err := resizer.Resize(info.Namespace, info.Name, uint(count), precondition, retry, nil); err != nil {
if err = wait.Poll(retryFrequency, retryTimeout, cond); err != nil {
msg = fmt.Sprintf("Failed to resize controller in spite of retrying for %s", retryTimeout)
if err != nil {
return err return err
} }
} fmt.Fprint(out, "resized\n")
fmt.Fprintf(out, "%s\n", msg)
return nil return nil
} }

View File

@ -102,7 +102,7 @@ type ReplicationControllerResizer struct {
} }
type RetryParams struct { type RetryParams struct {
interval, timeout time.Duration Interval, Timeout time.Duration
} }
func NewRetryParams(interval, timeout time.Duration) *RetryParams { func NewRetryParams(interval, timeout time.Duration) *RetryParams {
@ -153,18 +153,16 @@ func (resizer *ReplicationControllerResizer) Resize(namespace, name string, newS
} }
if retry == nil { if retry == nil {
// Make it try only once, immediately // Make it try only once, immediately
retry = &RetryParams{interval: time.Millisecond, timeout: time.Millisecond} retry = &RetryParams{Interval: time.Millisecond, Timeout: time.Millisecond}
} }
cond := ResizeCondition(resizer, preconditions, namespace, name, newSize) cond := ResizeCondition(resizer, preconditions, namespace, name, newSize)
if err := wait.Poll(retry.interval, retry.timeout, cond); err != nil { if err := wait.Poll(retry.Interval, retry.Timeout, cond); err != nil {
return err return err
} }
if waitForReplicas != nil { if waitForReplicas != nil {
rc := &api.ReplicationController{ObjectMeta: api.ObjectMeta{Namespace: namespace, Name: name}} rc := &api.ReplicationController{ObjectMeta: api.ObjectMeta{Namespace: namespace, Name: name}}
if err := wait.Poll(waitForReplicas.interval, waitForReplicas.timeout, return wait.Poll(waitForReplicas.Interval, waitForReplicas.Timeout,
resizer.c.ControllerHasDesiredReplicas(rc)); err != nil { resizer.c.ControllerHasDesiredReplicas(rc))
return err
}
} }
return nil return nil
} }