Skip to content

Commit

Permalink
Doc and deep equal
Browse files Browse the repository at this point in the history
  • Loading branch information
mproffitt committed Nov 1, 2023
1 parent 61144db commit 510e773
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/giantswarm/xfnlib

go 1.19
go 1.20

require (
github.com/aws/aws-sdk-go-v2 v1.21.2
Expand Down
3 changes: 3 additions & 0 deletions pkg/auth/aws/assumerole.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
"github.com/giantswarm/xfnlib/pkg/composite"
)

// GetAssumeRoleArn retrieves the current provider role arn from the providerconfig
//
// This requires the service account the function is runmning
func GetAssumeRoleArn(providerConfigRef *string) (arn *string, err error) {
var (
unstructuredData *unstructured.Unstructured = &unstructured.Unstructured{}
Expand Down
23 changes: 17 additions & 6 deletions pkg/composite/composition.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package composite

import (
"reflect"

"github.com/crossplane/crossplane-runtime/pkg/errors"
fnv1beta1 "github.com/crossplane/function-sdk-go/proto/v1beta1"
"github.com/crossplane/function-sdk-go/request"
Expand Down Expand Up @@ -29,15 +31,12 @@ type Composition struct {
Input InputProvider
}

// InputProvider This is basically a wrapper to `runtime.Object` and exists to ensure that
// all inputs to the `New` conform to a supported type
type InputProvider interface {
runtime.Object
}

type Input struct {
InputProvider
Spec *runtime.Object
}

// New takes a RunFunctionRequest object and converts it to a Composition
//
// This method should be called at the top of your RunFunction.
Expand All @@ -48,13 +47,16 @@ type Input struct {
// f.log.Info("Running Function", composedName, req.GetMeta().GetTag())
// rsp = response.To(req, response.DefaultTTL)
//
// if f.composed, err = RequestToComposition(req); err != nil {
// input := v1beta1.Input{}
// if f.composed, err = composite.New(req, &input, &f.composite); err != nil {
// response.Fatal(rsp, errors.Wrap(err, "error setting up function "+composedName))
// return rsp, nil
// }
//
// ...
// // Function body
// ...
//
// if err = f.composed.ToResponse(rsp); err != nil {
// response.Fatal(rsp, errors.Wrapf(err, "cannot convert composition to response %T", rsp))
// return
Expand Down Expand Up @@ -122,7 +124,16 @@ func (c *Composition) ToResponse(rsp *fnv1beta1.RunFunctionResponse) (err error)
}

// AddDesired takes an unstructured object and adds it to the desired composed resources
//
// If the object exists on the stack already, we do a deepEqual to see if the object has changed
// and if not, this method won't do anything.
func (c *Composition) AddDesired(name string, object *unstructured.Unstructured) (err error) {
if o, ok := c.DesiredComposed[resource.Name(name)]; ok {
// Object exists and hasn't changed
if reflect.DeepEqual(o.Resource.Object, object.Object) {
return
}
}
c.DesiredComposed[resource.Name(name)] = &resource.DesiredComposed{
Resource: &composed.Unstructured{
Unstructured: *object,
Expand Down
6 changes: 6 additions & 0 deletions pkg/composite/errors.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
package composite

// MissingMetadata is raised when an object does not contain a metadata type
type MissingMetadata struct{}

func (e *MissingMetadata) Error() string {
return "object does not contain metadata"
}

// InvalidMetadata is raised when an object metadata cannot be unpacked to a Metadata object
type InvalidMetadata struct{}

func (e *InvalidMetadata) Error() string {
return "invalid or empty metadata object"
}

// MissingSpec when an object requiring spec is detected but spec is not found during unpack
type MissingSpec struct{}

func (e *MissingSpec) Error() string {
return "object does not contain spec field"
}

// InvalidSpec is raised when an object spec cannot be unpacked to the required spec object
type InvalidSpec struct{}

func (e *InvalidSpec) Error() string {
return "invalid or empty object spec"
}

// WaitingForSpec Raise this error if your input has no spec on the XR but spec is required.
// Methods receiving this should return response.Normal
type WaitingForSpec struct{}

func (w *WaitingForSpec) Error() string {
Expand Down

0 comments on commit 510e773

Please sign in to comment.