Skip to content

Commit 0396d3f

Browse files
committed
consolidate if statements
1 parent 62aef0b commit 0396d3f

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

server.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,20 @@ func mutateHandler(w http.ResponseWriter, r *http.Request) {
120120
ReadOnly: true,
121121
}
122122

123-
// Define the env var
124123
if needsCreds {
124+
// Define the env var
125125
e := corev1.EnvVar{
126126
Name: "GOOGLE_APPLICATION_CREDENTIALS",
127127
Value: "/google-app-creds.json",
128128
}
129129
envVars = append(envVars, e)
130+
131+
// add the volume in the list of patches
132+
patch = append(patch, patchOperation{
133+
Op: "add",
134+
Path: "/spec/volumes",
135+
Value: append(pod.Spec.Volumes, v),
136+
})
130137
}
131138

132139
// If GOOGLE_CLOUD_PROJECT is set in the VM, set it for all GCP apps.
@@ -145,14 +152,6 @@ func mutateHandler(w http.ResponseWriter, r *http.Request) {
145152
}
146153
}
147154

148-
if needsCreds {
149-
patch = append(patch, patchOperation{
150-
Op: "add",
151-
Path: "/spec/volumes",
152-
Value: append(pod.Spec.Volumes, v),
153-
})
154-
}
155-
156155
if len(envVars) > 0 {
157156
for i, c := range pod.Spec.Containers {
158157
if needsCreds {

0 commit comments

Comments
 (0)