Skip to content

Commit

Permalink
hide the same-workload-error
Browse files Browse the repository at this point in the history
Signed-off-by: yunbo <yunbo10124scut@gmail.com>
  • Loading branch information
Funinu committed Dec 14, 2023
1 parent 1106ed8 commit ae47bdc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ $ kubectl kruise rollout status statefulsets.apps.kruise.io/sts2
# approve a kruise rollout resource named "rollout-demo" in "ns-demo" namespace
$ kubectl-kruise rollout approve rollout-demo -n ns-demo`
# undo a kruise rollout resource and a cloneset (ro1 dosen't reference to cs1 )
# undo a kruise rollout resource and a cloneset
$ kubectl-kruise rollout undo rollout/ro1 cloneset/cs1
```

Expand Down
28 changes: 8 additions & 20 deletions pkg/cmd/rollout/rollout_undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (o *UndoOptions) RunUndo() error {
// deduplication: If a rollout arg references a workload which is also specified as an arg in the same command,
// performing multiple undo operations on the workload within a single command is not smart. Such an action could
// lead to confusion and yield unintended consequences. Therefore, undo operations in this context are disallowed.
// Should such a scenario occur, the system will report an error and only the first argument that points to the workload will be executed.
// Should such a scenario occur, only the first argument that points to the workload will be executed.
deDuplica := make(map[string]struct{})

err := r.Visit(func(info *resource.Info, err error) error {
Expand All @@ -222,31 +222,19 @@ func (o *UndoOptions) RunUndo() error {
return err
}
deDuplicaKey := workloadRef.Kind + "." + gv.Version + "." + gv.Group + "/" + workloadRef.Name

printer, err := o.ToPrinter(fmt.Sprintf("references to %s", deDuplicaKey))
if err != nil {
return err
}
err = printer.PrintObj(info.Object, o.Out)
if err != nil {
return err
}

if _, ok := deDuplica[deDuplicaKey]; ok {
return fmt.Errorf("multiple undo operations on the same workload (%s) is not allowed", deDuplicaKey)
return nil
}
deDuplica[deDuplicaKey] = struct{}{}
refResources = append(refResources, deDuplicaKey)
return nil
} else {
gvk := info.Mapping.GroupVersionKind
deDuplicaKey := gvk.Kind + "." + gvk.Version + "." + gvk.Group + "/" + info.Name
if _, ok := deDuplica[deDuplicaKey]; ok {
return fmt.Errorf("multiple undo operations on the same workload (%s) is not allowed", deDuplicaKey)
}
deDuplica[deDuplicaKey] = struct{}{}
}

gvk := info.Mapping.GroupVersionKind
deDuplicaKey := gvk.Kind + "." + gvk.Version + "." + gvk.Group + "/" + info.Name
if _, ok := deDuplica[deDuplicaKey]; ok {
return nil
}
deDuplica[deDuplicaKey] = struct{}{}
return undoFunc(info, nil)
})

Expand Down

0 comments on commit ae47bdc

Please sign in to comment.