Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Don't from value_command when value_from file is present
Browse files Browse the repository at this point in the history
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) <[email protected]>
  • Loading branch information
alexellis committed Mar 3, 2020
1 parent ee11754 commit 2b9fb85
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pkg/types/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 2b9fb85

Please sign in to comment.