Skip to content

Commit

Permalink
updated invoker
Browse files Browse the repository at this point in the history
  • Loading branch information
henderiw committed Nov 6, 2024
1 parent 1048d50 commit c190fe8
Show file tree
Hide file tree
Showing 26 changed files with 255 additions and 151 deletions.
7 changes: 6 additions & 1 deletion apis/backend/as/asclaim_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -361,11 +362,15 @@ func (r *ASClaim) GetClaimSet(typ string) (sets.Set[tree.ID], error) {
return newClaimSet, nil
}

func (r *ASClaim) GetChoreoAPIVersion() string {
return schema.GroupVersion{Group: GroupName, Version: "as"}.String()
}

func ASClaimFromUnstructured(ru runtime.Unstructured) (backend.ClaimObject, error) {
obj := &ASClaim{}
err := runtime.DefaultUnstructuredConverter.FromUnstructured(ru.UnstructuredContent(), obj)
if err != nil {
return nil, fmt.Errorf("error converting unstructured to asIndex: %v", err)
return nil, fmt.Errorf("error converting unstructured to asClaim: %v", err)
}
return obj, nil
}
Expand Down
7 changes: 6 additions & 1 deletion apis/backend/as/asentry_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/kuidio/kuid/apis/backend"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
)
Expand Down Expand Up @@ -62,10 +63,14 @@ func (r *ASEntry) GetIndex() string { return r.Spec.Index }
func (r *ASEntry) GetClaimType() backend.ClaimType { return r.Spec.ClaimType }
func (r *ASEntry) GetSpecID() string { return r.Spec.ID }

func (r *ASEntry) GetChoreoAPIVersion() string {
return schema.GroupVersion{Group: GroupName, Version: "as"}.String()
}

func ASEntryFromRuntime(ru runtime.Object) (backend.EntryObject, error) {
entry, ok := ru.(*ASEntry)
if !ok {
return nil, errors.New("runtime object not ASIndex")
return nil, errors.New("runtime object not ASEntry")
}
return entry, nil
}
Expand Down
27 changes: 21 additions & 6 deletions apis/backend/as/invoker_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ func claimConvertFromInternal(obj runtime.Object) (runtime.Unstructured, error)
return &unstructured.Unstructured{Object: uobj}, nil
}

func (r *claiminvoker) convert(obj runtime.Object) (runtime.Unstructured, error) {
o, err := claimConvertToInternal(obj)
if err != nil {
return nil, err
}
return claimConvertFromInternal(o)
}

