Skip to content

Commit

Permalink
Refine log messages
Browse files Browse the repository at this point in the history
Longhorn 4883

Signed-off-by: Derek Su <derek.su@suse.com>
  • Loading branch information
derekbit committed Aug 8, 2023
1 parent 460b23b commit faf6a5c
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 131 deletions.
25 changes: 10 additions & 15 deletions csi/controller_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
}
}

vol, err := getVolumeOptions(volumeParameters)
vol, err := getVolumeOptions(volumeID, volumeParameters)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}

if err = cs.checkAndPrepareBackingImage(volumeID, vol.BackingImage, volumeParameters); err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
Expand Down Expand Up @@ -502,7 +503,7 @@ func (cs *ControllerServer) updateVolumeAccessMode(volume *longhornclient.Volume
log.Infof("Changing volume %s access mode to %s", volumeName, mode)
volume, err := cs.apiClient.Volume.ActionUpdateAccessMode(volume, input)
if err != nil {
logrus.WithError(err).Errorf("Failed to change Volume %s access mode to %s", volumeName, mode)
log.WithError(err).Errorf("Failed to change volume %s access mode to %s", volumeName, mode)
return nil, status.Error(codes.Internal, err.Error())
}

Expand Down Expand Up @@ -531,7 +532,7 @@ func (cs *ControllerServer) ControllerUnpublishVolume(ctx context.Context, req *

attachmentID := generateAttachmentID(volumeID, nodeID)

// TODO: hadndle cases in which NodeID is empty. Should we detach the volume from all nodes???
// TODO: handle cases in which NodeID is empty. Should we detach the volume from all nodes???

return cs.unpublishVolume(volume, nodeID, attachmentID, func() error {
checkVolumeUnpublished := func(vol *longhornclient.Volume) bool {
Expand All @@ -551,7 +552,7 @@ func (cs *ControllerServer) unpublishVolume(volume *longhornclient.Volume, nodeI
log := getLoggerForCSIControllerServer()
log = log.WithFields(logrus.Fields{"function": "unpublishVolume"})

logrus.Infof("Requesting volume %v detachment for %v with attachmentID %v ", volume.Name, nodeID, attachmentID)
log.Infof("Requesting volume %v detachment for node %v with attachmentID %v ", volume.Name, nodeID, attachmentID)
detachInput := &longhornclient.DetachInput{
AttachmentID: attachmentID,
HostId: nodeID,
Expand Down Expand Up @@ -811,7 +812,7 @@ func (cs *ControllerServer) createCSISnapshotTypeLonghornBackup(req *csi.CreateS
return nil, err
}

logrus.Infof("Volume %s backup %s of snapshot %s in progress", existVol.Name, backupStatus.Id, csiSnapshotName)
log.Infof("Volume %s backup %s of snapshot %s in progress", existVol.Name, backupStatus.Id, csiSnapshotName)
snapshotID := encodeSnapshotID(csiSnapshotTypeLonghornBackup, existVol.Name, backupStatus.Id)
rsp := createSnapshotResponseForSnapshotTypeLonghornBackup(existVol.Name, snapshotID, snapshotCR.CreationTime, existVol.Size, backupStatus.State == string(longhorn.BackupStateCompleted))
return rsp, nil
Expand All @@ -820,7 +821,7 @@ func (cs *ControllerServer) createCSISnapshotTypeLonghornBackup(req *csi.CreateS
func createSnapshotResponseForSnapshotTypeLonghornSnapshot(sourceVolumeName, snapshotID string, snapshotCR *longhornclient.SnapshotCR) *csi.CreateSnapshotResponse {
creationTime, err := toProtoTimestamp(snapshotCR.CreationTime)
if err != nil {
logrus.Errorf("Failed to parse creation time %v for csi snapshot %v", snapshotCR.CreationTime, snapshotID)
logrus.WithError(err).Errorf("Failed to parse creation time %v for csi snapshot %v", snapshotCR.CreationTime, snapshotID)
}

return &csi.CreateSnapshotResponse{
Expand All @@ -837,7 +838,7 @@ func createSnapshotResponseForSnapshotTypeLonghornSnapshot(sourceVolumeName, sna
func createSnapshotResponseForSnapshotTypeLonghornBackup(sourceVolumeName, snapshotID, snapshotTime, sourceVolumeSize string, readyToUse bool) *csi.CreateSnapshotResponse {
creationTime, err := toProtoTimestamp(snapshotTime)
if err != nil {
logrus.Errorf("Failed to parse creation time %v for CSI snapshot %v", snapshotTime, snapshotID)
logrus.WithError(err).Errorf("Failed to parse creation time %v for CSI snapshot %v", snapshotTime, snapshotID)
}

size, _ := util.ConvertSize(sourceVolumeSize)
Expand All @@ -856,7 +857,7 @@ func createSnapshotResponseForSnapshotTypeLonghornBackup(sourceVolumeName, snaps
func createSnapshotResponseForSnapshotTypeLonghornBackingImage(sourceVolumeName, snapshotID, snapshotTime, sourceVolumeSize string, readyToUse bool) *csi.CreateSnapshotResponse {
creationTime, err := toProtoTimestamp(snapshotTime)
if err != nil {
logrus.Errorf("Failed to parse creation time %v for CSI snapshot %v", snapshotTime, snapshotID)
logrus.WithError(err).Errorf("Failed to parse creation time %v for CSI snapshot %v", snapshotTime, snapshotID)
}

size, _ := util.ConvertSize(sourceVolumeSize)
Expand Down Expand Up @@ -1109,12 +1110,6 @@ func isVolumeAvailableOn(vol *longhornclient.Volume, node string) bool {
return vol.State == string(longhorn.VolumeStateAttached) && isEngineOnNodeAvailable(vol, node)
}

// isVolumeUnavailableOn checks that the volume is not attached to the requested node
func isVolumeUnavailableOn(vol *longhornclient.Volume, node string) bool {
isValidState := vol.State == string(longhorn.VolumeStateAttached) || vol.State == string(longhorn.VolumeStateDetached)
return isValidState && !isEngineOnNodeAvailable(vol, node)
}

func isEngineOnNodeAvailable(vol *longhornclient.Volume, node string) bool {
for _, controller := range vol.Controllers {
if controller.HostId == node && controller.Endpoint != "" {
Expand Down Expand Up @@ -1150,7 +1145,7 @@ func (cs *ControllerServer) waitForVolumeState(volumeID string, stateDescription
case <-tick:
existVol, err := cs.apiClient.Volume.ById(volumeID)
if err != nil {
log.Warnf("Failed to get volume while waiting for volume %s state %s error %s", volumeID, stateDescription, err)
log.WithError(err).Warnf("Failed to get volume while waiting for volume %s state %s", volumeID, stateDescription)
continue
}
if existVol == nil {
Expand Down
7 changes: 4 additions & 3 deletions csi/crypto/luks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package crypto
import (
"bytes"
"context"
"fmt"
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/pkg/errors"

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

Expand Down Expand Up @@ -63,9 +64,9 @@ func cryptSetupWithPassphrase(passphrase string, args ...string) (stdout string,
cmd.Stdin = strings.NewReader(passphrase)
}

output := string(stdoutBuf.Bytes())
output := stdoutBuf.String()
if err := cmd.Run(); err != nil {
return output, fmt.Errorf("failed to run cryptsetup args: %v output: %v error: %v", args, output, err)
return output, errors.Wrapf(err, "failed to run cryptsetup args: %v output: %v", args, output)
}

return stdoutBuf.String(), nil
Expand Down
16 changes: 8 additions & 8 deletions csi/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ func (p *ProvisionerDeployment) Cleanup(kubeClient *clientset.Clientset) {
util.RunAsync(&wg, func() {
if err := cleanup(kubeClient, p.service, "service",
serviceDeleteFunc, serviceGetFunc); err != nil {
logrus.Warnf("Failed to cleanup service in provisioner deployment: %v", err)
logrus.WithError(err).Warn("Failed to cleanup service in provisioner deployment")
}
})
util.RunAsync(&wg, func() {
if err := cleanup(kubeClient, p.deployment, "deployment",
deploymentDeleteFunc, deploymentGetFunc); err != nil {
logrus.Warnf("Failed to cleanup deployment in provisioner deployment: %v", err)
logrus.WithError(err).Warn("Failed to cleanup deployment in provisioner deployment")
}
})
}
Expand Down Expand Up @@ -242,13 +242,13 @@ func (p *ResizerDeployment) Cleanup(kubeClient *clientset.Clientset) {
util.RunAsync(&wg, func() {
if err := cleanup(kubeClient, p.service, "service",
serviceDeleteFunc, serviceGetFunc); err != nil {
logrus.Warnf("Failed to cleanup service in resizer deployment: %v", err)
logrus.WithError(err).Warn("Failed to cleanup service in resizer deployment")
}
})
util.RunAsync(&wg, func() {
if err := cleanup(kubeClient, p.deployment, "deployment",
deploymentDeleteFunc, deploymentGetFunc); err != nil {
logrus.Warnf("Failed to cleanup deployment in resizer deployment: %v", err)
logrus.WithError(err).Warn("Failed to cleanup deployment in resizer deployment")
}
})
}
Expand Down Expand Up @@ -307,13 +307,13 @@ func (p *SnapshotterDeployment) Cleanup(kubeClient *clientset.Clientset) {
util.RunAsync(&wg, func() {
if err := cleanup(kubeClient, p.service, "service",
serviceDeleteFunc, serviceGetFunc); err != nil {
logrus.Warnf("Failed to cleanup service in snapshotter deployment: %v", err)
logrus.WithError(err).Warn("Failed to cleanup service in snapshotter deployment")
}
})
util.RunAsync(&wg, func() {
if err := cleanup(kubeClient, p.deployment, "deployment",
deploymentDeleteFunc, deploymentGetFunc); err != nil {
logrus.Warnf("Failed to cleanup deployment in snapshotter deployment: %v", err)
logrus.WithError(err).Warn("Failed to cleanup deployment in snapshotter deployment")
}
})
}
Expand Down Expand Up @@ -602,7 +602,7 @@ func (p *PluginDeployment) Deploy(kubeClient *clientset.Clientset) error {
func (p *PluginDeployment) Cleanup(kubeClient *clientset.Clientset) {
if err := cleanup(kubeClient, p.daemonSet, "daemon set",
daemonSetDeleteFunc, daemonSetGetFunc); err != nil {
logrus.Warnf("Failed to cleanup DaemonSet in plugin deployment: %v", err)
logrus.WithError(err).Warn("Failed to cleanup DaemonSet in plugin deployment")
}
}

Expand Down Expand Up @@ -633,6 +633,6 @@ func (d *DriverObjectDeployment) Deploy(kubeClient *clientset.Clientset) error {
func (d *DriverObjectDeployment) Cleanup(kubeClient *clientset.Clientset) {
if err := cleanup(kubeClient, d.obj, "CSI Driver",
csiDriverObjectDeleteFunc, csiDriverObjectGetFunc); err != nil {
logrus.Warnf("Failed to cleanup CSI Driver object in CSI Driver object deployment: %v", err)
logrus.WithError(err).Warn("Failed to cleanup CSI Driver object in CSI Driver object deployment")
}
}
Loading

0 comments on commit faf6a5c

Please sign in to comment.