- 
                Notifications
    You must be signed in to change notification settings 
- Fork 55
Update to function-sdk-go 0.5.0 #498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -18,8 +18,8 @@ import ( | |
| "k8s.io/apimachinery/pkg/util/json" | ||
| "k8s.io/apimachinery/pkg/util/yaml" | ||
|  | ||
| "github.com/crossplane/crossplane-runtime/pkg/fieldpath" | ||
| "github.com/crossplane/crossplane-runtime/pkg/meta" | ||
| "github.com/crossplane/crossplane-runtime/v2/pkg/fieldpath" | ||
| "github.com/crossplane/crossplane-runtime/v2/pkg/meta" | ||
|  | ||
| "github.com/crossplane/function-sdk-go/errors" | ||
| "github.com/crossplane/function-sdk-go/logging" | ||
|  | @@ -134,12 +134,12 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) | |
| if yamlErr == (YamlErrorContext{}) { | ||
| newErr = err | ||
| } else { | ||
| context := strings.TrimSpace(yamlErr.Context) | ||
| if len(context) > 80 { | ||
| context = context[:80] + "..." | ||
| ctx := strings.TrimSpace(yamlErr.Context) | ||
| if len(ctx) > 80 { | ||
| ctx = ctx[:80] + "..." | ||
| } | ||
|  | ||
| newErr = fmt.Errorf("error converting YAML to JSON: yaml: line %d (document %d, line %d) near: '%s': %s", yamlErr.AbsLine, docIndex+1, yamlErr.RelLine, context, yamlErr.Message) | ||
| newErr = fmt.Errorf("error converting YAML to JSON: yaml: line %d (document %d, line %d) near: '%s': %s", yamlErr.AbsLine, docIndex+1, yamlErr.RelLine, ctx, yamlErr.Message) | ||
| } | ||
|  | ||
| response.Fatal(rsp, errors.Wrap(newErr, "cannot decode manifest")) | ||
|  | @@ -187,7 +187,7 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) | |
| } | ||
|  | ||
| // Initialize the requirements. | ||
| requirements := &fnv1.Requirements{ExtraResources: make(map[string]*fnv1.ResourceSelector)} | ||
| requirements := &fnv1.Requirements{Resources: make(map[string]*fnv1.ResourceSelector)} | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switching from ExtraResources to Resources will break things There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, that's why I put it back in Draft. We need to maintain the existing API to the user, which means adding the "extraResources" key into the template context with the same content as "requiredResources". Not ideal, but here we are. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch @tenitski, thanks for the reminder here! 😥 | ||
|  | ||
| // Convert the rendered manifests to a list of desired composed resources. | ||
| for _, obj := range objs { | ||
|  | @@ -274,11 +274,11 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) | |
| return rsp, nil | ||
| } | ||
| for k, v := range ers { | ||
| if _, found := requirements.ExtraResources[k]; found { | ||
| if _, found := requirements.Resources[k]; found { | ||
| response.Fatal(rsp, errors.Errorf("duplicate extra resource key %q", k)) | ||
| return rsp, nil | ||
| } | ||
| requirements.ExtraResources[k] = v.ToResourceSelector() | ||
| requirements.Resources[k] = v.ToResourceSelector() | ||
| } | ||
| default: | ||
| response.Fatal(rsp, errors.Errorf("invalid kind %q for apiVersion %q - must be one of CompositeConnectionDetails, Context or ExtraResources", obj.GetKind(), metaApiVersion)) | ||
|  | @@ -327,17 +327,24 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1.RunFunctionRequest) | |
| return rsp, nil | ||
| } | ||
|  | ||
| if len(requirements.ExtraResources) > 0 { | ||
| if len(requirements.Resources) > 0 { | ||
| rsp.Requirements = requirements | ||
| } | ||
|  | ||
| if len(req.ExtraResources) > 0 { | ||
| if len(req.ExtraResources) > 0 { // nolint:staticcheck // need to support existing clients | ||
| err = mergeExtraResourcesToContext(req, rsp) | ||
| if err != nil { | ||
| return rsp, nil | ||
| } | ||
| } | ||
|  | ||
| if len(req.RequiredResources) > 0 { | ||
| err = mergeRequiredResourcesToContext(req, rsp) | ||
| if err != nil { | ||
| return rsp, nil | ||
| } | ||
| } | ||
|  | ||
| f.log.Debug("Successfully composed desired resources", "source", in.Source, "count", len(objs)) | ||
|  | ||
| return rsp, nil | ||
|  | @@ -354,6 +361,14 @@ func convertToMap(req *fnv1.RunFunctionRequest) (map[string]any, error) { | |
| return nil, errors.Wrap(err, "cannot unmarshal json to map[string]any") | ||
| } | ||
|  | ||
| _, ok := mReq["extraResources"] | ||
| if !ok { | ||
| r, ok := mReq["requiredResources"] | ||
| if ok { | ||
| mReq["extraResources"] = r | ||
| } | ||
| } | ||
|  | ||
| return mReq, nil | ||
| } | ||
|  | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.