-
Notifications
You must be signed in to change notification settings - Fork 10
/
gcp.go
54 lines (43 loc) · 1.36 KB
/
gcp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
corev1 "k8s.io/api/core/v1"
)
type gcp struct {
config struct {
enabled bool
projectID string
secretName string
secretVersion string
serviceAccountKeySecretName string
}
}
func (gcp *gcp) mutateContainer(container corev1.Container) corev1.Container {
container = gcp.setArgs(container)
// Mount google service account key if given
if gcp.config.serviceAccountKeySecretName != "" {
container.VolumeMounts = append(container.VolumeMounts, []corev1.VolumeMount{
{
Name: VolumeMountGoogleCloudKeyName,
MountPath: VolumeMountGoogleCloudKeyPath,
},
}...)
}
return container
}
func (gcp *gcp) setArgs(c corev1.Container) corev1.Container {
args := []string{"gcp"}
args = append(args, fmt.Sprintf("--project-id=%s", gcp.config.projectID))
if gcp.config.secretName != "" {
args = append(args, fmt.Sprintf("--secret-name=%s", gcp.config.secretName))
}
if gcp.config.secretVersion != "" {
args = append(args, fmt.Sprintf("--secret-version=%s", gcp.config.secretVersion))
}
if gcp.config.secretName != "" {
args = append(args, fmt.Sprintf("--google-application-credentials=%s", fmt.Sprintf("%s/%s", VolumeMountGoogleCloudKeyPath, GCPServiceAccountCredentialsFileName)))
}
args = append(args, "--")
c.Args = append(args, c.Args...)
return c
}