Skip to content

Commit

Permalink
fix a rollout version bug
Browse files Browse the repository at this point in the history
Signed-off-by: yunbo <[email protected]>
  • Loading branch information
Funinu committed Dec 9, 2024
1 parent 9d68939 commit 2cba688
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions pkg/cmd/rollout/rollout_undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ package rollout
import (
"fmt"

rolloutsapi "github.com/openkruise/kruise-rollout-api/rollouts/v1beta1"
rolloutsapiv1alpha1 "github.com/openkruise/kruise-rollout-api/rollouts/v1alpha1"
rolloutsapiv1beta1 "github.com/openkruise/kruise-rollout-api/rollouts/v1beta1"
internalapi "github.com/openkruise/kruise-tools/pkg/api"
internalpolymorphichelpers "github.com/openkruise/kruise-tools/pkg/internal/polymorphichelpers"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -195,13 +196,12 @@ func (o *UndoOptions) RunUndo() error {
if info.Mapping.GroupVersionKind.Group == "rollouts.kruise.io" && info.Mapping.GroupVersionKind.Kind == "Rollout" {
obj := info.Object
if obj == nil {
return fmt.Errorf("Rollout object not found")
return fmt.Errorf("rollout object not found")
}
ro, ok := obj.(*rolloutsapi.Rollout)
if !ok {
return fmt.Errorf("unsupported version of Rollout")
workloadRef, err := getWorkloadRefFromRollout(obj)
if err != nil {
return err
}
workloadRef := ro.Spec.WorkloadRef
gv, err := schema.ParseGroupVersion(workloadRef.APIVersion)
if err != nil {
return err
Expand Down Expand Up @@ -246,3 +246,19 @@ func (o *UndoOptions) RunUndo() error {
aggErrs = append(aggErrs, err)
return errors.NewAggregate(aggErrs)
}

func getWorkloadRefFromRollout(obj interface{}) (workloadRef *rolloutsapiv1beta1.ObjectRef, err error) {
switch rollout := obj.(type) {
case *rolloutsapiv1alpha1.Rollout:
workloadRef = &rolloutsapiv1beta1.ObjectRef{
Kind: rollout.Spec.ObjectRef.WorkloadRef.Kind,
APIVersion: rollout.Spec.ObjectRef.WorkloadRef.APIVersion,
Name: rollout.Spec.ObjectRef.WorkloadRef.Name,
}
case *rolloutsapiv1beta1.Rollout:
workloadRef = &rollout.Spec.WorkloadRef
default:
return nil, fmt.Errorf("unsupported version of Rollout")
}
return workloadRef, nil
}

0 comments on commit 2cba688

Please sign in to comment.