Skip to content

Commit

Permalink
fix(preflight): check the system default NFS version in mount config
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn-9830

Signed-off-by: Raphanus Lo <[email protected]>
(cherry picked from commit b6af7b9)
  • Loading branch information
Raphanus Lo authored and COLDTURNIP committed Dec 12, 2024
1 parent 68aa828 commit bad0b20
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 70 deletions.
4 changes: 2 additions & 2 deletions docs/longhornctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ CLI for Longhorn troubleshooting and operations.

```
-h, --help help for longhornctl
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string log level (trace, debug, info, warn, error, fatal, panic) (default "info")
```
Expand All @@ -26,4 +26,4 @@ CLI for Longhorn troubleshooting and operations.
* [longhornctl trim](longhornctl_trim.md) - Longhorn trimming operations
* [longhornctl version](longhornctl_version.md) - Print longhornctl version

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_check.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Longhorn checking operations

```
-h, --help help for check
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
```
Expand All @@ -16,4 +16,4 @@ Longhorn checking operations
* [longhornctl](longhornctl.md) - Longhorn commandline interface.
* [longhornctl check preflight](longhornctl_check_preflight.md) - Check Longhorn preflight

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
6 changes: 3 additions & 3 deletions docs/longhornctl_check_preflight.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ INFO[2024-07-16T17:17:42+08:00] Completed preflight checker
--enable-spdk Enable checking of SPDK required packages, modules, and setup.
-h, --help help for preflight
--huge-page-size int Specify the huge page size in MiB for SPDK. (default 2048)
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
--userspace-driver string Userspace I/O driver for SPDK. (default "vfio_pci")
--userspace-driver string Userspace I/O driver for SPDK.
```

### SEE ALSO

* [longhornctl check](longhornctl_check.md) - Longhorn checking operations

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ longhornctl doc [output directory] [flags]
### Options inherited from parent commands

```
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string log level (trace, debug, info, warn, error, fatal, panic) (default "info")
```
Expand All @@ -28,4 +28,4 @@ longhornctl doc [output directory] [flags]

* [longhornctl](longhornctl.md) - Longhorn commandline interface.

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_export.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Export Longhorn resources

```
-h, --help help for export
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
```
Expand All @@ -16,4 +16,4 @@ Export Longhorn resources
* [longhornctl](longhornctl.md) - Longhorn commandline interface.
* [longhornctl export replica](longhornctl_export_replica.md) - Export Longhorn replica

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
6 changes: 3 additions & 3 deletions docs/longhornctl_export_replica.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ lost+found

```
--data-dir string Specify the Longhorn data directory. If not provided, the default will be attempted, or it will fall back to the directory of longhorn-disk.cfg. (default "/var/lib/longhorn")
--engine-image string Engine image to use to create volume from the replica. (default "longhornio/longhorn-engine:v1.7.0-rc2")
--engine-image string Engine image to use to create volume from the replica. (default "longhornio/longhorn-engine:v1.7.2")
-h, --help help for replica
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
--name string Specify the replica directory name to export. The replica data directory name is not the same as the Kubernetes Replica custom resource (CR) object name. To retrieve the replica directory name, use 'longhornctl get replica'.
Expand All @@ -62,4 +62,4 @@ lost+found
* [longhornctl export](longhornctl_export.md) - Export Longhorn resources
* [longhornctl export replica stop](longhornctl_export_replica_stop.md) - Stop exporting Longhorn replica

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_export_replica_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ INFO[2024-07-16T17:29:14+08:00] Successfully stopped exporting replica

```
-h, --help help for stop
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
```
Expand All @@ -31,4 +31,4 @@ INFO[2024-07-16T17:29:14+08:00] Successfully stopped exporting replica

* [longhornctl export replica](longhornctl_export_replica.md) - Export Longhorn replica

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Longhorn information gathering operations

