Skip to content

Commit

Permalink
support both rollout api v1beta1 and v1alpha1 (#105)
Browse files Browse the repository at this point in the history
Signed-off-by: AiRanthem <[email protected]>
  • Loading branch information
AiRanthem authored Oct 29, 2024
1 parent 7ee5bea commit a1f4d24
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/lithammer/dedent v1.1.0
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
github.com/openkruise/kruise-api v1.5.0
github.com/openkruise/kruise-rollout-api v0.5.0
github.com/openkruise/kruise-rollout-api v0.5.1
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/openkruise/kruise-api v1.5.0 h1:Pbg5sr0AiJ+Tb8MBoPKrQLD4jOeI66zGhC4q2UG5i4Y=
github.com/openkruise/kruise-api v1.5.0/go.mod h1:C+ZilhxrMUiX6EYDIOsNowyu3i6pTHL6s0B9dxf2zAk=
github.com/openkruise/kruise-rollout-api v0.5.0 h1:6e1YN6d/ArTAX0jxSMlZt/GxmxBO7zi7+YeKxXpYm7U=
github.com/openkruise/kruise-rollout-api v0.5.0/go.mod h1:Db/+T+VaMtE++qTmBkW+lkBFO7zO5fgTZibfnKKfGaM=
github.com/openkruise/kruise-rollout-api v0.5.1 h1:wZug9vIfkTjfGANEWX7//NhFLpsL4ZU3kZq8kFSYk7I=
github.com/openkruise/kruise-rollout-api v0.5.1/go.mod h1:Db/+T+VaMtE++qTmBkW+lkBFO7zO5fgTZibfnKKfGaM=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
Expand Down
6 changes: 4 additions & 2 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package api
import (
kruiseappsv1alpha1 "github.com/openkruise/kruise-api/apps/v1alpha1"
kruiseappsv1beta1 "github.com/openkruise/kruise-api/apps/v1beta1"
kruiserolloutsv1apha1 "github.com/openkruise/kruise-rollout-api/rollouts/v1beta1"
kruiserolloutsv1alpha1 "github.com/openkruise/kruise-rollout-api/rollouts/v1alpha1"
kruiserolloutsv1beta1 "github.com/openkruise/kruise-rollout-api/rollouts/v1beta1"
apps "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -39,7 +40,8 @@ func init() {
_ = clientgoscheme.AddToScheme(Scheme)
_ = kruiseappsv1alpha1.AddToScheme(Scheme)
_ = kruiseappsv1beta1.AddToScheme(Scheme)
_ = kruiserolloutsv1apha1.AddToScheme(Scheme)
_ = kruiserolloutsv1alpha1.AddToScheme(Scheme)
_ = kruiserolloutsv1beta1.AddToScheme(Scheme)
}

func GetScheme() *runtime.Scheme {
Expand Down
17 changes: 12 additions & 5 deletions pkg/internal/polymorphichelpers/objectapprover.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@ import (
"errors"
"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"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubectl/pkg/scheme"
)

// defaultObjectApprover currently only support Kruise Rollout.
func defaultObjectApprover(obj runtime.Object) ([]byte, error) {
switch obj := obj.(type) {
case *rolloutsapi.Rollout:
if obj.Status.CanaryStatus == nil || obj.Status.CanaryStatus.CurrentStepState != rolloutsapi.CanaryStepStatePaused {
case *rolloutsapiv1alpha1.Rollout:
if obj.Status.CanaryStatus == nil || obj.Status.CanaryStatus.CurrentStepState != rolloutsapiv1alpha1.CanaryStepStatePaused {
return nil, errors.New("does not allow to approve, because current canary state is not 'StepPaused'")
}
obj.Status.CanaryStatus.CurrentStepState = rolloutsapi.CanaryStepStateReady
return runtime.Encode(scheme.Codecs.LegacyCodec(rolloutsapi.GroupVersion), obj)
obj.Status.CanaryStatus.CurrentStepState = rolloutsapiv1alpha1.CanaryStepStateReady
return runtime.Encode(scheme.Codecs.LegacyCodec(rolloutsapiv1alpha1.GroupVersion), obj)
case *rolloutsapiv1beta1.Rollout:
if obj.Status.CanaryStatus == nil || obj.Status.CanaryStatus.CurrentStepState != rolloutsapiv1beta1.CanaryStepStatePaused {
return nil, errors.New("does not allow to approve, because current canary state is not 'StepPaused'")
}
obj.Status.CanaryStatus.CurrentStepState = rolloutsapiv1beta1.CanaryStepStateReady
return runtime.Encode(scheme.Codecs.LegacyCodec(rolloutsapiv1beta1.GroupVersion), obj)

default:
return nil, fmt.Errorf("approving is not supported")
Expand Down

0 comments on commit a1f4d24

Please sign in to comment.