feat(zfspv): move to klog (#166)

Signed-off-by: vaniisgh <vanisingh@live.co.uk>
This commit is contained in:
vaniisgh 2020-06-29 12:18:33 +05:30 committed by GitHub
parent 54f2b0b9fd
commit d0d1664d43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 124 additions and 2991 deletions

View file

@ -5,10 +5,10 @@ import (
"os"
"os/exec"
"github.com/Sirupsen/logrus"
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog"
"k8s.io/kubernetes/pkg/util/mount"
)
@ -18,7 +18,7 @@ func FormatAndMountZvol(devicePath string, mountInfo *apis.MountInfo) error {
err := mounter.FormatAndMount(devicePath, mountInfo.MountPath, mountInfo.FSType, mountInfo.MountOptions)
if err != nil {
logrus.Errorf(
klog.Errorf(
"zfspv: failed to mount volume %s [%s] to %s, error %v",
devicePath, mountInfo.FSType, mountInfo.MountPath, err,
)
@ -35,7 +35,7 @@ func UmountVolume(vol *apis.ZFSVolume, targetPath string,
dev, ref, err := mount.GetDeviceNameFromMount(mounter, targetPath)
if err != nil {
logrus.Errorf(
klog.Errorf(
"zfspv umount volume: failed to get device from mnt: %s\nError: %v",
targetPath, err,
)
@ -44,7 +44,7 @@ func UmountVolume(vol *apis.ZFSVolume, targetPath string,
// device has already been un-mounted, return successful
if len(dev) == 0 || ref == 0 {
logrus.Warningf(
klog.Warningf(
"Warning: Unmount skipped because volume %s not mounted: %v",
vol.Name, targetPath,
)
@ -54,7 +54,7 @@ func UmountVolume(vol *apis.ZFSVolume, targetPath string,
if pathExists, pathErr := mount.PathExists(targetPath); pathErr != nil {
return fmt.Errorf("Error checking if path exists: %v", pathErr)
} else if !pathExists {
logrus.Warningf(
klog.Warningf(
"Warning: Unmount skipped because path does not exist: %v",
targetPath,
)
@ -62,7 +62,7 @@ func UmountVolume(vol *apis.ZFSVolume, targetPath string,
}
if err = mounter.Unmount(targetPath); err != nil {
logrus.Errorf(
klog.Errorf(
"zfs: failed to unmount %s: path %s err: %v",
vol.Name, targetPath, err,
)
@ -72,17 +72,17 @@ func UmountVolume(vol *apis.ZFSVolume, targetPath string,
if err = SetDatasetLegacyMount(vol); err != nil {
// ignoring the failure as the volume has already
// been umounted, now the new pod can mount it
logrus.Warningf(
klog.Warningf(
"zfs: failed to set legacy mountpoint: %s err: %v",
vol.Name, err,
)
}
if err := os.Remove(targetPath); err != nil {
logrus.Errorf("zfspv: failed to remove mount path vol %s err : %v", vol.Name, err)
klog.Errorf("zfspv: failed to remove mount path vol %s err : %v", vol.Name, err)
}
logrus.Infof("umount done %s path %v", vol.Name, targetPath)
klog.Infof("umount done %s path %v", vol.Name, targetPath)
return nil
}
@ -142,7 +142,7 @@ func verifyMountRequest(vol *apis.ZFSVolume, mountpath string) error {
devicePath, err := GetVolumeDevPath(vol)
if err != nil {
logrus.Errorf("can not get device for volume:%s dev %s err: %v",
klog.Errorf("can not get device for volume:%s dev %s err: %v",
vol.Name, devicePath, err.Error())
return status.Errorf(codes.Internal, "verifyMount: GetVolumePath failed %s", err.Error())
}
@ -156,11 +156,11 @@ func verifyMountRequest(vol *apis.ZFSVolume, mountpath string) error {
*/
currentMounts, err := GetMounts(devicePath)
if err != nil {
logrus.Errorf("can not get mounts for volume:%s dev %s err: %v",
klog.Errorf("can not get mounts for volume:%s dev %s err: %v",
vol.Name, devicePath, err.Error())
return status.Errorf(codes.Internal, "verifyMount: Getmounts failed %s", err.Error())
} else if len(currentMounts) >= 1 {
logrus.Errorf(
klog.Errorf(
"can not mount, volume:%s already mounted dev %s mounts: %v",
vol.Name, devicePath, currentMounts,
)
@ -184,7 +184,7 @@ func MountZvol(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
return status.Error(codes.Internal, "not able to format and mount the zvol")
}
logrus.Infof("zvol %v mounted %v fs %v", volume, mount.MountPath, mount.FSType)
klog.Infof("zvol %v mounted %v fs %v", volume, mount.MountPath, mount.FSType)
return err
}
@ -214,11 +214,11 @@ func MountDataset(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
cmd := exec.Command("mount", MountVolArg...)
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf("zfs: could not mount the dataset %v cmd %v error: %s",
klog.Errorf("zfs: could not mount the dataset %v cmd %v error: %s",
volume, MountVolArg, string(out))
return status.Errorf(codes.Internal, "dataset: mount failed err : %s", string(out))
}
logrus.Infof("dataset : legacy mounted %s => %s", volume, mount.MountPath)
klog.Infof("dataset : legacy mounted %s => %s", volume, mount.MountPath)
} else {
/*
* We might have created volumes and then upgraded the node agent before
@ -229,7 +229,7 @@ func MountDataset(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
if err != nil {
return status.Errorf(codes.Internal, "zfs: mount failed err : %s", err.Error())
}
logrus.Infof("dataset : mounted %s => %s", volume, mount.MountPath)
klog.Infof("dataset : mounted %s => %s", volume, mount.MountPath)
}
return nil
@ -267,7 +267,7 @@ func MountBlock(vol *apis.ZFSVolume, mountinfo *apis.MountInfo) error {
return status.Errorf(codes.Internal, "mount failed at %v err : %v", target, err)
}
logrus.Infof("NodePublishVolume mounted block device %s at %s", devicePath, target)
klog.Infof("NodePublishVolume mounted block device %s at %s", devicePath, target)
return nil
}

View file

@ -17,10 +17,11 @@ limitations under the License.
package zfs
import (
"github.com/Sirupsen/logrus"
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1"
"k8s.io/kubernetes/pkg/util/mount"
"os/exec"
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1"
"k8s.io/klog"
"k8s.io/kubernetes/pkg/util/mount"
)
// ResizeExtn can be used to run a resize command on the ext2/3/4 filesystem
@ -29,7 +30,7 @@ func ResizeExtn(devpath string) error {
cmd := exec.Command("resize2fs", devpath)
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf("zfspv: ResizeExtn failed error: %s", string(out))
klog.Errorf("zfspv: ResizeExtn failed error: %s", string(out))
return err
}
return nil
@ -41,7 +42,7 @@ func ResizeXFS(path string) error {
cmd := exec.Command("xfs_growfs", path)
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf("zfspv: ResizeXFS failed error: %s", string(out))
klog.Errorf("zfspv: ResizeXFS failed error: %s", string(out))
return err
}
return nil

View file

@ -15,7 +15,6 @@
package zfs
import (
"github.com/Sirupsen/logrus"
"os"
"strconv"
@ -24,6 +23,7 @@ import (
"github.com/openebs/zfs-localpv/pkg/builder/volbuilder"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog"
)
const (
@ -64,11 +64,11 @@ func init() {
OpenEBSNamespace = os.Getenv(OpenEBSNamespaceKey)
if OpenEBSNamespace == "" {
logrus.Fatalf("OPENEBS_NAMESPACE environment variable not set")
klog.Fatalf("OPENEBS_NAMESPACE environment variable not set")
}
NodeID = os.Getenv("OPENEBS_NODE_ID")
if NodeID == "" && os.Getenv("OPENEBS_NODE_DRIVER") != "" {
logrus.Fatalf("NodeID environment variable not set")
klog.Fatalf("NodeID environment variable not set")
}
GoogleAnalyticsEnabled = os.Getenv(GoogleAnalyticsKey)
@ -82,7 +82,7 @@ func ProvisionVolume(
_, err := volbuilder.NewKubeclient().WithNamespace(OpenEBSNamespace).Create(vol)
if err == nil {
logrus.Infof("provisioned volume %s", vol.Name)
klog.Infof("provisioned volume %s", vol.Name)
}
return err
@ -105,7 +105,7 @@ func ProvisionSnapshot(
_, err := snapbuilder.NewKubeclient().WithNamespace(OpenEBSNamespace).Create(snap)
if err == nil {
logrus.Infof("provisioned snapshot %s", snap.Name)
klog.Infof("provisioned snapshot %s", snap.Name)
}
return err
@ -115,7 +115,7 @@ func ProvisionSnapshot(
func DeleteSnapshot(snapname string) (err error) {
err = snapbuilder.NewKubeclient().WithNamespace(OpenEBSNamespace).Delete(snapname)
if err == nil {
logrus.Infof("deprovisioned snapshot %s", snapname)
klog.Infof("deprovisioned snapshot %s", snapname)
}
return
@ -132,7 +132,7 @@ func GetVolume(volumeID string) (*apis.ZFSVolume, error) {
func DeleteVolume(volumeID string) (err error) {
err = volbuilder.NewKubeclient().WithNamespace(OpenEBSNamespace).Delete(volumeID)
if err == nil {
logrus.Infof("deprovisioned volume %s", volumeID)
klog.Infof("deprovisioned volume %s", volumeID)
}
return
@ -217,7 +217,7 @@ func GetZFSSnapshotStatus(snapID string) (string, error) {
WithNamespace(OpenEBSNamespace).Get(snapID, getOptions)
if err != nil {
logrus.Errorf("Get snapshot failed %s err: %s", snap.Name, err.Error())
klog.Errorf("Get snapshot failed %s err: %s", snap.Name, err.Error())
return "", err
}
@ -241,7 +241,7 @@ func UpdateSnapInfo(snap *apis.ZFSSnapshot) error {
newSnap.Status.State = ZFSStatusReady
if err != nil {
logrus.Errorf("Update snapshot failed %s err: %s", snap.Name, err.Error())
klog.Errorf("Update snapshot failed %s err: %s", snap.Name, err.Error())
return err
}

View file

@ -20,8 +20,9 @@ import (
"os"
"os/exec"
"github.com/Sirupsen/logrus"
"strings"
"k8s.io/klog"
)
func xfsTempMount(volume string) error {
@ -32,7 +33,7 @@ func xfsTempMount(volume string) error {
tmpdir := "/tmp/" + pvol[1]
err := os.Mkdir(tmpdir, 0755)
if err != nil {
logrus.Errorf("xfs: failed to create tmpdir %s error: %s", tmpdir, err.Error())
klog.Errorf("xfs: failed to create tmpdir %s error: %s", tmpdir, err.Error())
return err
}
@ -40,7 +41,7 @@ func xfsTempMount(volume string) error {
cmd := exec.Command("mount", "-o", "nouuid", device, tmpdir)
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf("xfs: failed to mount volume %s=>%s error: %s", device, tmpdir, string(out))
klog.Errorf("xfs: failed to mount volume %s=>%s error: %s", device, tmpdir, string(out))
return err
}
@ -48,14 +49,14 @@ func xfsTempMount(volume string) error {
cmd = exec.Command("umount", tmpdir)
out, err = cmd.CombinedOutput()
if err != nil {
logrus.Errorf("xfs: failed to umount tmpdir %s error: %s", tmpdir, string(out))
klog.Errorf("xfs: failed to umount tmpdir %s error: %s", tmpdir, string(out))
return err
}
// remove the directory
err = os.Remove(tmpdir)
if err != nil {
logrus.Errorf("xfs: failed to remove tmpdir %s error: %s", tmpdir, err.Error())
klog.Errorf("xfs: failed to remove tmpdir %s error: %s", tmpdir, err.Error())
return err
}
return nil
@ -82,9 +83,9 @@ func xfsGenerateUuid(volume string) error {
cmd := exec.Command("xfs_admin", "-U", "generate", device)
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf("xfs: uuid generate failed %s error: %s", volume, string(out))
klog.Errorf("xfs: uuid generate failed %s error: %s", volume, string(out))
return err
}
logrus.Infof("xfs: generated UUID for the cloned volume %s \n %v", volume, string(out))
klog.Infof("xfs: generated UUID for the cloned volume %s \n %v", volume, string(out))
return nil
}

View file

@ -21,8 +21,9 @@ import (
"path/filepath"
"fmt"
"github.com/Sirupsen/logrus"
apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1"
"k8s.io/klog"
)
// zfs related constants
@ -328,14 +329,14 @@ func CreateVolume(vol *apis.ZFSVolume) error {
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf(
klog.Errorf(
"zfs: could not create volume %v cmd %v error: %s", volume, args, string(out),
)
return err
}
logrus.Infof("created volume %s", volume)
klog.Infof("created volume %s", volume)
} else if err == nil {
logrus.Infof("using existing volume %v", volume)
klog.Infof("using existing volume %v", volume)
}
return nil
@ -353,14 +354,14 @@ func CreateClone(vol *apis.ZFSVolume) error {
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf(
klog.Errorf(
"zfs: could not clone volume %v cmd %v error: %s", volume, args, string(out),
)
return err
}
logrus.Infof("created clone %s", volume)
klog.Infof("created clone %s", volume)
} else if err == nil {
logrus.Infof("using existing clone volume %v", volume)
klog.Infof("using existing clone volume %v", volume)
}
if vol.Spec.FsType == "xfs" {
@ -379,7 +380,7 @@ func SetDatasetMountProp(volume string, mountpath string) error {
cmd := exec.Command(ZFSVolCmd, ZFSVolArg...)
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf("zfs: could not set mountpoint on dataset %v cmd %v error: %s",
klog.Errorf("zfs: could not set mountpoint on dataset %v cmd %v error: %s",
volume, ZFSVolArg, string(out))
return fmt.Errorf("could not set the mountpoint, %s", string(out))
}
@ -413,7 +414,7 @@ func MountZFSDataset(vol *apis.ZFSVolume, mountpath string) error {
cmd := exec.Command(ZFSVolCmd, MountVolArg...)
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf("zfs: could not mount the dataset %v cmd %v error: %s",
klog.Errorf("zfs: could not mount the dataset %v cmd %v error: %s",
volume, MountVolArg, string(out))
return fmt.Errorf("not able to mount, %s", string(out))
}
@ -452,7 +453,7 @@ func GetVolumeProperty(vol *apis.ZFSVolume, prop string) (string, error) {
cmd := exec.Command(ZFSVolCmd, ZFSVolArg...)
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf("zfs: could not get %s on dataset %v cmd %v error: %s",
klog.Errorf("zfs: could not get %s on dataset %v cmd %v error: %s",
prop, volume, ZFSVolArg, string(out))
return "", fmt.Errorf("zfs get %s failed, %s", prop, string(out))
}
@ -491,12 +492,12 @@ func SetVolumeProp(vol *apis.ZFSVolume) error {
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf(
klog.Errorf(
"zfs: could not set property on volume %v cmd %v error: %s", volume, args, string(out),
)
return err
}
logrus.Infof("property set on volume %s", volume)
klog.Infof("property set on volume %s", volume)
return err
}
@ -506,7 +507,7 @@ func DestroyVolume(vol *apis.ZFSVolume) error {
volume := vol.Spec.PoolName + "/" + vol.Name
if err := getVolume(volume); err != nil {
logrus.Errorf(
klog.Errorf(
"destroy: volume %v is not present, error: %s", volume, err.Error(),
)
return nil
@ -517,12 +518,12 @@ func DestroyVolume(vol *apis.ZFSVolume) error {
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf(
klog.Errorf(
"zfs: could not destroy volume %v cmd %v error: %s", volume, args, string(out),
)
return err
}
logrus.Infof("destroyed volume %s", volume)
klog.Infof("destroyed volume %s", volume)
return nil
}
@ -534,7 +535,7 @@ func CreateSnapshot(snap *apis.ZFSSnapshot) error {
snapDataset := snap.Spec.PoolName + "/" + volume + "@" + snap.Name
if err := getVolume(snapDataset); err == nil {
logrus.Infof("snapshot already there %s", snapDataset)
klog.Infof("snapshot already there %s", snapDataset)
// snapshot already there just return
return nil
}
@ -544,12 +545,12 @@ func CreateSnapshot(snap *apis.ZFSSnapshot) error {
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf(
klog.Errorf(
"zfs: could not create snapshot %v@%v cmd %v error: %s", volume, snap.Name, args, string(out),
)
return err
}
logrus.Infof("created snapshot %s@%s", volume, snap.Name)
klog.Infof("created snapshot %s@%s", volume, snap.Name)
return nil
}
@ -560,7 +561,7 @@ func DestroySnapshot(snap *apis.ZFSSnapshot) error {
snapDataset := snap.Spec.PoolName + "/" + volume + "@" + snap.Name
if err := getVolume(snapDataset); err != nil {
logrus.Errorf(
klog.Errorf(
"destroy: snapshot %v is not present, error: %s", volume, err.Error(),
)
return nil
@ -571,12 +572,12 @@ func DestroySnapshot(snap *apis.ZFSSnapshot) error {
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf(
klog.Errorf(
"zfs: could not destroy snapshot %v@%v cmd %v error: %s", volume, snap.Name, args, string(out),
)
return err
}
logrus.Infof("deleted snapshot %s@%s", volume, snap.Name)
klog.Infof("deleted snapshot %s@%s", volume, snap.Name)
return nil
}
@ -607,7 +608,7 @@ func ResizeZFSVolume(vol *apis.ZFSVolume, mountpath string) error {
out, err := cmd.CombinedOutput()
if err != nil {
logrus.Errorf(
klog.Errorf(
"zfs: could not resize the volume %v cmd %v error: %s", volume, args, string(out),
)
return err