Skip to content

Commit 4317e4b

Browse files
authored
Merge pull request #1086 from jdnurme/custom-endpoint-fix
add fix and corresponding tests
2 parents 40d1c24 + b937cf5 commit 4317e4b

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

pkg/sidecar_mounter/sidecar_mounter_config.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,18 @@ func (mc *MountConfig) prepareMountArgs() {
206206
for _, arg := range mc.Options {
207207
klog.Infof("processing mount arg %v", arg)
208208

209-
if strings.Contains(arg, ":") && !strings.Contains(arg, "https") {
210-
i := strings.LastIndex(arg, ":")
211-
f, v := arg[:i], arg[i+1:]
212-
209+
// Config file flags are identified by not containing '=' and containing ':'.
210+
// e.g., "logging:severity:error"
211+
if !strings.Contains(arg, "=") && strings.Contains(arg, ":") && !strings.Contains(arg, "https") {
212+
var f, v string
213+
if strings.HasPrefix(arg, "gcs-connection:custom-endpoint:") {
214+
parts := strings.SplitN(arg, ":", 3)
215+
f = parts[0] + ":" + parts[1]
216+
v = parts[2]
217+
} else {
218+
i := strings.LastIndex(arg, ":")
219+
f, v = arg[:i], arg[i+1:]
220+
}
213221
if f == util.DisableMetricsForGKE {
214222
if v == util.TrueStr {
215223
flagMap["prometheus-port"] = "0"

pkg/sidecar_mounter/sidecar_mounter_config_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,43 @@ func TestPrepareMountArgs(t *testing.T) {
301301
"cache-dir": "/gcsfuse-file-cache-ephemeral-disk/.volumes/volume-name",
302302
},
303303
},
304+
{
305+
name: "should correctly parse custom-endpoint with a port",
306+
mc: &MountConfig{
307+
BucketName: "test-bucket",
308+
BufferDir: "test-buffer-dir",
309+
CacheDir: "test-cache-dir",
310+
ConfigFile: "test-config-file",
311+
Options: []string{"gcs-connection:custom-endpoint:custom-service.my-system.svc.cluster.local:8080"},
312+
},
313+
expectedArgs: defaultFlagMap,
314+
expectedConfigMapArgs: map[string]string{
315+
"logging:file-path": "/dev/fd/1",
316+
"logging:format": "json",
317+
"cache-dir": "",
318+
"gcs-connection:custom-endpoint": "custom-service.my-system.svc.cluster.local:8080",
319+
},
320+
},
321+
{
322+
name: "should correctly parse custom-endpoint with a port in CLI format",
323+
mc: &MountConfig{
324+
BucketName: "test-bucket",
325+
BufferDir: "test-buffer-dir",
326+
CacheDir: "test-cache-dir",
327+
ConfigFile: "test-config-file",
328+
Options: []string{"custom-endpoint=custom-service.my-system.svc.cluster.local:8080"},
329+
},
330+
expectedArgs: map[string]string{
331+
"app-name": GCSFuseAppName,
332+
"temp-dir": "test-buffer-dir/temp-dir",
333+
"config-file": "test-config-file",
334+
"foreground": "",
335+
"uid": "0",
336+
"gid": "0",
337+
"custom-endpoint": "custom-service.my-system.svc.cluster.local:8080",
338+
},
339+
expectedConfigMapArgs: defaultConfigFileFlagMap,
340+
},
304341
}
305342

306343
testPrometheusPort := prometheusPort

0 commit comments

Comments
 (0)