func (r *claiminvoker) InvokeCreate(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
claim, err := claimConvertToInternal(obj)
if err != nil {
Expand All @@ -77,19 +85,25 @@ func (r *claiminvoker) InvokeCreate(ctx context.Context, obj runtime.Object, rec
return newClaim, nil
}

func (r *claiminvoker) InvokeUpdate(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
func (r *claiminvoker) InvokeUpdate(ctx context.Context, obj, old runtime.Object, recursion bool) (runtime.Object, runtime.Object, error) {
claim, err := claimConvertToInternal(obj)
if err != nil {
return obj, err
return obj, old, err
}
if err := r.be.Claim(ctx, claim, recursion); err != nil {
return obj, err
return obj, old, err
}
newClaim, err := claimConvertFromInternal(claim)
if err != nil {
return obj, err
return obj, old, err
}
return newClaim, nil

oldu, err := r.convert(old)
if err != nil {
return obj, old, err
}

return newClaim, oldu, nil
}

func (r *claiminvoker) InvokeDelete(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
Expand All @@ -98,11 +112,12 @@ func (r *claiminvoker) InvokeDelete(ctx context.Context, obj runtime.Object, rec
return obj, err
}
if err := r.be.Release(ctx, claim, recursion); err != nil {
return obj,err
return obj, err
}
newClaim, err := claimConvertFromInternal(claim)
if err != nil {
return obj, err
}
return newClaim, nil
}

23 changes: 18 additions & 5 deletions apis/backend/as/invoker_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ func indexConvertFromInternal(obj runtime.Object) (runtime.Unstructured, error)
return &unstructured.Unstructured{Object: uobj}, nil
}

func (r *idxinvoker) convert(obj runtime.Object) (runtime.Unstructured, error) {
o, err := indexConvertToInternal(obj)
if err != nil {
return nil, err
}
return indexConvertFromInternal(o)
}

func (r *idxinvoker) InvokeCreate(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
index, err := indexConvertToInternal(obj)
if err != nil {
Expand All @@ -78,19 +86,24 @@ func (r *idxinvoker) InvokeCreate(ctx context.Context, obj runtime.Object, recur
return newIndex, nil
}

func (r *idxinvoker) InvokeUpdate(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
func (r *idxinvoker) InvokeUpdate(ctx context.Context, obj, old runtime.Object, recursion bool) (runtime.Object, runtime.Object, error) {
index, err := indexConvertToInternal(obj)
if err != nil {
return obj, err
return obj, old, err
}
if err := r.be.CreateIndex(ctx, index); err != nil {
return obj, err
return obj, old, err
}
newIndex, err := indexConvertFromInternal(index)
if err != nil {
return obj, err
return obj, old, err
}
return newIndex, nil

oldu, err := r.convert(old)
if err != nil {
return obj, old, err
}
return newIndex, oldu, nil
}

func (r *idxinvoker) InvokeDelete(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
Expand Down
5 changes: 5 additions & 0 deletions apis/backend/extcomm/extcommclaim_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -370,6 +371,10 @@ func (r *EXTCOMMClaim) GetClaimSet(typ string) (sets.Set[tree.ID], error) {
return newClaimSet, nil
}

func (r *EXTCOMMClaim) GetChoreoAPIVersion() string {
return schema.GroupVersion{Group: GroupName, Version: "extcomm"}.String()
}

func EXTCOMMClaimFromUnstructured(ru runtime.Unstructured) (backend.ClaimObject, error) {
obj := &EXTCOMMClaim{}
err := runtime.DefaultUnstructuredConverter.FromUnstructured(ru.UnstructuredContent(), obj)
Expand Down
5 changes: 5 additions & 0 deletions apis/backend/extcomm/extcommentry_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/kuidio/kuid/apis/backend"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
)
Expand Down Expand Up @@ -62,6 +63,10 @@ func (r *EXTCOMMEntry) GetIndex() string { return r.Spec.Index }
func (r *EXTCOMMEntry) GetClaimType() backend.ClaimType { return r.Spec.ClaimType }
func (r *EXTCOMMEntry) GetSpecID() string { return r.Spec.ID }

func (r *EXTCOMMEntry) GetChoreoAPIVersion() string {
return schema.GroupVersion{Group: GroupName, Version: "extcomm"}.String()
}

func EXTCOMMEntryFromRuntime(ru runtime.Object) (backend.EntryObject, error) {
entry, ok := ru.(*EXTCOMMEntry)
if !ok {
Expand Down
27 changes: 20 additions & 7 deletions apis/backend/extcomm/invoker_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ func claimConvertFromInternal(obj runtime.Object) (runtime.Unstructured, error)
return &unstructured.Unstructured{Object: uobj}, nil
}

func (r *claiminvoker) convert(obj runtime.Object) (runtime.Unstructured, error) {
o, err := claimConvertToInternal(obj)
if err != nil {
return nil, err
}
return claimConvertFromInternal(o)
}

func (r *claiminvoker) InvokeCreate(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
claim, err := claimConvertToInternal(obj)
if err != nil {
Expand All @@ -77,19 +85,25 @@ func (r *claiminvoker) InvokeCreate(ctx context.Context, obj runtime.Object, rec
return newClaim, nil
}

func (r *claiminvoker) InvokeUpdate(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
func (r *claiminvoker) InvokeUpdate(ctx context.Context, obj, old runtime.Object, recursion bool) (runtime.Object, runtime.Object, error) {
claim, err := claimConvertToInternal(obj)
if err != nil {
return obj, err
return obj, old, err
}
if err := r.be.Claim(ctx, claim, recursion); err != nil {
return obj, err
return obj, old, err
}
newClaim, err := claimConvertFromInternal(claim)
if err != nil {
return obj, err
return obj, old, err
}
return newClaim, nil

oldu, err := r.convert(old)
if err != nil {
return obj, old, err
}

return newClaim, oldu, nil
}

func (r *claiminvoker) InvokeDelete(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
Expand All @@ -98,12 +112,11 @@ func (r *claiminvoker) InvokeDelete(ctx context.Context, obj runtime.Object, rec
return obj, err
}
if err := r.be.Release(ctx, claim, recursion); err != nil {
return obj,err
return obj, err
}
newClaim, err := claimConvertFromInternal(claim)
if err != nil {
return obj, err
}
return newClaim, nil
}

23 changes: 18 additions & 5 deletions apis/backend/extcomm/invoker_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ func indexConvertFromInternal(obj runtime.Object) (runtime.Unstructured, error)
return &unstructured.Unstructured{Object: uobj}, nil
}

func (r *idxinvoker) convert(obj runtime.Object) (runtime.Unstructured, error) {
o, err := indexConvertToInternal(obj)
if err != nil {
return nil, err
}
return indexConvertFromInternal(o)
}

func (r *idxinvoker) InvokeCreate(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
index, err := indexConvertToInternal(obj)
if err != nil {
Expand All @@ -78,19 +86,24 @@ func (r *idxinvoker) InvokeCreate(ctx context.Context, obj runtime.Object, recur
return newIndex, nil
}

func (r *idxinvoker) InvokeUpdate(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
func (r *idxinvoker) InvokeUpdate(ctx context.Context, obj, old runtime.Object, recursion bool) (runtime.Object, runtime.Object, error) {
index, err := indexConvertToInternal(obj)
if err != nil {
return obj, err
return obj, old, err
}
if err := r.be.CreateIndex(ctx, index); err != nil {
return obj, err
return obj, old, err
}
newIndex, err := indexConvertFromInternal(index)
if err != nil {
return obj, err
return obj, old, err
}
return newIndex, nil

oldu, err := r.convert(old)
if err != nil {
return obj, old, err
}
return newIndex, oldu, nil
}

func (r *idxinvoker) InvokeDelete(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
Expand Down
5 changes: 5 additions & 0 deletions apis/backend/genid/genidclaim_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/selection"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -356,6 +357,10 @@ func (r *GENIDClaim) GetClaimSet(typ string) (sets.Set[tree.ID], error) {
return newClaimSet, nil
}

func (r *GENIDClaim) GetChoreoAPIVersion() string {
return schema.GroupVersion{Group: GroupName, Version: "genid"}.String()
}

func GENIDClaimFromUnstructured(ru runtime.Unstructured) (backend.ClaimObject, error) {
obj := &GENIDClaim{}
err := runtime.DefaultUnstructuredConverter.FromUnstructured(ru.UnstructuredContent(), obj)
Expand Down
5 changes: 5 additions & 0 deletions apis/backend/genid/genidentry_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/kuidio/kuid/apis/backend"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
)
Expand Down Expand Up @@ -62,6 +63,10 @@ func (r *GENIDEntry) GetIndex() string { return r.Spec.Index }
func (r *GENIDEntry) GetClaimType() backend.ClaimType { return r.Spec.ClaimType }
func (r *GENIDEntry) GetSpecID() string { return r.Spec.ID }

func (r *GENIDEntry) GetChoreoAPIVersion() string {
return schema.GroupVersion{Group: GroupName, Version: "genid"}.String()
}

func GENIDEntryFromRuntime(ru runtime.Object) (backend.EntryObject, error) {
entry, ok := ru.(*GENIDEntry)
if !ok {
Expand Down
28 changes: 21 additions & 7 deletions apis/backend/genid/invoker_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ func claimConvertFromInternal(obj runtime.Object) (runtime.Unstructured, error)
return &unstructured.Unstructured{Object: uobj}, nil
}

func (r *claiminvoker) convert(obj runtime.Object) (runtime.Unstructured, error) {
o, err := claimConvertToInternal(obj)
if err != nil {
return nil, err
}
return claimConvertFromInternal(o)
}

func (r *claiminvoker) InvokeCreate(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
claim, err := claimConvertToInternal(obj)
if err != nil {
Expand All @@ -77,19 +85,25 @@ func (r *claiminvoker) InvokeCreate(ctx context.Context, obj runtime.Object, rec
return newClaim, nil
}

func (r *claiminvoker) InvokeUpdate(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
func (r *claiminvoker) InvokeUpdate(ctx context.Context, obj, old runtime.Object, recursion bool) (runtime.Object, runtime.Object, error) {
claim, err := claimConvertToInternal(obj)
if err != nil {
return obj, err
return obj, old, err
}
if err := r.be.Claim(ctx, claim, recursion); err != nil {
return obj, err
return obj, old, err
}
newClaim, err := claimConvertFromInternal(claim)
if err != nil {
return obj, err
return obj, old, err
}
return newClaim, nil

oldu, err := r.convert(old)
if err != nil {
return obj, old, err
}

return newClaim, oldu, nil
}

func (r *claiminvoker) InvokeDelete(ctx context.Context, obj runtime.Object, recursion bool) (runtime.Object, error) {
Expand All @@ -98,11 +112,11 @@ func (r *claiminvoker) InvokeDelete(ctx context.Context, obj runtime.Object, rec
return obj, err
}
if err := r.be.Release(ctx, claim, recursion); err != nil {
return obj,err
return obj, err
}
newClaim, err := claimConvertFromInternal(claim)
if err != nil {
return obj, err
}
return newClaim, nil
}
}
Loading

0 comments on commit c190fe8

Please sign in to comment.