cleanup: address gomnd warnings

Direct usage of numbers should be avoided.

Issue reported:
mnd: Magic number: X, in <argument> detected (gomnd)

Signed-off-by: Yug <yuggupta27@gmail.com>
This commit is contained in:
Yug
2020-07-21 10:40:13 +05:30
committed by mergify[bot]
parent e73fe64a0d
commit 71ddf51544
11 changed files with 38 additions and 22 deletions

View File

@ -234,11 +234,13 @@ func (rv *rbdVolume) flattenCloneImage(ctx context.Context) error {
// can flatten the parent images before use to avoid the stale omap entries.
hardLimit := rbdHardMaxCloneDepth
softLimit := rbdSoftMaxCloneDepth
if rbdHardMaxCloneDepth < 2 {
hardLimit = rbdHardMaxCloneDepth - 2
// choosing 2 so that we don't need to flatten the image in the request.
const depthToAvoidFlatten = 2
if rbdHardMaxCloneDepth < depthToAvoidFlatten {
hardLimit = rbdHardMaxCloneDepth - depthToAvoidFlatten
}
if rbdSoftMaxCloneDepth < 2 {
softLimit = rbdSoftMaxCloneDepth - 2
if rbdSoftMaxCloneDepth < depthToAvoidFlatten {
softLimit = rbdSoftMaxCloneDepth - depthToAvoidFlatten
}
err := tempClone.getImageInfo()
if err == nil {

View File

@ -65,6 +65,7 @@ var (
kernelRelease = ""
// deepFlattenSupport holds the list of kernel which support mapping rbd
// image with deep-flatten image feature
// nolint:gomnd // numbers specify Kernel versions.
deepFlattenSupport = []util.KernelVersion{
{
Version: 5,

View File

@ -62,9 +62,6 @@ const (
rbdImageRequiresEncryption = "requiresEncryption"
// image metadata key for encryption
encryptionMetaKey = ".rbd.csi.ceph.com/encrypted"
// go-ceph will provide rbd.ImageOptionCloneFormat
imageOptionCloneFormat = librbd.RbdImageOption(12)
)
// rbdVolume represents a CSI volume and its RBD image specifics.
@ -856,7 +853,7 @@ func (rv *rbdVolume) cloneRbdImageFromSnapshot(ctx context.Context, pSnapOpts *r
}
}
err = options.SetUint64(imageOptionCloneFormat, 2)
err = options.SetUint64(librbd.ImageOptionCloneFormat, 2)
if err != nil {
return fmt.Errorf("failed to set image features: %w", err)
}
@ -1006,7 +1003,8 @@ func (ri *rbdImageMetadataStash) String() string {
// JSON format.
func stashRBDImageMetadata(volOptions *rbdVolume, path string) error {
var imgMeta = rbdImageMetadataStash{
Version: 2, // there are no checks for this at present
// there are no checks for this at present
Version: 2, // nolint:gomnd // number specifies version.
Pool: volOptions.Pool,
ImageName: volOptions.RbdImageName,
Encrypted: volOptions.Encrypted,