```
-h, --help help for get
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
```
Expand All @@ -16,4 +16,4 @@ Longhorn information gathering operations
* [longhornctl](longhornctl.md) - Longhorn commandline interface.
* [longhornctl get replica](longhornctl_get_replica.md) - Get Longhorn replica information

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_get_replica.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ INFO[2024-07-16T17:23:51+08:00] Completed replica getter
```
--data-dir string Specify the Longhorn data directory. If not provided, the default will be attempted, or it will fall back to the directory of longhorn-disk.cfg. (default "/var/lib/longhorn")
-h, --help help for replica
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
--name string Specify the name of the replica to retrieve information.
Expand All @@ -60,4 +60,4 @@ INFO[2024-07-16T17:23:51+08:00] Completed replica getter

* [longhornctl get](longhornctl_get.md) - Longhorn information gathering operations

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_global-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ longhornctl global-options [flags]
### Options inherited from parent commands

```
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string log level (trace, debug, info, warn, error, fatal, panic) (default "info")
```
Expand All @@ -28,4 +28,4 @@ longhornctl global-options [flags]

* [longhornctl](longhornctl.md) - Longhorn commandline interface.

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Longhorn installation operations

```
-h, --help help for install
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
```
Expand All @@ -16,4 +16,4 @@ Longhorn installation operations
* [longhornctl](longhornctl.md) - Longhorn commandline interface.
* [longhornctl install preflight](longhornctl_install_preflight.md) - Install Longhorn preflight

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
6 changes: 3 additions & 3 deletions docs/longhornctl_install_preflight.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ INFO[2024-07-16T17:09:08+08:00] Completed preflight installer. Use 'longhornctl

```
--allow-pci string Specify a comma-separated (,) list of allowed PCI devices. By default, all PCI devices are blocked by a non-valid address. (default "none")
--driver-override string Userspace driver for device bindings. Override default driver for PCI devices. (default "vfio_pci")
--driver-override string Userspace driver for device bindings. Override default driver for PCI devices.
--enable-spdk Enable installation of SPDK required packages, modules, and setup.
-h, --help help for preflight
--huge-page-size int Specify the huge page size in MiB for SPDK. (default 2048)
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
--operating-system string Specify the operating system ("", cos). Leave this empty to use the package manager for installation.
Expand All @@ -45,4 +45,4 @@ INFO[2024-07-16T17:09:08+08:00] Completed preflight installer. Use 'longhornctl
* [longhornctl install](longhornctl_install.md) - Longhorn installation operations
* [longhornctl install preflight stop](longhornctl_install_preflight_stop.md) - Stop Longhorn preflight installer

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_install_preflight_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ INFO[2024-07-16T17:21:32+08:00] Successfully stopped preflight installer

```
-h, --help help for stop
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
--operating-system string Specify the operating system ("", cos). Leave this empty to use the package manager for installation.
Expand All @@ -32,4 +32,4 @@ INFO[2024-07-16T17:21:32+08:00] Successfully stopped preflight installer

* [longhornctl install preflight](longhornctl_install_preflight.md) - Install Longhorn preflight

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_trim.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Longhorn trimming operations

```
-h, --help help for trim
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
```
Expand All @@ -16,4 +16,4 @@ Longhorn trimming operations
* [longhornctl](longhornctl.md) - Longhorn commandline interface.
* [longhornctl trim volume](longhornctl_trim_volume.md) - Trim a Longhorn volume

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_trim_volume.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ INFO[2024-07-16T17:32:01+08:00] Completed volume trimmer vo

```
-h, --help help for volume
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string Log level (default "info")
--longhorn-namespace string Namespace where Longhorn is deployed within the Kubernetes cluster. (default "longhorn-system")
Expand All @@ -42,4 +42,4 @@ INFO[2024-07-16T17:32:01+08:00] Completed volume trimmer vo

* [longhornctl trim](longhornctl_trim.md) - Longhorn trimming operations

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
4 changes: 2 additions & 2 deletions docs/longhornctl_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ longhornctl version [flags]
### Options inherited from parent commands

```
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.0-rc2")
--image string Image containing longhornctl-local (default "longhornio/longhorn-cli:v1.7.2")
--kube-config string Kubernetes config (kubeconfig) path
-l, --log-level string log level (trace, debug, info, warn, error, fatal, panic) (default "info")
```
Expand All @@ -24,4 +24,4 @@ longhornctl version [flags]

* [longhornctl](longhornctl.md) - Longhorn commandline interface.

###### Auto generated by spf13/cobra on 26-Jul-2024
###### Auto generated by spf13/cobra on 12-Dec-2024
80 changes: 45 additions & 35 deletions pkg/local/preflight/checker.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package preflight

import (
"bufio"
"encoding/json"
"fmt"
"os"
"path/filepath"
"runtime"
"strconv"
Expand All @@ -17,7 +15,9 @@ import (
kubeclient "k8s.io/client-go/kubernetes"

lhgokube "github.com/longhorn/go-common-libs/kubernetes"
lhnfs "github.com/longhorn/go-common-libs/nfs"
lhgons "github.com/longhorn/go-common-libs/ns"
lhsys "github.com/longhorn/go-common-libs/sys"
lhgotypes "github.com/longhorn/go-common-libs/types"

"github.com/longhorn/cli/pkg/consts"
Expand Down Expand Up @@ -420,52 +420,62 @@ func (local *Checker) checkModulesLoaded(spdkDependent bool) error {
func (local *Checker) checkNFSv4Support() error {
logrus.Info("Checking if NFS4 (either 4.0, 4.1 or 4.2) is supported")

// check kernel capability
var isKernelSupport = false

kernelVersion, err := utils.GetKernelVersion()
if err != nil {
return err
}
kernelConfigPath := "/boot/config-" + kernelVersion
kernelConfigPath = filepath.Join(consts.VolumeMountHostDirectory, kernelConfigPath)
configFile, err := os.Open(kernelConfigPath)
hostBootDir := filepath.Join(consts.VolumeMountHostDirectory, lhgotypes.SysBootDirectory)
kernelConfigMap, err := lhsys.GetBootKernelConfigMap(hostBootDir, kernelVersion)
if err != nil {
return err
}
defer func(configFile *os.File) {
_ = configFile.Close()
}(configFile)

scanner := bufio.NewScanner(configFile)

for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "CONFIG_NFS_V4_2=") ||
strings.HasPrefix(line, "CONFIG_NFS_V4_1=") ||
strings.HasPrefix(line, "CONFIG_NFS_V4=") {
option := strings.Split(line, "=")
if len(option) == 2 {
if option[1] == "y" {
local.collection.Log.Info = append(local.collection.Log.Info, "NFS4 is supported")
return nil
} else if option[1] == "m" {
// Check if the module is loaded
moduleLoaded, err := utils.IsModuleLoaded(option[0])
if err != nil {
continue
}
if moduleLoaded {
local.collection.Log.Info = append(local.collection.Log.Info, "NFS4 is supported")
return nil
}
}
for configItem, module := range map[string]string{"CONFIG_NFS_V4_2": "nfs", "CONFIG_NFS_V4_1": "nfs", "CONFIG_NFS_V4": "nfs"} {
if configVal, exist := kernelConfigMap[configItem]; !exist {
continue
} else if configVal == "y" {
isKernelSupport = true
break
} else if configVal == "m" {
// Check if the module is loaded
moduleLoaded, err := utils.IsModuleLoaded(module)
if err != nil {
continue
}
if moduleLoaded {
isKernelSupport = true
break
}
}
}

if err := scanner.Err(); err != nil {
return errors.Wrap(err, "failed to check NFS4 support")
if !isKernelSupport {
local.collection.Log.Error = append(local.collection.Log.Error, "NFS4 is not supported")
return nil
}

// check default NFS protocol version
var isSupportedNFSVersion bool

hostEtcDir := filepath.Join(consts.VolumeMountHostDirectory, lhgotypes.SysEtcDirectory)
nfsMajor, nfsMinor, err := lhnfs.GetSystemDefaultNFSVersion(hostEtcDir)
if err == nil {
isSupportedNFSVersion = nfsMajor == 4 && (nfsMinor == 0 || nfsMinor == 1 || nfsMinor == 2)
} else if errors.Is(err, lhgotypes.ErrNotConfigured) {
// NFSv4 by default
isSupportedNFSVersion = true
} else {
local.collection.Log.Error = append(local.collection.Log.Error, "Failed to read NFS mount config")
return err
}

if !isSupportedNFSVersion {
local.collection.Log.Warn = append(local.collection.Log.Warn, "NFS4 is supported, but default protocol version is not 4, 4.1, or 4.2. Please refer to the NFS mount configuration manual page for more information: man 5 nfsmount.conf")
}

local.collection.Log.Error = append(local.collection.Log.Error, "NFS4 is not supported")
local.collection.Log.Info = append(local.collection.Log.Info, "NFS4 is supported")
return nil
}

Expand Down
Loading

0 comments on commit bad0b20

Please sign in to comment.