Skip to content

Allow implicit ResourceListProcessorFunc#760

Open
mozesl-nokia wants to merge 5 commits into
kptdev:mainfrom
nokia:as-main-types
Open

Allow implicit ResourceListProcessorFunc#760
mozesl-nokia wants to merge 5 commits into
kptdev:mainfrom
nokia:as-main-types

Conversation

@mozesl-nokia

Copy link
Copy Markdown
Contributor

Currently, if you want to pass a function to AsMain, even if it has the correct ResourceListProcessorFunc signature, it will still fail the casting. Thus, it has to be explicitly wrapped.

With this PR, you can now just pass the function pointer or an anonymous/lambda function.

No AI was used in the creation of this PR.

Copilot AI review requested due to automatic review settings June 22, 2026 09:02
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Go KRM Functions SDK’s AsMain entrypoint to accept more natural processor inputs (including plain functions matching the ResourceListProcessorFunc signature) without requiring explicit wrapping, and adds tests to cover the newly supported input forms.

Changes:

  • Extend AsMain to accept any ResourceListProcessor implementation and raw func(*ResourceList) (bool, error) values.
  • Remove redundant processor type-casting logic from Run.
  • Add a new unit test covering multiple AsMain input types (processor struct, implicit/explicit func, runner processor, anonymous func).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
go/fn/run.go Broaden AsMain input handling and simplify Run by removing prior type switching.
go/fn/run_test.go Add coverage for the expanded AsMain accepted input types.
Comments suppressed due to low confidence (1)

go/fn/run.go:216

  • Run no longer validates the processor argument, so calling Run(nil, ...) will now panic when p.Process is invoked. Since Run is a public API, it should fail fast with a regular error for a nil processor (maintains the previous behavior of returning an error instead of panicking).
func Run(p ResourceListProcessor, input []byte) ([]byte, error) {
	rl, err := ParseResourceList(input)
	if err != nil {
		return nil, err
	}
	success, fnErr := p.Process(rl)
	out, yamlErr := rl.ToYAML()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread go/fn/run_test.go
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
Signed-off-by: Mózes László Máté <laszlo.mozes@nokia.com>
@mozesl-nokia mozesl-nokia added enhancement New feature or request go Pull requests that update Go code labels Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants