Skip to content
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

Allow downstream projects to programmatically run envoy #433

Closed
arkodg opened this issue Oct 28, 2022 · 6 comments · Fixed by #446
Closed

Allow downstream projects to programmatically run envoy #433

arkodg opened this issue Oct 28, 2022 · 6 comments · Fixed by #446
Labels
enhancement New feature or request

Comments

@arkodg
Copy link
Contributor

arkodg commented Oct 28, 2022

Is your feature request related to a problem? Please describe.
I would like to import packages within this project to programmatically run envoy from another go process
so I can use this project to instantiate envoy sub processes during integration testing

Describe the solution you'd like
Ideally would like github.com/tetratelabs/func-e/internal/cmd to moved to github.com/tetratelabs/func-e/pkg/cmd

@arkodg arkodg added the enhancement New feature or request label Oct 28, 2022
@arkodg
Copy link
Contributor Author

arkodg commented Oct 28, 2022

@codefromthecrypt can you please elaborate on #419 (comment) if you still believe that is the better way of allowing downstream projects to consume the CLI rather than depending on the cmd package and its existing API ?

@codefromthecrypt
Copy link
Contributor

I don't think you need to expose the entire package hierarchy in order to provide an api. Basically what I mean is to make a top-level api that only includes the functionality needed. That top-level type can defer to the internal code.

@arkodg
Copy link
Contributor Author

arkodg commented Oct 28, 2022

this is a snippet of how someone might import func-e to spawn envoy

import (
	funcecmd "github.com/tetratelabs/func-e/pkg/cmd"
	funceglobals "github.com/tetratelabs/func-e/pkg/globals"
	funceversion "github.com/tetratelabs/func-e/pkg/version"
)
....
func FuncERunCmd(args []string) error {
	o := funceglobals.GlobalOpts{}
	o.EnvoyVersion = funceversion.LastKnownEnvoy
	o.Out = os.Stderr
	funcECmd := funcecmd.NewApp(&o)
	// Always use amd64 for now, since it is the only arch that consistently available in
	// https://archive.tetratelabs.io/envoy/envoy-versions.json. This is also done in e2e if we use
	// func-e as the Envoy runner.
	funcERunArgs := []string{"func-e", "--platform", runtime.GOOS + "/amd64", "run"}
	// Append args
	funcERunArgs = append(funcERunArgs, args...)
	return funcECmd.Run(funcERunArgs)
}

@codefromthecrypt are you referring to moving the bare minimum such as
cmd.NewApp and globals.GlobalOpts into api/ , if so, can raise a PR for it

@codefromthecrypt
Copy link
Contributor

Sorry I don't mean move as it is clunky. I mean to design a proper api and use it. I'll put a sketch up as I think show > tell

@arkodg
Copy link
Contributor Author

arkodg commented Oct 28, 2022

thanks @codefromthecrypt

@codefromthecrypt
Copy link
Contributor

cool #434 is on a shared branch so feel free to use it or close it.

Main thing is the library approach should be able to control writers and things especially as that makes it testable. Also, except for emulation, I think you'll want to default to the real architecture vs choosing something besides GOARCH. Anyway, the main idea is to make a package and only poke holes as needed, make it idiomatic for go use as opposed to exposing the CLI mechanics directly. This is true even if tactically CLI mechanics are used!

Hope this helps

arkodg added a commit that referenced this issue Aug 9, 2023
* Define an api that allows go projects to use func-e as a library

Takes #434 forward

Fixes: #433

Signed-off-by: Arko Dasgupta <[email protected]>
arkodg added a commit that referenced this issue Aug 9, 2023
* Define an api that allows go projects to use func-e as a library

Takes #434 forward

Fixes: #433

Signed-off-by: Arko Dasgupta <[email protected]>
@arkodg arkodg closed this as completed in c85a098 Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants