diff --git a/internal/task/step/shell.go b/internal/task/step/shell.go index e002e1cac..722de5e4b 100644 --- a/internal/task/step/shell.go +++ b/internal/task/step/shell.go @@ -29,6 +29,7 @@ import ( "os" "strings" + comm "github.com/opencurve/curveadm/internal/common" "github.com/opencurve/curveadm/internal/errno" "github.com/opencurve/curveadm/internal/task/context" "github.com/opencurve/curveadm/internal/utils" @@ -475,6 +476,15 @@ func (s *UnixName) Execute(ctx *context.Context) error { } func (s *ModInfo) Execute(ctx *context.Context) error { + isWsl2, err := ctx.Module().Shell().IsWsl2() + if err == nil && isWsl2 { + // NOTE: FUSE is statically compiled into the WSL2 kernel + // See also: https://github.com/microsoft/WSL/issues/17#issuecomment-759817472 + if s.Name == comm.KERNERL_MODULE_FUSE { + *s.Success = true + return nil + } + } cmd := ctx.Module().Shell().ModInfo(s.Name) out, err := cmd.Execute(s.ExecOptions) return PostHandle(s.Success, s.Out, out, err, errno.ERR_GET_KERNEL_MODULE_INFO_FAILED) diff --git a/pkg/module/shell.go b/pkg/module/shell.go index b9f246a6f..84f345c21 100644 --- a/pkg/module/shell.go +++ b/pkg/module/shell.go @@ -112,6 +112,18 @@ func (s *Shell) Execute(options ExecOptions) (string, error) { return execCommand(s.sshClient, s.tmpl, s.data, options) } +func (s *Shell) IsWsl2() (isWsl2 bool, err error) { + cmd := s.Command("uname -a | grep \"WSL2\" | wc -l") + out, err := cmd.Execute(ExecOptions{}) + if err != nil { + return + } + if out != "" && out[0] == '1' { + isWsl2 = true + } + return +} + // text func (s *Shell) Sed(file ...string) *Shell { s.tmpl = template.Must(template.New("sed").Parse(TEMPLATE_SED))