From 2b9fb85f4b86be4cdbeb0122c88cc3188622a431 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Tue, 3 Mar 2020 15:33:33 +0000 Subject: [PATCH] Don't from value_command when value_from file is present If a value_command is set and a value_from file is already on the disk, then do not regenerate the file. Fixes: #198 Tested e2e with k3d, and checked that the local file in /tmp/ was not re-created with a new value, when oauth was enabled. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- pkg/types/secrets.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/types/secrets.go b/pkg/types/secrets.go index fb4d214..befb746 100644 --- a/pkg/types/secrets.go +++ b/pkg/types/secrets.go @@ -34,19 +34,24 @@ func BuildSecretTask(kvn KeyValueNamespaceTuple) execute.ExecTask { } for _, file := range kvn.Files { + filePath := file.ExpandValueFrom() if len(file.ValueCommand) > 0 { + if _, err := os.Stat(filePath); err != nil { - valueTask := execute.ExecTask{ - Command: file.ValueCommand, - StreamStdio: true, - } - res, err := valueTask.Execute() - if err != nil { - log.Fatal(fmt.Errorf("error executing value_command: %s", file.ValueCommand)) - } + valueTask := execute.ExecTask{ + Command: file.ValueCommand, + StreamStdio: true, + } + res, err := valueTask.Execute() + if err != nil { + log.Fatal(fmt.Errorf("error executing value_command: %s", file.ValueCommand)) + } - if res.ExitCode != 0 { - log.Fatal(fmt.Errorf("error running value_command: %s, stderr: %s", file.ValueCommand, res.Stderr)) + if res.ExitCode != 0 { + log.Fatal(fmt.Errorf("error running value_command: %s, stderr: %s", file.ValueCommand, res.Stderr)) + } + } else { + fmt.Printf("%s exists, not running value_command\n", filePath) } }