Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubectl: simplify Rollbacker interface #28217

Merged
merged 1 commit into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/kubectl/cmd/rollout/rollout_undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (o *UndoOptions) CompleteUndo(f *cmdutil.Factory, cmd *cobra.Command, out i
func (o *UndoOptions) RunUndo() error {
allErrs := []error{}
for ix, info := range o.Infos {
result, err := o.Rollbackers[ix].Rollback(info.Namespace, info.Name, nil, o.ToRevision, info.Object)
result, err := o.Rollbackers[ix].Rollback(info.Object, nil, o.ToRevision)
if err != nil {
allErrs = append(allErrs, cmdutil.AddSourceToErr("undoing", info.Source, err))
continue
Expand Down
19 changes: 11 additions & 8 deletions pkg/kubectl/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (

// Rollbacker provides an interface for resources that can be rolled back.
type Rollbacker interface {
Rollback(namespace, name string, updatedAnnotations map[string]string, toRevision int64, obj runtime.Object) (string, error)
Rollback(obj runtime.Object, updatedAnnotations map[string]string, toRevision int64) (string, error)
}

func RollbackerFor(kind unversioned.GroupKind, c client.Interface) (Rollbacker, error) {
Expand All @@ -48,13 +48,16 @@ type DeploymentRollbacker struct {
c client.Interface
}

func (r *DeploymentRollbacker) Rollback(namespace, name string, updatedAnnotations map[string]string, toRevision int64, obj runtime.Object) (string, error) {
d := obj.(*extensions.Deployment)
func (r *DeploymentRollbacker) Rollback(obj runtime.Object, updatedAnnotations map[string]string, toRevision int64) (string, error) {
d, ok := obj.(*extensions.Deployment)
if !ok {
return "", fmt.Errorf("passed object is not a Deployment: %#v", obj)
}
if d.Spec.Paused {
return "", fmt.Errorf("you cannot rollback a paused deployment; resume it first with 'kubectl rollout resume' and try again")
return "", fmt.Errorf("you cannot rollback a paused deployment; resume it first with 'kubectl rollout resume deployment/%s' and try again", d.Name)
}
deploymentRollback := &extensions.DeploymentRollback{
Name: name,
Name: d.Name,
UpdatedAnnotations: updatedAnnotations,
RollbackTo: extensions.RollbackConfig{
Revision: toRevision,
Expand All @@ -63,16 +66,16 @@ func (r *DeploymentRollbacker) Rollback(namespace, name string, updatedAnnotatio
result := ""

// Get current events
events, err := r.c.Events(namespace).List(api.ListOptions{})
events, err := r.c.Events(d.Namespace).List(api.ListOptions{})
if err != nil {
return result, err
}
// Do the rollback
if err := r.c.Extensions().Deployments(namespace).Rollback(deploymentRollback); err != nil {
if err := r.c.Extensions().Deployments(d.Namespace).Rollback(deploymentRollback); err != nil {
return result, err
}
// Watch for the changes of events
watch, err := r.c.Events(namespace).Watch(api.ListOptions{Watch: true, ResourceVersion: events.ResourceVersion})
watch, err := r.c.Events(d.Namespace).Watch(api.ListOptions{Watch: true, ResourceVersion: events.ResourceVersion})
if err != nil {
return result, err
}
Expand Down