Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/node-disk-manager-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion pkg/block/block_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/blockdevice/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions pkg/lvm/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/provisioner/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
73 changes: 0 additions & 73 deletions pkg/utils/process.go

This file was deleted.

17 changes: 7 additions & 10 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"syscall"
"time"

"github.com/harvester/go-common/common"
"github.com/sirupsen/logrus"
)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion pkg/webhook/blockdevice/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
10 changes: 5 additions & 5 deletions pkg/webhook/blockdevice/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -219,7 +219,7 @@ func newVolume(name string) *lhv1.Volume {
return &lhv1.Volume{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: utils.LonghornSystemNamespaceName,
Namespace: common.LonghornSystemNamespaceName,
},
}
}
Expand All @@ -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{
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pkg/webhook/storageclass/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions vendor/github.com/harvester/go-common/common/constants.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading