From d508f509f4edba20a70f21b2087c65e4663becfa Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 7 Dec 2024 04:20:52 +0000 Subject: [PATCH] fix(deps): update patch digest dependencies --- go.mod | 4 +- go.sum | 4 +- .../longhorn/go-common-libs/sys/sys.go | 76 +++++++++++++++++++ .../longhorn/go-common-libs/types/error.go | 23 ++++++ .../longhorn/go-common-libs/types/nfs.go | 3 + .../longhorn/go-common-libs/types/sys.go | 5 ++ vendor/modules.txt | 2 +- 7 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 vendor/github.com/longhorn/go-common-libs/types/error.go create mode 100644 vendor/github.com/longhorn/go-common-libs/types/nfs.go diff --git a/go.mod b/go.mod index 17df142a..912971c4 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,10 @@ module github.com/longhorn/cli go 1.23 -toolchain go1.23.3 +toolchain go1.23.4 require ( - github.com/longhorn/go-common-libs v0.0.0-20241128023039-4d6c3a880dbc + github.com/longhorn/go-common-libs v0.0.0-20241206085105-b60ef86c0b25 github.com/longhorn/longhorn-manager v1.7.2 github.com/otiai10/copy v1.14.0 github.com/pkg/errors v0.9.1 diff --git a/go.sum b/go.sum index 976d6ac5..be782b89 100644 --- a/go.sum +++ b/go.sum @@ -102,8 +102,8 @@ github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhn github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE= github.com/lithammer/dedent v1.1.0 h1:VNzHMVCBNG1j0fh3OrsFRkVUwStdDArbgBWoPAffktY= github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc= -github.com/longhorn/go-common-libs v0.0.0-20241128023039-4d6c3a880dbc h1:Ok7qdNu2038Oj7tQNaKjFqP20NqokR31a3RVMV7ulms= -github.com/longhorn/go-common-libs v0.0.0-20241128023039-4d6c3a880dbc/go.mod h1:gSa+qB058kcNlCaOOwIFPHb3tvqMTmKcxtL7HPTS4o4= +github.com/longhorn/go-common-libs v0.0.0-20241206085105-b60ef86c0b25 h1:yAu164uaQUX/um0YqjEmMHUSX0JlnPRmwCQyE7Uit7o= +github.com/longhorn/go-common-libs v0.0.0-20241206085105-b60ef86c0b25/go.mod h1:gSa+qB058kcNlCaOOwIFPHb3tvqMTmKcxtL7HPTS4o4= github.com/longhorn/longhorn-manager v1.7.2 h1:hf0phTtk8Odq+zoVYO5JuHbKJOi4nK+iugUJ1FQw56M= github.com/longhorn/longhorn-manager v1.7.2/go.mod h1:QvOuwQP3TqICQHyJcPynjtAhF3TMCFeygVIpf9q7/cI= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= diff --git a/vendor/github.com/longhorn/go-common-libs/sys/sys.go b/vendor/github.com/longhorn/go-common-libs/sys/sys.go index 076d3dcc..576ae86d 100644 --- a/vendor/github.com/longhorn/go-common-libs/sys/sys.go +++ b/vendor/github.com/longhorn/go-common-libs/sys/sys.go @@ -1,7 +1,10 @@ package sys import ( + "bufio" + "compress/gzip" "fmt" + "io" "os" "path/filepath" "strconv" @@ -12,6 +15,8 @@ import ( "golang.org/x/sys/unix" "github.com/longhorn/go-common-libs/types" + + commonio "github.com/longhorn/go-common-libs/io" ) // GetKernelRelease returns the kernel release string. @@ -127,3 +132,74 @@ func getSystemBlockDeviceInfo(sysClassBlockDirectory string, readDirFn func(stri } return deviceInfo, nil } + +// GetBootKernelConfigMap reads the kernel config into a key-value map. It tries to read kernel config from +// ${bootDir}/config-${kernelVersion}, and comments are ignored. If the bootDir is empty, it points to /boot by default. +func GetBootKernelConfigMap(bootDir, kernelVersion string) (configMap map[string]string, err error) { + if kernelVersion == "" { + return nil, fmt.Errorf("kernelVersion cannot be empty") + } + if bootDir == "" { + bootDir = types.SysBootDirectory + } + + defer func() { + err = errors.Wrapf(err, "failed to get kernel config map from %s", bootDir) + }() + + configPath := filepath.Join(bootDir, "config-"+kernelVersion) + configContent, err := commonio.ReadFileContent(configPath) + if err != nil { + return nil, err + } + return parseKernelModuleConfigMap(strings.NewReader(configContent)) +} + +// GetProcKernelConfigMap reads the kernel config into a key-value map. It tries to read kernel config from +// procfs mounted at procDir from the view of processName in namespace. If the procDir is empty, it points to /proc by +// default. +func GetProcKernelConfigMap(procDir string) (configMap map[string]string, err error) { + if procDir == "" { + procDir = types.SysProcDirectory + } + + defer func() { + err = errors.Wrapf(err, "failed to get kernel config map from %s", procDir) + }() + + configPath := filepath.Join(procDir, types.SysKernelConfigGz) + configFile, err := os.Open(configPath) + if err != nil { + return nil, err + } + defer configFile.Close() + gzReader, err := gzip.NewReader(configFile) + if err != nil { + return nil, err + } + defer gzReader.Close() + return parseKernelModuleConfigMap(gzReader) +} + +// parseKernelModuleConfigMap parses the kernel config into key-value map. All commented items will be ignored. +func parseKernelModuleConfigMap(contentReader io.Reader) (map[string]string, error) { + configMap := map[string]string{} + + scanner := bufio.NewScanner(contentReader) + for scanner.Scan() { + config := scanner.Text() + if !strings.HasPrefix(config, "CONFIG_") { + continue + } + key, val, parsable := strings.Cut(config, "=") + if !parsable { + return nil, fmt.Errorf("failed to parse kernel config %s", config) + } + configMap[strings.TrimSpace(key)] = strings.TrimSpace(val) + } + + if err := scanner.Err(); err != nil { + return nil, err + } + return configMap, nil +} diff --git a/vendor/github.com/longhorn/go-common-libs/types/error.go b/vendor/github.com/longhorn/go-common-libs/types/error.go new file mode 100644 index 00000000..a4aa19c2 --- /dev/null +++ b/vendor/github.com/longhorn/go-common-libs/types/error.go @@ -0,0 +1,23 @@ +package types + +import "github.com/pkg/errors" + +var ( + // It is recommended to wrap the following common errors with meaningful message, so that the error handler can unwrap + // the underlying error and compare directly using errors.Is. For example: + // + // func GetSysConfig(filePath string) (string, error) { + // configVal, err := readConfig(filePath) + // if os.IsNotExist(err) { + // return fmt.Errorf("config file %q not present: %w", filePath, ErrNotConfigured) + // } + // ... + // } + // + // configVal, err := GetSysConfig(filePath) + // if errors.Is(err, types.ErrNotConfigured) { + // configVal = defaultVal + // } + + ErrNotConfigured = errors.New("is not configured") +) diff --git a/vendor/github.com/longhorn/go-common-libs/types/nfs.go b/vendor/github.com/longhorn/go-common-libs/types/nfs.go new file mode 100644 index 00000000..a52ed150 --- /dev/null +++ b/vendor/github.com/longhorn/go-common-libs/types/nfs.go @@ -0,0 +1,3 @@ +package types + +const NFSMountFileName = "nfsmount.conf" diff --git a/vendor/github.com/longhorn/go-common-libs/types/sys.go b/vendor/github.com/longhorn/go-common-libs/types/sys.go index 15155b3b..b778210f 100644 --- a/vendor/github.com/longhorn/go-common-libs/types/sys.go +++ b/vendor/github.com/longhorn/go-common-libs/types/sys.go @@ -2,6 +2,11 @@ package types const OsReleaseFilePath = "/etc/os-release" const SysClassBlockDirectory = "/sys/class/block/" +const SysBootDirectory = "/boot/" +const SysProcDirectory = "/proc/" +const SysEtcDirectory = "/etc/" + +const SysKernelConfigGz = "config.gz" const OSDistroTalosLinux = "talos" diff --git a/vendor/modules.txt b/vendor/modules.txt index 9cc92967..109db419 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -133,7 +133,7 @@ github.com/json-iterator/go # github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de ## explicit github.com/liggitt/tabwriter -# github.com/longhorn/go-common-libs v0.0.0-20241128023039-4d6c3a880dbc +# github.com/longhorn/go-common-libs v0.0.0-20241206085105-b60ef86c0b25 ## explicit; go 1.22.7 github.com/longhorn/go-common-libs/exec github.com/longhorn/go-common-libs/io