Include environment variables from the additional env file in the environment annotation.

This commit is contained in:
John Brownlee 2022-07-11 21:16:32 -07:00
parent a7978ce009
commit 123dc7bb32
2 changed files with 11 additions and 8 deletions

View File

@ -69,7 +69,7 @@ type Argument struct {
Offset int `json:"offset,omitempty"`
// IPFamily provides the family to use for IPList type arguments.
IPFamily int `json:"ipFamily,omitEmpty"`
IPFamily int `json:"ipFamily,omitempty"`
}
// ArgumentType defines the types for arguments.
@ -121,9 +121,9 @@ func (argument Argument) GenerateArgument(processNumber int, env map[string]stri
number = number + argument.Offset
return strconv.Itoa(number), nil
case EnvironmentArgumentType:
return argument.lookupEnv(env)
return argument.LookupEnv(env)
case IPListArgumentType:
envValue, err := argument.lookupEnv(env)
envValue, err := argument.LookupEnv(env)
if err != nil {
return "", err
}
@ -153,7 +153,7 @@ func (argument Argument) GenerateArgument(processNumber int, env map[string]stri
}
// lookupEnv looks up the value for an argument from the environment.
func (argument Argument) lookupEnv(env map[string]string) (string, error) {
func (argument Argument) LookupEnv(env map[string]string) (string, error) {
var value string
var present bool
if env != nil {

View File

@ -96,13 +96,16 @@ func CreatePodClient(logger logr.Logger) (*PodClient, error) {
// retrieveEnvironmentVariables extracts the environment variables we have for
// an argument into a map.
func retrieveEnvironmentVariables(argument api.Argument, target map[string]string) {
func retrieveEnvironmentVariables(monitor *Monitor, argument api.Argument, target map[string]string) {
if argument.Source != "" {
target[argument.Source] = os.Getenv(argument.Source)
value, err := argument.LookupEnv(monitor.CustomEnvironment)
if err == nil {
target[argument.Source] = value
}
}
if argument.Values != nil {
for _, childArgument := range argument.Values {
retrieveEnvironmentVariables(childArgument, target)
retrieveEnvironmentVariables(monitor, childArgument, target)
}
}
}
@ -112,7 +115,7 @@ func retrieveEnvironmentVariables(argument api.Argument, target map[string]strin
func (client *PodClient) UpdateAnnotations(monitor *Monitor) error {
environment := make(map[string]string)
for _, argument := range monitor.ActiveConfiguration.Arguments {
retrieveEnvironmentVariables(argument, environment)
retrieveEnvironmentVariables(monitor, argument, environment)
}
environment["BINARY_DIR"] = path.Dir(monitor.ActiveConfiguration.BinaryPath)
jsonEnvironment, err := json.Marshal(environment)