@@ -28,15 +28,17 @@ import (
2828 "syscall"
2929 "time"
3030
31+ driver "github.com/googlecloudplatform/gcs-fuse-csi-driver/pkg/csi_driver"
3132 sidecarmounter "github.com/googlecloudplatform/gcs-fuse-csi-driver/pkg/sidecar_mounter"
3233 "github.com/googlecloudplatform/gcs-fuse-csi-driver/pkg/webhook"
3334 "k8s.io/klog/v2"
3435)
3536
3637var (
37- gcsfusePath = flag .String ("gcsfuse-path" , "/gcsfuse" , "gcsfuse path" )
38- volumeBasePath = flag .String ("volume-base-path" , webhook .SidecarContainerTmpVolumeMountPath + "/.volumes" , "volume base path" )
39- _ = flag .Int ("grace-period" , 0 , "grace period for gcsfuse termination. This flag has been deprecated, has no effect and will be removed in the future." )
38+ gcsfusePath = flag .String ("gcsfuse-path" , "/gcsfuse" , "gcsfuse path" )
39+ volumeBasePath = flag .String ("volume-base-path" , webhook .SidecarContainerTmpVolumeMountPath + "/.volumes" , "volume base path" )
40+ disableAutoConfig = flag .Bool ("disable-autoconfig" , true , "disable defaulting configurations" )
41+ _ = flag .Int ("grace-period" , 0 , "grace period for gcsfuse termination. This flag has been deprecated, has no effect and will be removed in the future." )
4042 // This is set at compile time.
4143 version = "unknown"
4244)
@@ -55,13 +57,28 @@ func main() {
5557 mounter := sidecarmounter .New (* gcsfusePath )
5658 ctx , cancel := context .WithCancel (context .Background ())
5759
60+ machineType := ""
61+ volumePath := * volumeBasePath + driver .MachineTypePath
62+ klog .Infof ("Checking if machine-type file exists: %v" , volumePath )
63+ if _ , err := os .Stat (volumePath ); err == nil {
64+ machineTypeBytes , err := os .ReadFile (volumePath )
65+ if err != nil {
66+ klog .Fatalf ("failed to read machine-type file: %v" , err )
67+ }
68+ machineType = string (machineTypeBytes )
69+ }
70+
5871 for _ , sp := range socketPaths {
5972 // sleep 1.5 seconds before launch the next gcsfuse to avoid
6073 // 1. different gcsfuse logs mixed together.
6174 // 2. memory usage peak.
6275 time .Sleep (1500 * time .Millisecond )
6376 mc := sidecarmounter .NewMountConfig (sp )
6477 if mc != nil {
78+ // TODO: Pass machine-type to gcsfuse binary
79+ klog .Infof ("Setting machine type to gcsfuse binary %v" , machineType )
80+ mc .FlagMap ["machine-type" ] = machineType
81+ mc .FlagMap ["disable-autoconfig" ] = strconv .FormatBool (* disableAutoConfig )
6582 if err := mounter .Mount (ctx , mc ); err != nil {
6683 mc .ErrWriter .WriteMsg (fmt .Sprintf ("failed to mount bucket %q for volume %q: %v\n " , mc .BucketName , mc .VolumeName , err ))
6784 }
0 commit comments