Skip to content

Commit 0698c68

Browse files
committed
no panic, if no params
1 parent 03c4f6e commit 0698c68

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/stretchr/testify v1.4.0
1212
github.com/urfave/cli/v2 v2.0.0
1313
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
14+
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e
1415
google.golang.org/api v0.15.0 // indirect
1516
google.golang.org/genproto v0.0.0-20191220175831-5c49e3ecc1c1
1617
)

main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
log "github.com/sirupsen/logrus"
1818
"github.com/urfave/cli/v2"
19+
"golang.org/x/sys/unix"
1920
)
2021

2122
var (
@@ -119,6 +120,11 @@ func run(ctx context.Context, provider secrets.Provider, commandSlice []string)
119120
var commandStr string
120121
var argsSlice []string
121122

123+
if len(commandSlice) == 0 {
124+
log.Warn("no command specified")
125+
return nil
126+
}
127+
122128
// split command and arguments
123129
commandStr = commandSlice[0]
124130
// if there is args
@@ -170,7 +176,7 @@ func run(ctx context.Context, provider secrets.Provider, commandSlice []string)
170176
"pid": cmd.Process.Pid,
171177
"path": cmd.Path,
172178
"args": cmd.Args,
173-
"signal": sig,
179+
"signal": unix.SignalName(sig.(syscall.Signal)),
174180
}).WithError(e).Error("failed to send system signal to the process")
175181
}
176182
}

test.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: secretmanagerdemo
5+
spec:
6+
replicas: 1
7+
template:
8+
metadata:
9+
labels:
10+
app: secretmanagerdemo
11+
spec:
12+
serviceAccountName: secrets-init-demo-sa
13+
initContainers:
14+
- name: secrets-init
15+
image: doitintl/secrets-init:v0.2.6
16+
command:
17+
- sh
18+
args:
19+
- -c
20+
- "cp /usr/local/bin/secrets-init /secrets-init/bin/"
21+
volumeMounts:
22+
- mountPath: /secrets-init/bin
23+
name: secrets-init-volume
24+
containers:
25+
- image: alpine:3
26+
name: print-env
27+
env:
28+
- name: TEST_SECRET
29+
value: gcp:secretmanager:projects/240804453656/secrets/test-secret
30+
command:
31+
- /secrets-init/bin/secrets-init
32+
args:
33+
- --provider
34+
- google
35+
- sh
36+
- -c
37+
- 'echo test-secret=$TEST_SECRET; tail -f /dev/null'
38+
volumeMounts:
39+
- mountPath: /secrets-init/bin
40+
name: secrets-init-volume
41+
volumes:
42+
- name: secrets-init-volume
43+
emptyDir: {}

0 commit comments

Comments
 (0)