From f38829a190d7e8fa5713dd93595f5cea73f657c3 Mon Sep 17 00:00:00 2001 From: Martin Dekov Date: Mon, 12 Jan 2026 10:24:59 +0200 Subject: [PATCH] Reuse go-common code and small refactoring Reusing go-common code redefined in the repo including: * constants * methods * leftover feedback from previous review * fix deprecated namespaces * fix linter errors Signed-off-by: Martin Dekov --- cmd/node-disk-manager-webhook/main.go | 2 +- go.mod | 4 +- go.sum | 8 +- pkg/block/block_device.go | 3 +- pkg/controller/blockdevice/controller.go | 2 +- pkg/lvm/lvm.go | 5 +- pkg/provisioner/lvm.go | 6 +- pkg/utils/command.go | 2 +- pkg/utils/process.go | 73 ----------- pkg/utils/utils.go | 17 ++- pkg/webhook/blockdevice/validator.go | 6 +- pkg/webhook/blockdevice/validator_test.go | 10 +- pkg/webhook/storageclass/validator.go | 3 +- .../harvester/go-common/common/constants.go | 8 ++ .../prometheus/procfs/Makefile.common | 15 ++- vendor/github.com/prometheus/procfs/mdstat.go | 5 +- .../github.com/prometheus/procfs/meminfo.go | 33 +++++ .../github.com/prometheus/procfs/proc_stat.go | 12 +- .../prometheus/procfs/proc_statm.go | 116 ++++++++++++++++++ vendor/modules.txt | 6 +- 20 files changed, 219 insertions(+), 117 deletions(-) delete mode 100644 pkg/utils/process.go create mode 100644 vendor/github.com/harvester/go-common/common/constants.go create mode 100644 vendor/github.com/prometheus/procfs/proc_statm.go diff --git a/cmd/node-disk-manager-webhook/main.go b/cmd/node-disk-manager-webhook/main.go index 7ee9ed854..b4dcac386 100644 --- a/cmd/node-disk-manager-webhook/main.go +++ b/cmd/node-disk-manager-webhook/main.go @@ -149,7 +149,7 @@ func runWebhookServer(ctx context.Context, cfg *rest.Config, options *config.Opt } func newCaches(ctx context.Context, cfg *rest.Config, threadiness int) (*resourceCaches, error) { - var starters []start.Starter + var starters []start.Starter // nolint: prealloc disks, err := ctldisk.NewFactoryFromConfig(cfg) if err != nil { diff --git a/go.mod b/go.mod index 16585655b..6ebe9a37f 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ replace ( require ( github.com/ehazlett/simplelog v0.0.0-20200226020431-d374894e92a4 - github.com/harvester/go-common v0.0.0-20250109132713-e748ce72a7ba + github.com/harvester/go-common v0.0.0-20260108124725-70d352e21314 github.com/harvester/harvester v1.5.1 github.com/harvester/webhook v0.1.5 github.com/jaypipes/ghw v0.8.1-0.20210701154532-dd036bd38c40 @@ -46,7 +46,6 @@ require ( github.com/melbahja/goph v1.3.0 github.com/pilebones/go-udev v0.0.0-20210126000448-a3c2a7a4afb7 github.com/pkg/errors v0.9.1 - github.com/prometheus/procfs v0.16.1 github.com/rancher/lasso v0.2.3 github.com/rancher/wrangler/v3 v3.2.4 github.com/sirupsen/logrus v1.9.3 @@ -92,6 +91,7 @@ require ( github.com/prometheus/client_golang v1.23.2 // indirect github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.66.1 // indirect + github.com/prometheus/procfs v0.17.0 // indirect github.com/rancher/dynamiclistener v0.7.0 // indirect github.com/rancher/wrangler v1.1.2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect diff --git a/go.sum b/go.sum index e71e556c4..82166612b 100644 --- a/go.sum +++ b/go.sum @@ -113,8 +113,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= -github.com/harvester/go-common v0.0.0-20250109132713-e748ce72a7ba h1:U9Q4hwXeqniHkwPORVvVGGUUz8ZG0n7B/jr8uCiofeQ= -github.com/harvester/go-common v0.0.0-20250109132713-e748ce72a7ba/go.mod h1:VPPSa9KzRB1XPPkOAz4M4263UPm5bl/Xd3jEnALh3uo= +github.com/harvester/go-common v0.0.0-20260108124725-70d352e21314 h1:xW4ac1Jb6+5T7xPkgVoK8+rcRPzTBVLyKcaKpYx8hXU= +github.com/harvester/go-common v0.0.0-20260108124725-70d352e21314/go.mod h1:r0hTaF8ZSSJEN7slrEzeJ80H66MPy+xFv3aScrxhLGI= github.com/harvester/harvester v1.5.1 h1:QXpTrHpk3zsK9WmSgMICKV+RPeT9fPgo43x+TMD6O00= github.com/harvester/harvester v1.5.1/go.mod h1:4exlBYpzXDasoMiYhqklwKEHrzd8+tDpg/vX5MVKKlA= github.com/harvester/webhook v0.1.5 h1:LSredtpCpr5n6XzGRW/qMeZDiSX2W206rI9UFFSHPdY= @@ -245,8 +245,8 @@ github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNw github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs= github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA= -github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg= -github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is= +github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0= +github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw= github.com/rancher/dynamiclistener v0.7.0 h1:+jyfZ4lVamc1UbKWo8V8dhSPtCgRZYaY8nm7wiHeko4= github.com/rancher/dynamiclistener v0.7.0/go.mod h1:Q2YA42xp7Xc69JiSlJ8GpvLvze261T0iQ/TP4RdMCYk= github.com/rancher/lasso v0.2.3 h1:74/z/C/O3ykhyMrRuEgc9kVyYiSoS7kp5BAijlcyXDg= diff --git a/pkg/block/block_device.go b/pkg/block/block_device.go index 3b80cc171..6355adf7a 100644 --- a/pkg/block/block_device.go +++ b/pkg/block/block_device.go @@ -17,6 +17,7 @@ import ( "github.com/sirupsen/logrus" "golang.org/x/crypto/blake2b" + "github.com/harvester/go-common/common" ndmutils "github.com/harvester/node-disk-manager/pkg/utils" ) @@ -509,7 +510,7 @@ func partitionInfo(ctx *context.Context, paths *linuxpath.Paths, part string) (s func openProcMounts(ctx *context.Context, paths *linuxpath.Paths) (*os.File, error) { file := paths.ProcMounts if path, ok := ctx.PathOverrides[ndmutils.ProcPath]; ok { - ns := ndmutils.GetHostNamespacePath(path) + ns := common.GetHostNamespacePath(path) file = strings.TrimSuffix(ns, "ns/") + "mounts" } return os.Open(file) diff --git a/pkg/controller/blockdevice/controller.go b/pkg/controller/blockdevice/controller.go index 44aac5b6e..81d58f241 100644 --- a/pkg/controller/blockdevice/controller.go +++ b/pkg/controller/blockdevice/controller.go @@ -462,7 +462,7 @@ func isOnUpgrade(upgrades ctlharvesterv1.UpgradeClient) bool { return false } - upgradesItems, err := upgrades.List(utils.HarvesterNS, metav1.ListOptions{ + upgradesItems, err := upgrades.List(gocommon.HarvesterSystemNamespaceName, metav1.ListOptions{ LabelSelector: labels.NewSelector().Add(*req).String(), }) if err != nil { diff --git a/pkg/lvm/lvm.go b/pkg/lvm/lvm.go index a777ed554..f6902353e 100644 --- a/pkg/lvm/lvm.go +++ b/pkg/lvm/lvm.go @@ -8,6 +8,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/selection" + "github.com/harvester/go-common/common" "github.com/harvester/node-disk-manager/pkg/utils" ) @@ -16,7 +17,7 @@ const ( ) func GetPVScanResult() (map[string]string, error) { - ns := utils.GetHostNamespacePath(utils.HostProcPath) + ns := common.GetHostNamespacePath(utils.HostProcPath) executor, err := utils.NewExecutorWithNS(ns) if err != nil { return nil, fmt.Errorf("generate executor failed: %v", err) @@ -48,7 +49,7 @@ func GetPVScanResult() (map[string]string, error) { } func executeCommandWithNS(cmd string, args []string) error { - ns := utils.GetHostNamespacePath(utils.HostProcPath) + ns := common.GetHostNamespacePath(utils.HostProcPath) executor, err := utils.NewExecutorWithNS(ns) if err != nil { return fmt.Errorf("generate executor failed: %v", err) diff --git a/pkg/provisioner/lvm.go b/pkg/provisioner/lvm.go index 26086f33f..6ce35ca2a 100644 --- a/pkg/provisioner/lvm.go +++ b/pkg/provisioner/lvm.go @@ -9,11 +9,11 @@ import ( "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/harvester/go-common/common" diskv1 "github.com/harvester/node-disk-manager/pkg/apis/harvesterhci.io/v1beta1" "github.com/harvester/node-disk-manager/pkg/block" ctldiskv1 "github.com/harvester/node-disk-manager/pkg/generated/controllers/harvesterhci.io/v1beta1" "github.com/harvester/node-disk-manager/pkg/lvm" - "github.com/harvester/node-disk-manager/pkg/utils" ) type LVMProvisioner struct { @@ -185,7 +185,7 @@ func (l *LVMProvisioner) addDevOrCreateLVMVgCRD(lvmVG *diskv1.LVMVolumeGroup, fo lvmVG = &diskv1.LVMVolumeGroup{ ObjectMeta: metav1.ObjectMeta{ GenerateName: fmt.Sprintf("%s-", l.vgName), - Namespace: utils.HarvesterNS, + Namespace: common.HarvesterSystemNamespaceName, Labels: map[string]string{ lvm.LVMTopoKeyNode: l.nodeName, }, @@ -268,7 +268,7 @@ func (l *LVMProvisioner) getTargetLVMVG() (target *diskv1.LVMVolumeGroup, err er err = fmt.Errorf("failed to generate selector: %w", err) return } - lvmvgs, err := l.vgClient.List(utils.HarvesterNS, metav1.ListOptions{LabelSelector: selector.String()}) + lvmvgs, err := l.vgClient.List(common.HarvesterSystemNamespaceName, metav1.ListOptions{LabelSelector: selector.String()}) if err != nil { err = fmt.Errorf("failed to list LVMVolumeGroup %s: %w", l.vgName, err) return diff --git a/pkg/utils/command.go b/pkg/utils/command.go index 9787e4237..eefb47e77 100644 --- a/pkg/utils/command.go +++ b/pkg/utils/command.go @@ -46,7 +46,7 @@ func (exec *Executor) Execute(cmd string, args []string) (string, error) { command := cmd cmdArgs := args if exec.namespace != "" { - cmdArgs = []string{ + cmdArgs = []string{ // nolint: prealloc "--mount=" + filepath.Join(exec.namespace, "mnt"), "--net=" + filepath.Join(exec.namespace, "net"), "--ipc=" + filepath.Join(exec.namespace, "ipc"), diff --git a/pkg/utils/process.go b/pkg/utils/process.go deleted file mode 100644 index d5d22b7a6..000000000 --- a/pkg/utils/process.go +++ /dev/null @@ -1,73 +0,0 @@ -package utils - -import ( - "fmt" - - "github.com/prometheus/procfs" -) - -const ( - DockerdProcess = "dockerd" - ContainerdProcess = "containerd" - ContainerdProcessShim = "containerd-shim" -) - -func getPidProc(hostProcPath string, pid int) (*procfs.Proc, error) { - fs, err := procfs.NewFS(hostProcPath) - if err != nil { - return nil, err - } - proc, err := fs.Proc(pid) - if err != nil { - return nil, err - } - return &proc, nil -} - -func getSelfProc(hostProcPath string) (*procfs.Proc, error) { - fs, err := procfs.NewFS(hostProcPath) - if err != nil { - return nil, err - } - proc, err := fs.Self() - if err != nil { - return nil, err - } - return &proc, nil -} - -func findAncestorByName(hostProcPath string, ancestorProcess string) (*procfs.Proc, error) { - proc, err := getSelfProc(hostProcPath) - if err != nil { - return nil, err - } - - for { - st, err := proc.Stat() - if err != nil { - return nil, err - } - if st.Comm == ancestorProcess { - return proc, nil - } - if st.PPID == 0 { - break - } - proc, err = getPidProc(hostProcPath, st.PPID) - if err != nil { - return nil, err - } - } - return nil, fmt.Errorf("failed to find the ancestor process: %s", ancestorProcess) -} - -func GetHostNamespacePath(hostProcPath string) string { - containerNames := []string{DockerdProcess, ContainerdProcess, ContainerdProcessShim} - for _, name := range containerNames { - proc, err := findAncestorByName(hostProcPath, name) - if err == nil { - return fmt.Sprintf("%s/%d/ns/", hostProcPath, proc.PID) - } - } - return fmt.Sprintf("%s/%d/ns/", hostProcPath, 1) -} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 769d03037..34f31d32a 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -9,6 +9,7 @@ import ( "syscall" "time" + "github.com/harvester/go-common/common" "github.com/sirupsen/logrus" ) @@ -19,14 +20,10 @@ const ( HostProcPath = "/host/proc" // DiskRemoveTag indicates a Longhorn is pending to remove. DiskRemoveTag = "harvester-ndm-disk-remove" - // Harvester Namespace - HarvesterNS = "harvester-system" // LVMCSIDriver is the LVM CSI driver name LVMCSIDriver = "lvm.driver.harvesterhci.io" // LVMTopologyNodeKey is the key of LVM topology node LVMTopologyNodeKey = "topology.lvm.csi/node" - // LonghornSystemNamespaceName is the namespace containing longhorn components - LonghornSystemNamespaceName = "longhorn-system" ) var CmdTimeoutError error @@ -166,7 +163,7 @@ func mountExt4(device, path string, readonly bool) error { // mountExt4OnHostNamespace provides the same functionality as mountExt4 but on host namespace. func mountExt4OnHostNamespace(device, path string, readonly bool) error { - ns := GetHostNamespacePath(HostProcPath) + ns := common.GetHostNamespacePath(HostProcPath) executor, err := NewExecutorWithNS(ns) if err != nil { return err @@ -184,7 +181,7 @@ func mountExt4OnHostNamespace(device, path string, readonly bool) error { // executeOnHostNamespace executes the command in the host namespace // return the command result and error func executeOnHostNamespace(cmd string, args []string) (string, error) { - ns := GetHostNamespacePath(HostProcPath) + ns := common.GetHostNamespacePath(HostProcPath) executor, err := NewExecutorWithNS(ns) if err != nil { return "", err @@ -195,7 +192,7 @@ func executeOnHostNamespace(cmd string, args []string) (string, error) { // executeOnHostNamespace executes the command with timeout value in the host namespace // return the command result and error func executeOnHostNamespaceWithTimeout(cmd string, args []string, cmdTimeout time.Duration) (string, error) { - ns := GetHostNamespacePath(HostProcPath) + ns := common.GetHostNamespacePath(HostProcPath) executor, err := NewExecutorWithNS(ns) executor.SetTimeout(cmdTimeout) if err != nil { @@ -227,7 +224,7 @@ func CallerWithCondLock[T any](cond *sync.Cond, f func() T) T { // IsMultipathDevice checks if a dm-x device is multipath device func IsMultipathDevice(path string) (string, error) { - ns := GetHostNamespacePath(HostProcPath) + ns := common.GetHostNamespacePath(HostProcPath) executor, err := NewExecutorWithNS(ns) if err != nil { return "", fmt.Errorf("failed to create executor with namespace: %v", err) @@ -245,7 +242,7 @@ func IsMultipathDevice(path string) (string, error) { // IsManagedByMultipath checks if a /dev/xxx device is managed by multipath func IsManagedByMultipath(deviceName string) (string, error) { - ns := GetHostNamespacePath(HostProcPath) + ns := common.GetHostNamespacePath(HostProcPath) executor, err := NewExecutorWithNS(ns) if err != nil { return "", fmt.Errorf("failed to create executor with namespace: %v", err) @@ -275,7 +272,7 @@ func IsManagedByMultipath(deviceName string) (string, error) { // For example, dm-0 might return "0QEMU_QEMU_HARDDISK_disk2" // This provides a stable device name that persists across reboots, unlike dm-x which can change func GetMapperDeviceFromDM(dmDevice string) (string, error) { - ns := GetHostNamespacePath(HostProcPath) + ns := common.GetHostNamespacePath(HostProcPath) executor, err := NewExecutorWithNS(ns) if err != nil { return "", fmt.Errorf("failed to create executor with namespace: %v", err) diff --git a/pkg/webhook/blockdevice/validator.go b/pkg/webhook/blockdevice/validator.go index 8ed6a9d1e..bcd6dc749 100644 --- a/pkg/webhook/blockdevice/validator.go +++ b/pkg/webhook/blockdevice/validator.go @@ -98,7 +98,7 @@ func (v *Validator) validateLHDisk(oldBd, newBd *diskv1.BlockDevice) error { if oldBd.Spec.Provisioner.Longhorn == nil || newBd.Spec.Provisioner.Longhorn == nil { return nil } - if !oldBd.Spec.Provision || newBd.Spec.Provision { + if !isProvisioningDisabled(oldBd, newBd) { return nil } uuid, err := v.validateDiskInNode(oldBd) @@ -378,3 +378,7 @@ func replicaByVolumeIndexer(replica *lhv1.Replica) ([]string, error) { } return []string{replica.Spec.VolumeName}, nil } + +func isProvisioningDisabled(oldBd, newBd *diskv1.BlockDevice) bool { + return oldBd.Spec.Provision && !newBd.Spec.Provision +} diff --git a/pkg/webhook/blockdevice/validator_test.go b/pkg/webhook/blockdevice/validator_test.go index 82bb26cc5..0c00f7fda 100644 --- a/pkg/webhook/blockdevice/validator_test.go +++ b/pkg/webhook/blockdevice/validator_test.go @@ -3,10 +3,10 @@ package blockdevice import ( "testing" + "github.com/harvester/go-common/common" lhv1beta2 "github.com/harvester/harvester/pkg/generated/controllers/longhorn.io/v1beta2" diskv1 "github.com/harvester/node-disk-manager/pkg/apis/harvesterhci.io/v1beta1" ctldiskv1 "github.com/harvester/node-disk-manager/pkg/generated/controllers/harvesterhci.io/v1beta1" - "github.com/harvester/node-disk-manager/pkg/utils" "github.com/harvester/node-disk-manager/pkg/utils/fake" lhv1 "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2" ctlcorev1 "github.com/rancher/wrangler/v3/pkg/generated/controllers/core/v1" @@ -207,7 +207,7 @@ func newLHNode(name string, disks map[string]string) *lhv1.Node { return &lhv1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: utils.LonghornSystemNamespaceName, + Namespace: common.LonghornSystemNamespaceName, }, Status: lhv1.NodeStatus{ DiskStatus: diskStatus, @@ -219,7 +219,7 @@ func newVolume(name string) *lhv1.Volume { return &lhv1.Volume{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: utils.LonghornSystemNamespaceName, + Namespace: common.LonghornSystemNamespaceName, }, } } @@ -236,7 +236,7 @@ func newReplica(name, volName, nodeID, diskID string, isFailed, isHealthy bool) return &lhv1.Replica{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: utils.LonghornSystemNamespaceName, + Namespace: common.LonghornSystemNamespaceName, }, Spec: lhv1.ReplicaSpec{ InstanceSpec: lhv1.InstanceSpec{ @@ -259,7 +259,7 @@ func newBackingImage(name string, diskStatuses map[string]lhv1.BackingImageState return &lhv1.BackingImage{ ObjectMeta: metav1.ObjectMeta{ Name: name, - Namespace: utils.LonghornSystemNamespaceName, + Namespace: common.LonghornSystemNamespaceName, }, Status: lhv1.BackingImageStatus{ DiskFileStatusMap: statusMap, diff --git a/pkg/webhook/storageclass/validator.go b/pkg/webhook/storageclass/validator.go index e50a07249..f1fb7e231 100644 --- a/pkg/webhook/storageclass/validator.go +++ b/pkg/webhook/storageclass/validator.go @@ -10,6 +10,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" + "github.com/harvester/go-common/common" diskv1 "github.com/harvester/node-disk-manager/pkg/apis/harvesterhci.io/v1beta1" ctldiskv1 "github.com/harvester/node-disk-manager/pkg/generated/controllers/harvesterhci.io/v1beta1" "github.com/harvester/node-disk-manager/pkg/utils" @@ -36,7 +37,7 @@ func (v *Validator) validateVGStatus(sc *storagev1.StorageClass) error { if sc.Provisioner != utils.LVMCSIDriver { return nil } - vgs, err := v.lvmVGCache.List(utils.HarvesterNS, labels.Everything()) + vgs, err := v.lvmVGCache.List(common.HarvesterSystemNamespaceName, labels.Everything()) if err != nil { return err } diff --git a/vendor/github.com/harvester/go-common/common/constants.go b/vendor/github.com/harvester/go-common/common/constants.go new file mode 100644 index 000000000..50f6c57de --- /dev/null +++ b/vendor/github.com/harvester/go-common/common/constants.go @@ -0,0 +1,8 @@ +package common + +const ( + LonghornSystemNamespaceName = "longhorn-system" + HarvesterSystemNamespaceName = "harvester-system" + // Deprecated: use HarvesterSystemNamespaceName instead + HarvesterNS = HarvesterSystemNamespaceName +) diff --git a/vendor/github.com/prometheus/procfs/Makefile.common b/vendor/github.com/prometheus/procfs/Makefile.common index 0ed55c2ba..4de21512f 100644 --- a/vendor/github.com/prometheus/procfs/Makefile.common +++ b/vendor/github.com/prometheus/procfs/Makefile.common @@ -33,7 +33,7 @@ GOHOSTOS ?= $(shell $(GO) env GOHOSTOS) GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH) GO_VERSION ?= $(shell $(GO) version) -GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))Error Parsing File +GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION)) PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.') PROMU := $(FIRST_GOPATH)/bin/promu @@ -61,7 +61,8 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_ SKIP_GOLANGCI_LINT := GOLANGCI_LINT := GOLANGCI_LINT_OPTS ?= -GOLANGCI_LINT_VERSION ?= v2.0.2 +GOLANGCI_LINT_VERSION ?= v2.1.5 +GOLANGCI_FMT_OPTS ?= # golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64. # windows isn't included here because of the path separator being different. ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin)) @@ -156,9 +157,13 @@ $(GOTEST_DIR): @mkdir -p $@ .PHONY: common-format -common-format: +common-format: $(GOLANGCI_LINT) @echo ">> formatting code" $(GO) fmt $(pkgs) +ifdef GOLANGCI_LINT + @echo ">> formatting code with golangci-lint" + $(GOLANGCI_LINT) fmt $(GOLANGCI_FMT_OPTS) +endif .PHONY: common-vet common-vet: @@ -248,8 +253,8 @@ $(PROMU): cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu rm -r $(PROMU_TMP) -.PHONY: proto -proto: +.PHONY: common-proto +common-proto: @echo ">> generating code from proto files" @./scripts/genproto.sh diff --git a/vendor/github.com/prometheus/procfs/mdstat.go b/vendor/github.com/prometheus/procfs/mdstat.go index 67a9d2b44..1fd4381b2 100644 --- a/vendor/github.com/prometheus/procfs/mdstat.go +++ b/vendor/github.com/prometheus/procfs/mdstat.go @@ -123,13 +123,16 @@ func parseMDStat(mdStatData []byte) ([]MDStat, error) { finish := float64(0) pct := float64(0) recovering := strings.Contains(lines[syncLineIdx], "recovery") + reshaping := strings.Contains(lines[syncLineIdx], "reshape") resyncing := strings.Contains(lines[syncLineIdx], "resync") checking := strings.Contains(lines[syncLineIdx], "check") // Append recovery and resyncing state info. - if recovering || resyncing || checking { + if recovering || resyncing || checking || reshaping { if recovering { state = "recovering" + } else if reshaping { + state = "reshaping" } else if checking { state = "checking" } else { diff --git a/vendor/github.com/prometheus/procfs/meminfo.go b/vendor/github.com/prometheus/procfs/meminfo.go index 4b2c4050a..937e1f960 100644 --- a/vendor/github.com/prometheus/procfs/meminfo.go +++ b/vendor/github.com/prometheus/procfs/meminfo.go @@ -66,6 +66,10 @@ type Meminfo struct { // Memory which has been evicted from RAM, and is temporarily // on the disk SwapFree *uint64 + // Memory consumed by the zswap backend (compressed size) + Zswap *uint64 + // Amount of anonymous memory stored in zswap (original size) + Zswapped *uint64 // Memory which is waiting to get written back to the disk Dirty *uint64 // Memory which is actively being written back to the disk @@ -85,6 +89,8 @@ type Meminfo struct { // amount of memory dedicated to the lowest level of page // tables. PageTables *uint64 + // secondary page tables. + SecPageTables *uint64 // NFS pages sent to the server, but not yet committed to // stable storage NFSUnstable *uint64 @@ -129,15 +135,18 @@ type Meminfo struct { Percpu *uint64 HardwareCorrupted *uint64 AnonHugePages *uint64 + FileHugePages *uint64 ShmemHugePages *uint64 ShmemPmdMapped *uint64 CmaTotal *uint64 CmaFree *uint64 + Unaccepted *uint64 HugePagesTotal *uint64 HugePagesFree *uint64 HugePagesRsvd *uint64 HugePagesSurp *uint64 Hugepagesize *uint64 + Hugetlb *uint64 DirectMap4k *uint64 DirectMap2M *uint64 DirectMap1G *uint64 @@ -161,6 +170,8 @@ type Meminfo struct { MlockedBytes *uint64 SwapTotalBytes *uint64 SwapFreeBytes *uint64 + ZswapBytes *uint64 + ZswappedBytes *uint64 DirtyBytes *uint64 WritebackBytes *uint64 AnonPagesBytes *uint64 @@ -171,6 +182,7 @@ type Meminfo struct { SUnreclaimBytes *uint64 KernelStackBytes *uint64 PageTablesBytes *uint64 + SecPageTablesBytes *uint64 NFSUnstableBytes *uint64 BounceBytes *uint64 WritebackTmpBytes *uint64 @@ -182,11 +194,14 @@ type Meminfo struct { PercpuBytes *uint64 HardwareCorruptedBytes *uint64 AnonHugePagesBytes *uint64 + FileHugePagesBytes *uint64 ShmemHugePagesBytes *uint64 ShmemPmdMappedBytes *uint64 CmaTotalBytes *uint64 CmaFreeBytes *uint64 + UnacceptedBytes *uint64 HugepagesizeBytes *uint64 + HugetlbBytes *uint64 DirectMap4kBytes *uint64 DirectMap2MBytes *uint64 DirectMap1GBytes *uint64 @@ -287,6 +302,12 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) { case "SwapFree:": m.SwapFree = &val m.SwapFreeBytes = &valBytes + case "Zswap:": + m.Zswap = &val + m.ZswapBytes = &valBytes + case "Zswapped:": + m.Zswapped = &val + m.ZswapBytes = &valBytes case "Dirty:": m.Dirty = &val m.DirtyBytes = &valBytes @@ -317,6 +338,9 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) { case "PageTables:": m.PageTables = &val m.PageTablesBytes = &valBytes + case "SecPageTables:": + m.SecPageTables = &val + m.SecPageTablesBytes = &valBytes case "NFS_Unstable:": m.NFSUnstable = &val m.NFSUnstableBytes = &valBytes @@ -350,6 +374,9 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) { case "AnonHugePages:": m.AnonHugePages = &val m.AnonHugePagesBytes = &valBytes + case "FileHugePages:": + m.FileHugePages = &val + m.FileHugePagesBytes = &valBytes case "ShmemHugePages:": m.ShmemHugePages = &val m.ShmemHugePagesBytes = &valBytes @@ -362,6 +389,9 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) { case "CmaFree:": m.CmaFree = &val m.CmaFreeBytes = &valBytes + case "Unaccepted:": + m.Unaccepted = &val + m.UnacceptedBytes = &valBytes case "HugePages_Total:": m.HugePagesTotal = &val case "HugePages_Free:": @@ -373,6 +403,9 @@ func parseMemInfo(r io.Reader) (*Meminfo, error) { case "Hugepagesize:": m.Hugepagesize = &val m.HugepagesizeBytes = &valBytes + case "Hugetlb:": + m.Hugetlb = &val + m.HugetlbBytes = &valBytes case "DirectMap4k:": m.DirectMap4k = &val m.DirectMap4kBytes = &valBytes diff --git a/vendor/github.com/prometheus/procfs/proc_stat.go b/vendor/github.com/prometheus/procfs/proc_stat.go index 06a8d931c..3328556bd 100644 --- a/vendor/github.com/prometheus/procfs/proc_stat.go +++ b/vendor/github.com/prometheus/procfs/proc_stat.go @@ -101,6 +101,12 @@ type ProcStat struct { RSS int // Soft limit in bytes on the rss of the process. RSSLimit uint64 + // The address above which program text can run. + StartCode uint64 + // The address below which program text can run. + EndCode uint64 + // The address of the start (i.e., bottom) of the stack. + StartStack uint64 // CPU number last executed on. Processor uint // Real-time scheduling priority, a number in the range 1 to 99 for processes @@ -177,9 +183,9 @@ func (p Proc) Stat() (ProcStat, error) { &s.VSize, &s.RSS, &s.RSSLimit, - &ignoreUint64, - &ignoreUint64, - &ignoreUint64, + &s.StartCode, + &s.EndCode, + &s.StartStack, &ignoreUint64, &ignoreUint64, &ignoreUint64, diff --git a/vendor/github.com/prometheus/procfs/proc_statm.go b/vendor/github.com/prometheus/procfs/proc_statm.go new file mode 100644 index 000000000..ed5798424 --- /dev/null +++ b/vendor/github.com/prometheus/procfs/proc_statm.go @@ -0,0 +1,116 @@ +// Copyright 2025 The Prometheus Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package procfs + +import ( + "os" + "strconv" + "strings" + + "github.com/prometheus/procfs/internal/util" +) + +// - https://man7.org/linux/man-pages/man5/proc_pid_statm.5.html + +// ProcStatm Provides memory usage information for a process, measured in memory pages. +// Read from /proc/[pid]/statm. +type ProcStatm struct { + // The process ID. + PID int + // total program size (same as VmSize in status) + Size uint64 + // resident set size (same as VmRSS in status) + Resident uint64 + // number of resident shared pages (i.e., backed by a file) + Shared uint64 + // text (code) + Text uint64 + // library (unused since Linux 2.6; always 0) + Lib uint64 + // data + stack + Data uint64 + // dirty pages (unused since Linux 2.6; always 0) + Dt uint64 +} + +// NewStatm returns the current status information of the process. +// Deprecated: Use p.Statm() instead. +func (p Proc) NewStatm() (ProcStatm, error) { + return p.Statm() +} + +// Statm returns the current memory usage information of the process. +func (p Proc) Statm() (ProcStatm, error) { + data, err := util.ReadFileNoStat(p.path("statm")) + if err != nil { + return ProcStatm{}, err + } + + statmSlice, err := parseStatm(data) + if err != nil { + return ProcStatm{}, err + } + + procStatm := ProcStatm{ + PID: p.PID, + Size: statmSlice[0], + Resident: statmSlice[1], + Shared: statmSlice[2], + Text: statmSlice[3], + Lib: statmSlice[4], + Data: statmSlice[5], + Dt: statmSlice[6], + } + + return procStatm, nil +} + +// parseStatm return /proc/[pid]/statm data to uint64 slice. +func parseStatm(data []byte) ([]uint64, error) { + var statmSlice []uint64 + statmItems := strings.Fields(string(data)) + for i := 0; i < len(statmItems); i++ { + statmItem, err := strconv.ParseUint(statmItems[i], 10, 64) + if err != nil { + return nil, err + } + statmSlice = append(statmSlice, statmItem) + } + return statmSlice, nil +} + +// SizeBytes returns the process of total program size in bytes. +func (s ProcStatm) SizeBytes() uint64 { + return s.Size * uint64(os.Getpagesize()) +} + +// ResidentBytes returns the process of resident set size in bytes. +func (s ProcStatm) ResidentBytes() uint64 { + return s.Resident * uint64(os.Getpagesize()) +} + +// SHRBytes returns the process of share memory size in bytes. +func (s ProcStatm) SHRBytes() uint64 { + return s.Shared * uint64(os.Getpagesize()) +} + +// TextBytes returns the process of text (code) size in bytes. +func (s ProcStatm) TextBytes() uint64 { + return s.Text * uint64(os.Getpagesize()) +} + +// DataBytes returns the process of data + stack size in bytes. +func (s ProcStatm) DataBytes() uint64 { + return s.Data * uint64(os.Getpagesize()) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 592ae5854..ced0ea007 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -70,8 +70,8 @@ github.com/google/uuid # github.com/gorilla/mux v1.8.1 ## explicit; go 1.20 github.com/gorilla/mux -# github.com/harvester/go-common v0.0.0-20250109132713-e748ce72a7ba -## explicit; go 1.23 +# github.com/harvester/go-common v0.0.0-20260108124725-70d352e21314 +## explicit; go 1.25 github.com/harvester/go-common/common github.com/harvester/go-common/ds # github.com/harvester/harvester v1.5.1 @@ -161,7 +161,7 @@ github.com/prometheus/client_model/go ## explicit; go 1.23.0 github.com/prometheus/common/expfmt github.com/prometheus/common/model -# github.com/prometheus/procfs v0.16.1 +# github.com/prometheus/procfs v0.17.0 ## explicit; go 1.23.0 github.com/prometheus/procfs github.com/prometheus/procfs/internal/fs