Skip to content

Commit

Permalink
enable the file cache in sidecar mounter
Browse files Browse the repository at this point in the history
  • Loading branch information
songjiaxun committed Feb 14, 2024
1 parent eb3dfc1 commit a71bd7e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
7 changes: 7 additions & 0 deletions pkg/sidecar_mounter/sidecar_mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type MountConfig struct {
VolumeName string `json:"volumeName,omitempty"`
BucketName string `json:"bucketName,omitempty"`
BufferDir string `json:"-"`
CacheDir string `json:"-"`
ConfigFile string `json:"-"`
Options []string `json:"options,omitempty"`
ErrWriter io.Writer `json:"-"`
Expand Down Expand Up @@ -126,8 +127,10 @@ var disallowedFlags = map[string]bool{
"logging:log-rotate:max-file-size-mb": true,
"logging:log-rotate:backup-file-count": true,
"logging:log-rotate:compress": true,
"cache-location": true,
}

// TODO: move experimental-local-file-cache flag to disallowedFlags when the file cache feature is ready.
var boolFlags = map[string]bool{
"implicit-dirs": true,
"experimental-local-file-cache": true,
Expand All @@ -152,6 +155,7 @@ func NewMountConfig(sp string) (*MountConfig, error) {
mc := MountConfig{
VolumeName: volumeName,
BufferDir: filepath.Join(webhook.SidecarContainerBufferVolumeMountPath, ".volumes", volumeName),
CacheDir: filepath.Join(webhook.SidecarContainerCacheVolumeMountPath, ".volumes", volumeName),
ConfigFile: filepath.Join(webhook.SidecarContainerTmpVolumeMountPath, ".volumes", volumeName, "config.yaml"),
}

Expand Down Expand Up @@ -197,6 +201,7 @@ func (mc *MountConfig) prepareMountArgs() (map[string]string, map[string]string)
configFileFlagMap := map[string]string{
"logging:file-path": "/dev/fd/1", // redirect the output to cmd stdout
"logging:format": "text",
"cache-location": mc.CacheDir,
}

invalidArgs := []string{}
Expand Down Expand Up @@ -272,6 +277,8 @@ func (mc *MountConfig) prepareConfigFile(flagMap map[string]string) error {

if boolVal, err := strconv.ParseBool(v); err == nil {
curLevel[t] = boolVal
} else if intVal, err := strconv.ParseInt(v, 10, 64); err == nil {
curLevel[t] = intVal
} else {
curLevel[t] = v
}
Expand Down
23 changes: 19 additions & 4 deletions pkg/sidecar_mounter/sidecar_mounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
defaultConfigFileFlagMap = map[string]string{
"logging:file-path": "/dev/fd/1",
"logging:format": "text",
"cache-location": "test-cache-dir",
}

invalidArgs = []string{
Expand Down Expand Up @@ -71,6 +72,7 @@ func TestPrepareMountArgs(t *testing.T) {
mc: &MountConfig{
BucketName: "test-bucket",
BufferDir: "test-buffer-dir",
CacheDir: "test-cache-dir",
ConfigFile: "test-config-file",
},
expectedArgs: defaultFlagMap,
Expand All @@ -81,6 +83,7 @@ func TestPrepareMountArgs(t *testing.T) {
mc: &MountConfig{
BucketName: "test-bucket",
BufferDir: "test-buffer-dir",
CacheDir: "test-cache-dir",
ConfigFile: "test-config-file",
Options: []string{"uid=100", "gid=200", "debug_gcs", "max-conns-per-host=10", "implicit-dirs", "write:create-empty-file:false", "logging:severity:error", "write:create-empty-file:true"},
},
Expand All @@ -100,13 +103,15 @@ func TestPrepareMountArgs(t *testing.T) {
"logging:format": "text",
"logging:severity": "error",
"write:create-empty-file": "true",
"cache-location": "test-cache-dir",
},
},
{
name: "should return valid args with bool options correctly",
mc: &MountConfig{
BucketName: "test-bucket",
BufferDir: "test-buffer-dir",
CacheDir: "test-cache-dir",
ConfigFile: "test-config-file",
Options: []string{"uid=100", "gid=200", "debug_gcs", "max-conns-per-host=10", "implicit-dirs=true"},
},
Expand All @@ -128,6 +133,7 @@ func TestPrepareMountArgs(t *testing.T) {
mc: &MountConfig{
BucketName: "test-bucket",
BufferDir: "test-buffer-dir",
CacheDir: "test-cache-dir",
ConfigFile: "test-config-file",
Options: invalidArgs,
},
Expand All @@ -139,6 +145,7 @@ func TestPrepareMountArgs(t *testing.T) {
mc: &MountConfig{
BucketName: "test-bucket",
BufferDir: "test-buffer-dir",
CacheDir: "test-cache-dir",
ConfigFile: "test-config-file",
Options: []string{"app-name=Vertex"},
},
Expand Down Expand Up @@ -184,10 +191,13 @@ func TestPrepareConfigFile(t *testing.T) {
ConfigFile: "./test-config-file.yaml",
},
configMapArgs: map[string]string{
"logging:file-path": "/dev/fd/1",
"logging:format": "text",
"logging:severity": "error",
"write:create-empty-file": "true",
"logging:file-path": "/dev/fd/1",
"logging:format": "text",
"logging:severity": "error",
"write:create-empty-file": "true",
"file-cache:max-size-in-mb": "10000",
"file-cache:cache-file-for-range-read": "true",
"cache-location": "/gcsfuse-cache/.volumes/volume-name",
},
expectedConfig: map[string]interface{}{
"logging": map[string]interface{}{
Expand All @@ -198,6 +208,11 @@ func TestPrepareConfigFile(t *testing.T) {
"write": map[string]interface{}{
"create-empty-file": true,
},
"file-cache": map[string]interface{}{
"max-size-in-mb": 10000,
"cache-file-for-range-read": true,
},
"cache-location": "/gcsfuse-cache/.volumes/volume-name",
},
},
{
Expand Down

0 comments on commit a71bd7e

Please sign in to comment.