func NewMountConfig()

in pkg/sidecar_mounter/sidecar_mounter_config.go [98:153]


func NewMountConfig(sp string) *MountConfig {
	// socket path pattern: /gcsfuse-tmp/.volumes/<volume-name>/socket
	tempDir := filepath.Dir(sp)
	volumeName := filepath.Base(tempDir)
	mc := MountConfig{
		VolumeName: volumeName,
		BufferDir:  filepath.Join(webhook.SidecarContainerBufferVolumeMountPath, ".volumes", volumeName),
		CacheDir:   filepath.Join(webhook.SidecarContainerCacheVolumeMountPath, ".volumes", volumeName),
		TempDir:    tempDir,
		ConfigFile: filepath.Join(webhook.SidecarContainerTmpVolumeMountPath, ".volumes", volumeName, "config.yaml"),
		ErrWriter:  NewErrorWriter(filepath.Join(tempDir, "error")),
	}

	klog.Infof("connecting to socket %q", sp)
	c, err := net.Dial("unix", sp)
	if err != nil {
		mc.ErrWriter.WriteMsg(fmt.Sprintf("failed to connect to the socket %q: %v", sp, err))

		return nil
	}

	fd, msg, err := util.RecvMsg(c)
	if err != nil {
		mc.ErrWriter.WriteMsg(fmt.Sprintf("failed to receive mount options from the socket %q: %v", sp, err))

		return nil
	}
	// as we got all the information from the socket, closing the connection and deleting the socket
	c.Close()
	if err = syscall.Unlink(sp); err != nil {
		klog.Errorf("failed to close socket %q: %v", sp, err)
	}

	mc.FileDescriptor = fd

	if err := json.Unmarshal(msg, &mc); err != nil {
		mc.ErrWriter.WriteMsg(fmt.Sprintf("failed to unmarshal the mount config: %v", err))

		return nil
	}

	if mc.BucketName == "" {
		mc.ErrWriter.WriteMsg("failed to fetch bucket name from CSI driver")

		return nil
	}

	mc.prepareMountArgs()
	if err := mc.prepareConfigFile(); err != nil {
		mc.ErrWriter.WriteMsg(fmt.Sprintf("failed to create config file %q: %v", mc.ConfigFile, err))

		return nil
	}

	return &mc
}