Skip to content

Commit

Permalink
chore(vendor): update go-common-libs/go-iscsi-utils and resolve break…
Browse files Browse the repository at this point in the history
…ing changes

ref: longhorn/longhorn 7960

Signed-off-by: Jack Lin <jack.lin@suse.com>
  • Loading branch information
ChanYiLin authored and innobead committed Mar 26, 2024
1 parent e9d4aea commit f9aa89c
Show file tree
Hide file tree
Showing 285 changed files with 18,855 additions and 2,676 deletions.
13 changes: 7 additions & 6 deletions app/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (

iscsiutil "github.com/longhorn/go-iscsi-helper/util"

lhns "github.com/longhorn/go-common-libs/ns"
lhtypes "github.com/longhorn/go-common-libs/types"

"github.com/longhorn/longhorn-manager/api"
"github.com/longhorn/longhorn-manager/controller"
"github.com/longhorn/longhorn-manager/datastore"
Expand Down Expand Up @@ -237,15 +240,13 @@ func startManager(c *cli.Context) error {
}

func environmentCheck() error {
initiatorNSPath := iscsiutil.GetHostNamespacePath(util.HostProcPath)
namespace, err := iscsiutil.NewNamespaceExecutor(initiatorNSPath)
namespaces := []lhtypes.Namespace{lhtypes.NamespaceMnt, lhtypes.NamespaceNet}
nsexec, err := lhns.NewNamespaceExecutor(iscsiutil.ISCSIdProcess, lhtypes.HostProcDirectory, namespaces)
if err != nil {
return err
}
if err := iscsi.CheckForInitiatorExistence(namespace); err != nil {
return err
}
return nil

return iscsi.CheckForInitiatorExistence(nsexec)
}

func updateRegistrySecretName(m *manager.VolumeManager) error {
Expand Down
6 changes: 5 additions & 1 deletion controller/engine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
clientset "k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1"

lhexec "github.com/longhorn/go-common-libs/exec"
lhtypes "github.com/longhorn/go-common-libs/types"
etypes "github.com/longhorn/longhorn-engine/pkg/types"
imapi "github.com/longhorn/longhorn-instance-manager/pkg/api"
imclient "github.com/longhorn/longhorn-instance-manager/pkg/client"
Expand Down Expand Up @@ -570,7 +572,9 @@ func (ec *EngineController) DeleteInstance(obj interface{}) (err error) {
url := imutil.GetURL(im.Status.IP, engineapi.InstanceManagerProcessManagerServiceDefaultPort)
args := []string{"--url", url, "engine", "delete", "--name", e.Name}

_, err = util.ExecuteWithoutTimeout([]string{}, engineapi.GetDeprecatedInstanceManagerBinary(e.Status.CurrentImage), args...)
execute := lhexec.NewExecutor().Execute
deprecatedIMBinary := engineapi.GetDeprecatedInstanceManagerBinary(e.Status.CurrentImage)
_, err = execute([]string{}, deprecatedIMBinary, args, lhtypes.ExecuteNoTimeout)
if err != nil && !types.ErrorIsNotFound(err) {
return err
}
Expand Down
8 changes: 5 additions & 3 deletions controller/monitor/disk_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

"k8s.io/apimachinery/pkg/util/wait"

lhtypes "github.com/longhorn/go-common-libs/types"

"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/engineapi"
"github.com/longhorn/longhorn-manager/types"
Expand Down Expand Up @@ -48,13 +50,13 @@ type NodeMonitor struct {
type CollectedDiskInfo struct {
Path string
NodeOrDiskEvicted bool
DiskStat *util.DiskStat
DiskStat *lhtypes.DiskStat
DiskUUID string
Condition *longhorn.Condition
OrphanedReplicaDirectoryNames map[string]string
}

type GetDiskStatHandler func(longhorn.DiskType, string, string, *engineapi.DiskService) (*util.DiskStat, error)
type GetDiskStatHandler func(longhorn.DiskType, string, string, *engineapi.DiskService) (*lhtypes.DiskStat, error)
type GetDiskConfigHandler func(longhorn.DiskType, string, string, *engineapi.DiskService) (*util.DiskConfig, error)
type GenerateDiskConfigHandler func(longhorn.DiskType, string, string, string, *engineapi.DiskService) (*util.DiskConfig, error)
type GetReplicaInstanceNamesHandler func(longhorn.DiskType, *longhorn.Node, string, string, string, *engineapi.DiskService) (map[string]string, error)
Expand Down Expand Up @@ -276,7 +278,7 @@ func canCollectDiskData(node *longhorn.Node, diskName, diskUUID, diskPath string
types.GetCondition(node.Status.DiskStatus[diskName].Conditions, longhorn.DiskConditionTypeReady).Status == longhorn.ConditionStatusTrue
}

func NewDiskInfo(path, diskUUID string, nodeOrDiskEvicted bool, stat *util.DiskStat, orphanedReplicaDirectoryNames map[string]string, errorReason, errorMessage string) *CollectedDiskInfo {
func NewDiskInfo(path, diskUUID string, nodeOrDiskEvicted bool, stat *lhtypes.DiskStat, orphanedReplicaDirectoryNames map[string]string, errorReason, errorMessage string) *CollectedDiskInfo {
diskInfo := &CollectedDiskInfo{
Path: path,
NodeOrDiskEvicted: nodeOrDiskEvicted,
Expand Down
67 changes: 33 additions & 34 deletions controller/monitor/disk_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"encoding/json"
"fmt"
"path/filepath"
"time"

"github.com/pkg/errors"

grpccodes "google.golang.org/grpc/codes"
grpcstatus "google.golang.org/grpc/status"

iscsiutil "github.com/longhorn/go-iscsi-helper/util"
lhns "github.com/longhorn/go-common-libs/ns"
lhtypes "github.com/longhorn/go-common-libs/types"

"github.com/longhorn/longhorn-manager/engineapi"
"github.com/longhorn/longhorn-manager/util"
Expand All @@ -23,22 +25,18 @@ const (
)

// GetDiskStat returns the disk stat of the given directory
func getDiskStat(diskType longhorn.DiskType, name, path string, client *engineapi.DiskService) (stat *util.DiskStat, err error) {
func getDiskStat(diskType longhorn.DiskType, name, path string, client *engineapi.DiskService) (stat *lhtypes.DiskStat, err error) {
switch diskType {
case longhorn.DiskTypeFilesystem:
return getFilesystemTypeDiskStat(path)
return lhns.GetDiskStat(path)
case longhorn.DiskTypeBlock:
return getBlockTypeDiskStat(client, name, path)
default:
return nil, fmt.Errorf("unknown disk type %v", diskType)
}
}

func getFilesystemTypeDiskStat(path string) (stat *util.DiskStat, err error) {
return util.GetDiskStat(path)
}

func getBlockTypeDiskStat(client *engineapi.DiskService, name, path string) (stat *util.DiskStat, err error) {
func getBlockTypeDiskStat(client *engineapi.DiskService, name, path string) (stat *lhtypes.DiskStat, err error) {
if client == nil {
return nil, errors.New("disk service client is nil")
}
Expand All @@ -47,7 +45,7 @@ func getBlockTypeDiskStat(client *engineapi.DiskService, name, path string) (sta
if err != nil {
return nil, err
}
return &util.DiskStat{
return &lhtypes.DiskStat{
DiskID: info.ID,
Path: info.Path,
Type: info.Type,
Expand All @@ -72,20 +70,20 @@ func getDiskConfig(diskType longhorn.DiskType, name, path string, client *engine
}

func getFilesystemTypeDiskConfig(path string) (*util.DiskConfig, error) {
nsPath := iscsiutil.GetHostNamespacePath(util.HostProcPath)
nsExec, err := iscsiutil.NewNamespaceExecutor(nsPath)
if err != nil {
return nil, err
}
filePath := filepath.Join(path, util.DiskConfigFile)
output, err := nsExec.Execute("cat", []string{filePath})
var err error
defer func() {
err = errors.Wrapf(err, "failed to get disk config for %v", path)
}()

diskCfgFilePath := filepath.Join(path, util.DiskConfigFile)
output, err := lhns.ReadFileContent(diskCfgFilePath)
if err != nil {
return nil, fmt.Errorf("cannot find config file %v on host: %v", filePath, err)
return nil, errors.Wrapf(err, "failed to read host disk config file %v", util.DiskConfigFile)
}

cfg := &util.DiskConfig{}
if err := json.Unmarshal([]byte(output), cfg); err != nil {
return nil, fmt.Errorf("failed to unmarshal %v content %v on host: %v", filePath, output, err)
return nil, errors.Wrapf(err, "failed to unmarshal host %v content: %v", diskCfgFilePath, output)
}
return cfg, nil
}
Expand Down Expand Up @@ -120,6 +118,11 @@ func generateDiskConfig(diskType longhorn.DiskType, name, uuid, path string, cli
}

func generateFilesystemTypeDiskConfig(path string) (*util.DiskConfig, error) {
var err error
defer func() {
err = errors.Wrapf(err, "failed to generate disk config for %v", path)
}()

cfg := &util.DiskConfig{
DiskUUID: util.UUID(),
}
Expand All @@ -128,33 +131,29 @@ func generateFilesystemTypeDiskConfig(path string) (*util.DiskConfig, error) {
return nil, fmt.Errorf("BUG: Cannot marshal %+v: %v", cfg, err)
}

nsPath := iscsiutil.GetHostNamespacePath(util.HostProcPath)
nsExec, err := iscsiutil.NewNamespaceExecutor(nsPath)
if err != nil {
return nil, err
}
filePath := filepath.Join(path, util.DiskConfigFile)
if _, err := nsExec.Execute("ls", []string{filePath}); err == nil {
return nil, fmt.Errorf("disk cfg on %v exists, cannot override", filePath)
diskCfgFilePath := filepath.Join(path, util.DiskConfigFile)
if _, err := lhns.GetFileInfo(diskCfgFilePath); err == nil {
return nil, fmt.Errorf("disk cfg on %v exists, cannot override", diskCfgFilePath)
}

defer func() {
if err != nil {
if derr := util.DeleteDiskPathReplicaSubdirectoryAndDiskCfgFile(nsExec, path); derr != nil {
if derr := util.DeleteDiskPathReplicaSubdirectoryAndDiskCfgFile(path); derr != nil {
err = errors.Wrapf(err, "cleaning up disk config path %v failed with error: %v", path, derr)
}

}
}()

if _, err := nsExec.ExecuteWithStdin("dd", []string{"of=" + filePath}, string(encoded)); err != nil {
return nil, fmt.Errorf("cannot write to disk cfg on %v: %v", filePath, err)
}
if err := util.CreateDiskPathReplicaSubdirectory(path); err != nil {
if err := lhns.WriteFile(diskCfgFilePath, string(encoded)); err != nil {
return nil, err
}
if _, err := nsExec.Execute("sync", []string{filePath}); err != nil {
return nil, fmt.Errorf("cannot sync disk cfg on %v: %v", filePath, err)

if _, err := lhns.CreateDirectory(filepath.Join(path, util.ReplicaDirectory), time.Now()); err != nil {
return nil, errors.Wrapf(err, "failed to create replica subdirectory %v", path)
}

if err := lhns.SyncFile(diskCfgFilePath); err != nil {
return nil, err
}

return cfg, nil
Expand Down
7 changes: 4 additions & 3 deletions controller/monitor/fake_disk_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/sirupsen/logrus"

lhtypes "github.com/longhorn/go-common-libs/types"
"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/engineapi"
"github.com/longhorn/longhorn-manager/util"
Expand Down Expand Up @@ -49,10 +50,10 @@ func fakeGetReplicaDirectoryNames(diskType longhorn.DiskType, node *longhorn.Nod
}, nil
}

func fakeGetDiskStat(diskType longhorn.DiskType, name, directory string, client *engineapi.DiskService) (*util.DiskStat, error) {
func fakeGetDiskStat(diskType longhorn.DiskType, name, directory string, client *engineapi.DiskService) (*lhtypes.DiskStat, error) {
switch diskType {
case longhorn.DiskTypeFilesystem:
return &util.DiskStat{
return &lhtypes.DiskStat{
DiskID: "fsid",
Path: directory,
Type: "ext4",
Expand All @@ -64,7 +65,7 @@ func fakeGetDiskStat(diskType longhorn.DiskType, name, directory string, client
StorageAvailable: 0,
}, nil
case longhorn.DiskTypeBlock:
return &util.DiskStat{
return &lhtypes.DiskStat{
DiskID: "block",
Path: directory,
Type: "ext4",
Expand Down
9 changes: 7 additions & 2 deletions controller/orphan_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"fmt"
"path/filepath"
"reflect"
"strings"
"time"
Expand All @@ -21,10 +22,11 @@ import (
clientset "k8s.io/client-go/kubernetes"
v1core "k8s.io/client-go/kubernetes/typed/core/v1"

lhns "github.com/longhorn/go-common-libs/ns"

"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/engineapi"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
)
Expand Down Expand Up @@ -315,7 +317,10 @@ func (oc *OrphanController) deleteOrphanedReplica(orphan *longhorn.Orphan) error

switch longhorn.DiskType(diskType) {
case longhorn.DiskTypeFilesystem:
return util.DeleteReplicaDirectory(orphan.Spec.Parameters[longhorn.OrphanDiskPath], orphan.Spec.Parameters[longhorn.OrphanDataName])
diskPath := orphan.Spec.Parameters[longhorn.OrphanDiskPath]
replicaDirectoryName := orphan.Spec.Parameters[longhorn.OrphanDataName]
err := lhns.DeletePath(filepath.Join(diskPath, "replicas", replicaDirectoryName))
return errors.Wrapf(err, "failed to delete orphan replica directory %v in disk %v", replicaDirectoryName, diskPath)
case longhorn.DiskTypeBlock:
return oc.DeleteSpdkReplicaInstance(orphan.Spec.Parameters[longhorn.OrphanDiskName], orphan.Spec.Parameters[longhorn.OrphanDiskUUID], orphan.Spec.Parameters[longhorn.OrphanDataName])
default:
Expand Down
5 changes: 3 additions & 2 deletions controller/replica_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import (

imapi "github.com/longhorn/longhorn-instance-manager/pkg/api"

lhns "github.com/longhorn/go-common-libs/ns"

"github.com/longhorn/longhorn-manager/constant"
"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/engineapi"
"github.com/longhorn/longhorn-manager/types"
"github.com/longhorn/longhorn-manager/util"

longhorn "github.com/longhorn/longhorn-manager/k8s/pkg/apis/longhorn/v1beta2"
)
Expand Down Expand Up @@ -257,7 +258,7 @@ func (rc *ReplicaController) syncReplica(key string) (err error) {
return fmt.Errorf("%v doesn't look like a replica data path", dataPath)
}
log.Info("Cleaning up replica")
if err := util.RemoveHostDirectoryContent(dataPath); err != nil {
if err := lhns.DeleteDirectory(dataPath); err != nil {
return errors.Wrapf(err, "cannot cleanup after replica %v at %v", replica.Name, dataPath)
}
} else {
Expand Down
6 changes: 4 additions & 2 deletions controller/setting_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"k8s.io/client-go/tools/record"
"k8s.io/kubernetes/pkg/controller"

lhns "github.com/longhorn/go-common-libs/ns"

"github.com/longhorn/longhorn-manager/constant"
"github.com/longhorn/longhorn-manager/datastore"
"github.com/longhorn/longhorn-manager/types"
Expand Down Expand Up @@ -1678,7 +1680,7 @@ func (info *ClusterInfo) collectNodeScope() {
}

func (info *ClusterInfo) collectHostKernelRelease() error {
kernelRelease, err := util.GetHostKernelRelease()
kernelRelease, err := lhns.GetKernelRelease()
if err == nil {
info.structFields.tags.Append(ClusterInfoHostKernelRelease, kernelRelease)
}
Expand All @@ -1687,7 +1689,7 @@ func (info *ClusterInfo) collectHostKernelRelease() error {

func (info *ClusterInfo) collectHostOSDistro() (err error) {
if info.osDistro == "" {
info.osDistro, err = util.GetHostOSDistro()
info.osDistro, err = lhns.GetOSDistro()
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit f9aa89c

Please sign in to comment.