Coder Social home page Coder Social logo

Comments (5)

blakeromano avatar blakeromano commented on June 12, 2024 1

When I update code to I do not get an error

	desired.Resource.Object = map[string]interface{}{
		"apiVersion": "s3.aws.upbound.io/v1beta1",
		"kind": "BucketServerSideEncryptionConfiguration",
		"metadata": map[string]interface{}{
			"name": oxr.Resource.GetClaimReference().Name,
			"namespace": oxr.Resource.GetClaimReference().Namespace,
		},
		"spec": map[string]interface{}{
			"deletionPolicy": "Retain",
			"forProvider": map[string]interface{}{
				"region": "us-east-2",
				"bucketSelector": map[string]interface{}{
					"matchControllerRef": true,
				},
				"rule": []interface{}{
					map[string]interface{}{
						"applyServerSideEncryptionByDefault": []interface{}{
							map[string]interface{}{
								"sseAlgorithm": "AES256",
							},
						},
					},
				},
			},
			"providerConfigRef": map[string]interface{}{
				"name": "aws-provider",
			},
		},
	}

Yeah I am taking a first stab at XFNs so if there is a better way to import resource types and do it that way I'd love to see some examples.

from function-sdk-go.

negz avatar negz commented on June 12, 2024

@blakeromano Does it work if you make rule an []interface{} where the values happen to be map[string]interface{}?

As a side note, working with unstructured interface data like this feels likely to be unintuitive and error prone. For managed resources like BucketServerSideEncryptionConfiguration we could probably import the go types from the providers and use those. I'd like to add some examples of that pattern.

from function-sdk-go.

negz avatar negz commented on June 12, 2024

@blakeromano The reason behind the this behavior is that there's an assumption that Object will be a map[string]interface{} containing values in the shape that https://pkg.go.dev/encoding/json#Unmarshal would create when unmarshalling JSON into a map[string]interface{}.

See:

One thing we could do here would be to make this clear in the error that you hit.

from function-sdk-go.

Kidswiss avatar Kidswiss commented on June 12, 2024

@negz it would be nice if the SDK interface would just accept runtime.Object and do the serialization to unscructured in the background.

As a side note, working with unstructured interface data like this feels likely to be unintuitive and error prone. For managed resources like BucketServerSideEncryptionConfiguration we could probably import the go types from the providers and use those. I'd like to add some examples of that pattern.

We did something similar with the alpha FunctionIO, although then it was mostly raw []byte, but the concept is the same. We import the managed resource structs wherever possible and work with those. Then we wrote some tooling to marshal them seamlessly.

For example to get the composite: https://github.com/vshn/appcat/blob/master/pkg/comp-functions/runtime/desired.go#L155
And then it's easy to get any typed object back: https://github.com/vshn/appcat/blob/master/pkg/comp-functions/functions/miniobucket/miniobucket.go#L28

Would you be open for a PR that implements something similar with the function-sdk-go? I'm currently in the process of adjusting our code to crossplane 1.14 and it would be really great if function-sdk-go could provide APIs for typed objects.

from function-sdk-go.

negz avatar negz commented on June 12, 2024

I'll close out this issue. I'm not sure what next steps are here. I think maybe the most interesting thing here is that some folks want to (or at least intuited that they should) work with functions by setting the unstructured Object directly, which is not really something I expected. If that becomes a trend we may need to point folks at documentation (e.g. upstream Go documentation) WRT expectations around building a JSON-compatible map[string]interface{}.

@Kidswiss Can you raise a dedicated tracking issue for improving the support for working with runtime.Object? Ideally with a proposed API. I'm open to changes to support that better.

We do already have (e.g.) composed.From() to create a new composed resource from an arbitrary runtime.Object, But we don't have anything going the other way - i.e. to load the desired XR into an arbitrary runtime.Object.

from function-sdk-go.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.