You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We implemented a knative function using a go-lang handler.
This handler reads its configuration from environment variables retrieved via the envconfig library.
The environment variables are correctly parsed and read if the function is deployed on a cluster with the CLI via func deploy, so technically it works in our production environment.
However when the function is run locally with func run there is no way to pass the environment variables to the function.
func run -e 'URL=http://example.com' or func run --env 'URL=http://example.com' does not seem to work properly and passes nothing into our function. Setting the parameters in the func.yaml also does not pass them into the function when func run is used, but works perfectly fine with func deploy.
The Start function looks like the following:
func (h *CloserHandler) Start(ctx context.Context, args map[string]string) error {
h.logger = GetLogger(levelFromString(h.config.LogLevel), "function", "closer", "version", "1.0.0")
h.logger.Info(fmt.Sprintf("%#v", h.config))
// Print all environment variables
for _, env := range os.Environ() {
h.logger.Info(env)
}
// Parse the environment variables
err := envconfig.Process("", &h.config)
if err != nil {
return errors.Join(ErrUnparseableEnvironment, fmt.Errorf("failed to parse environment variables: %w", err))
}
}
The config.go looks like this:
package function
import "net/url"
type darktraceConfig struct {
PublicToken string `envconfig:"DARKTRACE_PUBLIC_TOKEN" required:"true"`
PrivateToken string `envconfig:"DARKTRACE_PRIVATE_TOKEN" required:"true"`
URL *url.URL `envconfig:"DARKTRACE_URL" required:"true"`
SkipVerify bool `envconfig:"DARKTRACE_SKIP_VERIFY" default:"false"`
}
type cfg struct {
// LogLevel is the log level for the structured logger.
LogLevel string `envconfig:"LOG_LEVEL" default:"debug"`
ValueExtractor valueExtractor `envconfig:"EXTRACTOR"`
Darktrace darktraceConfig `envconfig:"DARKTRACE" required:"true"`
}
Given func run -e DARKTRACE_PUBLIC_TOKEN=test only the enviromenment variables PORT and PWD are printed out by the Start function.
The text was updated successfully, but these errors were encountered:
This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.
We implemented a knative function using a go-lang handler.
This handler reads its configuration from environment variables retrieved via the envconfig library.
The environment variables are correctly parsed and read if the function is deployed on a cluster with the CLI via
func deploy
, so technically it works in our production environment.However when the function is run locally with
func run
there is no way to pass the environment variables to the function.func run -e 'URL=http://example.com'
orfunc run --env 'URL=http://example.com'
does not seem to work properly and passes nothing into our function. Setting the parameters in the func.yaml also does not pass them into the function whenfunc run
is used, but works perfectly fine withfunc deploy
.The Start function looks like the following:
The config.go looks like this:
Given
func run -e DARKTRACE_PUBLIC_TOKEN=test
only the enviromenment variables PORT and PWD are printed out by the Start function.The text was updated successfully, but these errors were encountered: