chore: align extra-resources with sdk v0.5.0 and template#86
chore: align extra-resources with sdk v0.5.0 and template#86
Conversation
Signed-off-by: Philippe Scorsolini <p.scorsolini@gmail.com>
b6ed217 to
320ce29
Compare
There was a problem hiding this comment.
Pull request overview
Aligns function-extra-resources with the latest function SDK/template conventions while keeping existing branch behavior.
Changes:
- Adds package capability metadata (
spec.capabilities: [composition]). - Migrates request/response resource requirement handling to
RequiredResources/Requirements.Resources. - Refactors deterministic sorting comparisons using typed helpers (
lessByKind/lessAs).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| package/crossplane.yaml | Declares package capabilities to match current template expectations. |
| input/v1beta1/resource_select.go | Updates an optionality-related comment near selector label matcher logic. |
| fn.go | Migrates to RequiredResources APIs and refactors sorting comparisons with typed helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case reflect.String: | ||
| return lessAs[string](a, b) | ||
| default: | ||
| return false, errors.Errorf("unsupported type %q for sorting", kind) |
There was a problem hiding this comment.
Using %q with reflect.Kind will not format as intended (it’s not a string/rune), and may produce %!q(...) output. Use %s with kind.String() or %v to produce a clear error (e.g., errors.Errorf(\"unsupported type %s for sorting\", kind) or ...%v...).
| return false, errors.Errorf("unsupported type %q for sorting", kind) | |
| return false, errors.Errorf("unsupported type %s for sorting", kind.String()) |
| less, lessErr := lessByKind(t.Kind(), vali, valj) | ||
| if lessErr != nil { | ||
| err = lessErr | ||
| return false | ||
| } | ||
| return less | ||
| }) |
There was a problem hiding this comment.
If lessByKind returns an error once, the sort comparator may continue to be invoked many more times, doing unnecessary work and potentially overwriting err. Add an early guard at the top of the comparator (e.g., if err != nil { return false }) and consider only setting err if it’s currently nil.
| // FromFieldPathIsOptional returns true if the FromFieldPathPolicy is set to | ||
| // +optional | ||
| // Optional. | ||
| func (e *ResourceSourceSelectorLabelMatcher) FromFieldPathIsOptional() bool { |
There was a problem hiding this comment.
The doc comment is now grammatically incomplete across the wrapped lines. Consider making it a single coherent sentence, e.g. "... is set to Optional." so it reads cleanly in GoDoc.
Description of your changes
This PR aligns
function-extra-resourceswith the latest function SDK/template direction while preserving the current branch behavior (including namespaced selectors and max receive size support).Key updates:
req.RequiredResourcesrequest.GetRequiredResources(...)rsp.Requirements.ResourceslessByKind/lessAs) for safer comparisons.crossplane-runtime/v2.spec.capabilities: [composition]Rebase/conflict resolution notes:
MaxRecvMessageSize) and re-applying the SDK migration/sorting improvements.Validation:
go test ./...golangci-lint runFixes #
I have: