ceph: handle golangci-lint linter staticcheck error
this commit handle golangci-lint linter staticcheck error. `staticcheck` - Staticcheck is a go vet on steroids, applying a ton of static analysis checks. To see only `staticcheck` linter output `golangci-lint run --disable-all -E staticcheck` Signed-off-by: subhamkrai <srai@redhat.com>
This commit is contained in:
1 parent
1d5c590e4f
commit
de8dbbcdcc
22 files changed
+63
-86
No files matched your search
@@ -286,14 +286,17 @@ func getFlexDriverInfo(flexDriverPath string) (vendor, driver string, err error)
|
||||
parts := strings.Split(flexDriverPath, string(os.PathSeparator))
|
||||
for i := len(parts) - 1; i >= 0; i-- {
|
||||
p := parts[i]
|
||||
if matched, _ := regexp.Match(".+~.+", []byte(p)); matched {
|
||||
// found a match for the flex driver directory name pattern
|
||||
flexInfo := strings.Split(p, "~")
|
||||
if len(flexInfo) > 2 {
|
||||
return "", "", errors.Errorf("unexpected number of items in flex driver info %+v from path %s", flexInfo, flexDriverPath)
|
||||
}
|
||||
matched, err := regexp.Compile(".+~.+")
|
||||
if err == nil {
|
||||
if matched.Match([]byte(p)) {
|
||||
// found a match for the flex driver directory name pattern
|
||||
flexInfo := strings.Split(p, "~")
|
||||
if len(flexInfo) > 2 {
|
||||
return "", "", errors.Errorf("unexpected number of items in flex driver info %+v from path %s", flexInfo, flexDriverPath)
|
||||
}
|
||||
|
||||
return flexInfo[0], flexInfo[1], nil
|
||||
return flexInfo[0], flexInfo[1], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ func AuthUpdateCaps(context *clusterd.Context, clusterInfo *ClusterInfo, name st
|
||||
// AuthGetCaps gets the capabilities for the given user.
|
||||
func AuthGetCaps(context *clusterd.Context, clusterInfo *ClusterInfo, name string) (caps map[string]string, error error) {
|
||||
logger.Infof("getting ceph auth caps for %q", name)
|
||||
args := append([]string{"auth", "get", name})
|
||||
args := []string{"auth", "get", name}
|
||||
output, err := NewCephCommand(context, clusterInfo, args).Run()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to get caps for %q", name)
|
||||
|
||||
@@ -46,7 +46,7 @@ func TestCreateImage(t *testing.T) {
|
||||
return "", errors.Errorf("unexpected ceph command %q", args)
|
||||
}
|
||||
clusterInfo := AdminClusterInfo("mycluster")
|
||||
image, err := CreateImage(context, clusterInfo, "image1", "pool1", "", uint64(sizeMB)) // 1MB
|
||||
_, err := CreateImage(context, clusterInfo, "image1", "pool1", "", uint64(sizeMB)) // 1MB
|
||||
assert.NotNil(t, err)
|
||||
assert.True(t, strings.Contains(err.Error(), "mocked detailed ceph error output stream"))
|
||||
|
||||
@@ -70,7 +70,7 @@ func TestCreateImage(t *testing.T) {
|
||||
|
||||
// 0 byte --> 0 MB
|
||||
expectedSizeArg = "0"
|
||||
image, err = CreateImage(context, clusterInfo, "image1", "pool1", "", uint64(0))
|
||||
image, err := CreateImage(context, clusterInfo, "image1", "pool1", "", uint64(0))
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, image)
|
||||
assert.True(t, createCalled)
|
||||
|
||||
@@ -265,10 +265,10 @@ func TestCmdReporterHelperProcess(*testing.T) {
|
||||
}
|
||||
|
||||
if stdout != "" {
|
||||
fmt.Fprintf(os.Stdout, stdout)
|
||||
fmt.Fprint(os.Stdout, stdout)
|
||||
}
|
||||
if stderr != "" {
|
||||
fmt.Fprintf(os.Stderr, stderr)
|
||||
fmt.Fprint(os.Stderr, stderr)
|
||||
}
|
||||
if retcode != "" {
|
||||
rc, err := strconv.Atoi(retcode)
|
||||
|
||||
@@ -85,7 +85,7 @@ func TestCreateClusterSecrets(t *testing.T) {
|
||||
secret.Data[adminSecretNameKey] = []byte(adminSecretNameKey)
|
||||
_, err = clientset.CoreV1().Secrets(namespace).Update(secret)
|
||||
assert.NoError(t, err)
|
||||
info, _, _, err = CreateOrLoadClusterInfo(context, namespace, ownerRef)
|
||||
_, _, _, err = CreateOrLoadClusterInfo(context, namespace, ownerRef)
|
||||
assert.Error(t, err)
|
||||
|
||||
// Load the external cluster with the legacy external creds
|
||||
|
||||
@@ -215,7 +215,7 @@ func TestGetNodeInfoFromNode(t *testing.T) {
|
||||
}
|
||||
|
||||
var info *NodeInfo
|
||||
info, err = getNodeInfoFromNode(*node)
|
||||
_, err = getNodeInfoFromNode(*node)
|
||||
assert.NotNil(t, err)
|
||||
|
||||
node.Status.Addresses[0].Type = v1.NodeInternalIP
|
||||
|
||||
@@ -748,7 +748,7 @@ func (c *Cluster) getPVCHostName(pvcName string) (string, error) {
|
||||
if name == "" {
|
||||
return "", errors.Errorf("node name not found on the osd pod %q", pod.Name)
|
||||
}
|
||||
return name, nil
|
||||
return name, nil //nolint, no need for else statement
|
||||
}
|
||||
|
||||
return "", errors.Errorf("node selector not found on deployment for osd with pvc %q", pvcName)
|
||||
|
||||
@@ -74,7 +74,6 @@ func TestCephRBDMirrorController(t *testing.T) {
|
||||
},
|
||||
TypeMeta: controllerTypeMeta,
|
||||
}
|
||||
cephCluster := &cephv1.CephCluster{}
|
||||
|
||||
// Objects to track in the fake client.
|
||||
object := []runtime.Object{
|
||||
@@ -146,7 +145,7 @@ func TestCephRBDMirrorController(t *testing.T) {
|
||||
//
|
||||
// FAILURE we have a cluster but it's not ready
|
||||
//
|
||||
cephCluster = &cephv1.CephCluster{
|
||||
cephCluster := &cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: namespace,
|
||||
Namespace: namespace,
|
||||
|
||||
@@ -150,9 +150,8 @@ func CephVolumeMounts(dataPaths *config.DataPathMap, confGeneratedInPod bool) []
|
||||
// RookVolumeMounts returns the common list of Kubernetes volume mounts for Rook containers.
|
||||
// This function is only used by OSDs.
|
||||
func RookVolumeMounts(dataPaths *config.DataPathMap, confGeneratedInPod bool) []v1.VolumeMount {
|
||||
return append(
|
||||
CephVolumeMounts(dataPaths, confGeneratedInPod),
|
||||
)
|
||||
return CephVolumeMounts(dataPaths, confGeneratedInPod)
|
||||
|
||||
}
|
||||
|
||||
// DaemonVolumesBase returns the common / static set of volumes.
|
||||
|
||||
@@ -17,8 +17,6 @@ limitations under the License.
|
||||
package clusterdisruption
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
"github.com/rook/rook/pkg/operator/ceph/cluster/mon"
|
||||
@@ -40,7 +38,7 @@ const (
|
||||
// odd - floor((n+1)/2)
|
||||
func (r *ReconcileClusterDisruption) reconcileMonPDB(cephCluster *cephv1.CephCluster) error {
|
||||
monCount := cephCluster.Spec.Mon.Count
|
||||
minAvailable := int32(math.Floor(float64((monCount + 1) / 2)))
|
||||
minAvailable := int32(float64((monCount + 1) / 2))
|
||||
if monCount%2 == 0 {
|
||||
logger.Error("mon count should be an odd number, setting effective maxUnvailable to 1")
|
||||
minAvailable = int32(monCount - 1)
|
||||
|
||||
@@ -169,7 +169,6 @@ func TestCephFilesystemController(t *testing.T) {
|
||||
},
|
||||
TypeMeta: controllerTypeMeta,
|
||||
}
|
||||
cephCluster := &cephv1.CephCluster{}
|
||||
|
||||
// Objects to track in the fake client.
|
||||
object := []runtime.Object{
|
||||
@@ -224,7 +223,7 @@ func TestCephFilesystemController(t *testing.T) {
|
||||
//
|
||||
// FAILURE we have a cluster but it's not ready
|
||||
//
|
||||
cephCluster = &cephv1.CephCluster{
|
||||
cephCluster := &cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: namespace,
|
||||
Namespace: namespace,
|
||||
|
||||
@@ -119,12 +119,10 @@ func (c *Cluster) makeMdsDaemonContainer(mdsConfig *mdsConfig) v1.Container {
|
||||
Command: []string{
|
||||
"ceph-mds",
|
||||
},
|
||||
Args: args,
|
||||
Image: c.clusterSpec.CephVersion.Image,
|
||||
VolumeMounts: controller.DaemonVolumeMounts(mdsConfig.DataPathMap, mdsConfig.ResourceName),
|
||||
Env: append(
|
||||
controller.DaemonEnvVars(c.clusterSpec.CephVersion.Image),
|
||||
),
|
||||
Args: args,
|
||||
Image: c.clusterSpec.CephVersion.Image,
|
||||
VolumeMounts: controller.DaemonVolumeMounts(mdsConfig.DataPathMap, mdsConfig.ResourceName),
|
||||
Env: controller.DaemonEnvVars(c.clusterSpec.CephVersion.Image),
|
||||
Resources: c.fs.Spec.MetadataServer.Resources,
|
||||
SecurityContext: mon.PodSecurityContext(),
|
||||
LivenessProbe: controller.GenerateLivenessProbeExecDaemon(config.MdsType, mdsConfig.DaemonID),
|
||||
|
||||
@@ -97,7 +97,6 @@ func TestCephNFSController(t *testing.T) {
|
||||
},
|
||||
TypeMeta: controllerTypeMeta,
|
||||
}
|
||||
cephCluster := &cephv1.CephCluster{}
|
||||
|
||||
// Objects to track in the fake client.
|
||||
object := []runtime.Object{
|
||||
@@ -151,7 +150,7 @@ func TestCephNFSController(t *testing.T) {
|
||||
//
|
||||
// FAILURE we have a cluster but it's not ready
|
||||
//
|
||||
cephCluster = &cephv1.CephCluster{
|
||||
cephCluster := &cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: namespace,
|
||||
Namespace: namespace,
|
||||
|
||||
@@ -207,9 +207,7 @@ func (r *ReconcileCephNFS) daemonContainer(nfs *cephv1.CephNFS, cfg daemonConfig
|
||||
nfsConfigMount,
|
||||
dbusMount,
|
||||
},
|
||||
Env: append(
|
||||
controller.DaemonEnvVars(r.cephClusterSpec.CephVersion.Image),
|
||||
),
|
||||
Env: controller.DaemonEnvVars(r.cephClusterSpec.CephVersion.Image),
|
||||
Resources: nfs.Spec.Server.Resources,
|
||||
SecurityContext: mon.PodSecurityContext(),
|
||||
}
|
||||
@@ -233,10 +231,7 @@ func (r *ReconcileCephNFS) dbusContainer(nfs *cephv1.CephNFS) v1.Container {
|
||||
VolumeMounts: []v1.VolumeMount{
|
||||
dbusMount,
|
||||
},
|
||||
Env: append(
|
||||
// do not need access to Ceph env vars b/c not a Ceph daemon
|
||||
k8sutil.ClusterDaemonEnvVars(r.cephClusterSpec.CephVersion.Image),
|
||||
),
|
||||
Env: k8sutil.ClusterDaemonEnvVars(r.cephClusterSpec.CephVersion.Image), // do not need access to Ceph env vars b/c not a Ceph daemon
|
||||
Resources: nfs.Spec.Server.Resources,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,6 @@ func TestCephObjectStoreController(t *testing.T) {
|
||||
Spec: cephv1.ObjectStoreSpec{},
|
||||
TypeMeta: controllerTypeMeta,
|
||||
}
|
||||
cephCluster := &cephv1.CephCluster{}
|
||||
objectStore.Spec.Gateway.Port = 80
|
||||
|
||||
// Objects to track in the fake client.
|
||||
@@ -262,7 +261,7 @@ func TestCephObjectStoreController(t *testing.T) {
|
||||
//
|
||||
// FAILURE we have a cluster but it's not ready
|
||||
//
|
||||
cephCluster = &cephv1.CephCluster{
|
||||
cephCluster := &cephv1.CephCluster{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: namespace,
|
||||
Namespace: namespace,
|
||||
|
||||
@@ -150,16 +150,14 @@ func (c *clusterConfig) makeDaemonContainer(rgwConfig *rgwConfig) v1.Container {
|
||||
"radosgw",
|
||||
},
|
||||
Args: append(
|
||||
append(
|
||||
controller.DaemonFlags(c.clusterInfo, strings.TrimPrefix(generateCephXUser(rgwConfig.ResourceName), "client.")),
|
||||
"--foreground",
|
||||
cephconfig.NewFlag("rgw frontends", fmt.Sprintf("%s %s", rgwFrontendName, c.portString())),
|
||||
cephconfig.NewFlag("host", controller.ContainerEnvVarReference(k8sutil.PodNameEnvVar)),
|
||||
cephconfig.NewFlag("rgw-mime-types-file", mimeTypesMountPath()),
|
||||
cephconfig.NewFlag("rgw realm", rgwConfig.Realm),
|
||||
cephconfig.NewFlag("rgw zonegroup", rgwConfig.ZoneGroup),
|
||||
cephconfig.NewFlag("rgw zone", rgwConfig.Zone),
|
||||
),
|
||||
controller.DaemonFlags(c.clusterInfo, strings.TrimPrefix(generateCephXUser(rgwConfig.ResourceName), "client.")),
|
||||
"--foreground",
|
||||
cephconfig.NewFlag("rgw frontends", fmt.Sprintf("%s %s", rgwFrontendName, c.portString())),
|
||||
cephconfig.NewFlag("host", controller.ContainerEnvVarReference(k8sutil.PodNameEnvVar)),
|
||||
cephconfig.NewFlag("rgw-mime-types-file", mimeTypesMountPath()),
|
||||
cephconfig.NewFlag("rgw realm", rgwConfig.Realm),
|
||||
cephconfig.NewFlag("rgw zonegroup", rgwConfig.ZoneGroup),
|
||||
cephconfig.NewFlag("rgw zone", rgwConfig.Zone),
|
||||
),
|
||||
VolumeMounts: append(
|
||||
controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName),
|
||||
|
||||
@@ -241,7 +241,7 @@ func UnlinkUser(c *Context, id, bucket string) (string, int, error) {
|
||||
// EnableUserQuota will allows to enable quota defined for a user
|
||||
func EnableUserQuota(c *Context, id string) (string, error) {
|
||||
logger.Debug("Enabling user quota for %q", id)
|
||||
args := append([]string{"quota", "enable", "--quota-scope", "user", "--uid", id})
|
||||
args := []string{"quota", "enable", "--quota-scope", "user", "--uid", id}
|
||||
result, err := runAdminCommand(c, args...)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "failed to enable quota for the user")
|
||||
|
||||
@@ -264,7 +264,10 @@ func GetPodLog(clientset kubernetes.Interface, namespace string, labelSelector s
|
||||
builder := &strings.Builder{}
|
||||
defer readCloser.Close()
|
||||
_, err = io.Copy(builder, readCloser)
|
||||
return builder.String(), err
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "error copying file from %s to %s", builder, readCloser)
|
||||
}
|
||||
return builder.String(), err //nolint, no else statement needed
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("did not find any pods with label %s", labelSelector)
|
||||
|
||||
@@ -122,7 +122,6 @@ func CreateOrUpdatePrometheusRule(prometheusRule *monitoringv1.PrometheusRule) (
|
||||
}
|
||||
prometheusRule.ObjectMeta.ResourceVersion = promRule.ObjectMeta.ResourceVersion
|
||||
|
||||
promRule, err = client.MonitoringV1().PrometheusRules(namespace).Update(prometheusRule)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to update prometheusRule. %v", err)
|
||||
}
|
||||
|
||||
@@ -175,14 +175,6 @@ func validateClusterSpec(spec yugabytedbv1alpha1.YBClusterSpec) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if &spec.Master.VolumeClaimTemplate == nil {
|
||||
return fmt.Errorf("VolumeClaimTemplate unavailable in Master spec.")
|
||||
}
|
||||
|
||||
if &spec.TServer.VolumeClaimTemplate == nil {
|
||||
return fmt.Errorf("VolumeClaimTemplate unavailable in TServer spec.")
|
||||
}
|
||||
|
||||
if err := validateResourceSpec(spec.Master.Resource, false); err != nil {
|
||||
return errors.Wrap(err, "failed to validate resource spec")
|
||||
}
|
||||
@@ -195,7 +187,7 @@ func validateClusterSpec(spec yugabytedbv1alpha1.YBClusterSpec) error {
|
||||
}
|
||||
|
||||
func validateResourceSpec(resourceSpec v1.ResourceRequirements, isTServer bool) error {
|
||||
if (&resourceSpec.Requests == nil || len(resourceSpec.Requests) != 0) && (&resourceSpec.Limits == nil || len(resourceSpec.Limits) != 0) {
|
||||
if (len(resourceSpec.Requests) != 0) && (len(resourceSpec.Limits) != 0) {
|
||||
reqCPU, reqOk := resourceSpec.Requests[v1.ResourceCPU]
|
||||
limCPU, limOk := resourceSpec.Limits[v1.ResourceCPU]
|
||||
podName := "Master"
|
||||
@@ -379,10 +371,8 @@ func createMasterContainerCommand(namespace, serviceName string, masterCompleteN
|
||||
"--logtostderr",
|
||||
}
|
||||
|
||||
if &resources.Limits != nil {
|
||||
if memLimit, ok := getMemoryLimitBytes(resources); ok {
|
||||
command = append(command, fmt.Sprintf("--memory_limit_hard_bytes=%d", memLimit))
|
||||
}
|
||||
if memLimit, ok := getMemoryLimitBytes(resources); ok {
|
||||
command = append(command, fmt.Sprintf("--memory_limit_hard_bytes=%d", memLimit))
|
||||
}
|
||||
|
||||
return command
|
||||
@@ -401,10 +391,8 @@ func createTServerContainerCommand(namespace, serviceName, masterServiceName str
|
||||
"--logtostderr",
|
||||
}
|
||||
|
||||
if &resources.Limits != nil {
|
||||
if memLimit, ok := getMemoryLimitBytes(resources); ok {
|
||||
command = append(command, fmt.Sprintf("--memory_limit_hard_bytes=%d", memLimit))
|
||||
}
|
||||
if memLimit, ok := getMemoryLimitBytes(resources); ok {
|
||||
command = append(command, fmt.Sprintf("--memory_limit_hard_bytes=%d", memLimit))
|
||||
}
|
||||
|
||||
return command
|
||||
@@ -484,11 +472,9 @@ func (c *cluster) addCRNameSuffix(str string) string {
|
||||
func getResourceSpec(resourceSpec v1.ResourceRequirements, isTServerStatefulset bool) v1.ResourceRequirements {
|
||||
resources := resourceSpec
|
||||
|
||||
if &resources == nil {
|
||||
resources = v1.ResourceRequirements{
|
||||
Requests: make(map[v1.ResourceName]resource.Quantity),
|
||||
Limits: make(map[v1.ResourceName]resource.Quantity),
|
||||
}
|
||||
resources = v1.ResourceRequirements{
|
||||
Requests: make(map[v1.ResourceName]resource.Quantity),
|
||||
Limits: make(map[v1.ResourceName]resource.Quantity),
|
||||
}
|
||||
|
||||
if len(resources.Requests) != 0 || len(resources.Limits) != 0 {
|
||||
@@ -501,13 +487,13 @@ func getResourceSpec(resourceSpec v1.ResourceRequirements, isTServerStatefulset
|
||||
memoryLimit = tserverMemLimitDefault
|
||||
}
|
||||
|
||||
if &resources.Requests == nil || len(resources.Requests) == 0 {
|
||||
if len(resources.Requests) == 0 {
|
||||
resources.Requests = make(map[v1.ResourceName]resource.Quantity)
|
||||
resources.Requests[v1.ResourceCPU] = resource.MustParse(podCPULimitDefault)
|
||||
resources.Requests[v1.ResourceMemory] = resource.MustParse(memoryLimit)
|
||||
}
|
||||
|
||||
if &resources.Limits == nil || len(resources.Limits) == 0 {
|
||||
if len(resources.Limits) == 0 {
|
||||
resources.Limits = make(map[v1.ResourceName]resource.Quantity)
|
||||
resources.Limits[v1.ResourceCPU] = resource.MustParse(podCPULimitDefault)
|
||||
resources.Limits[v1.ResourceMemory] = resource.MustParse(memoryLimit)
|
||||
|
||||
@@ -114,16 +114,18 @@ func (p *PoolOperation) DeletePool(blockClient *BlockOperation, clusterInfo *cli
|
||||
blockImagesList, _ := blockClient.ListImagesInPool(clusterInfo, poolName)
|
||||
for _, blockImage := range blockImagesList {
|
||||
logger.Infof("force deleting block image %q in pool %q", blockImage, poolName)
|
||||
max := 10
|
||||
// Wait and retry up to 10 times/seconds to delete RBD images
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := 0; i < max; i++ {
|
||||
err := blockClient.DeleteBlockImage(clusterInfo, blockImage)
|
||||
if err != nil {
|
||||
logger.Infof("failed deleting image %q from %q. %v", blockImage, poolName, err)
|
||||
time.Sleep(2 * time.Second)
|
||||
} else {
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
return fmt.Errorf("gave up waiting for image %q from %q to be deleted. %v", blockImage, poolName, err)
|
||||
logger.Infof("failed deleting image %q from %q. %v", blockImage, poolName, err)
|
||||
time.Sleep(2 * time.Second)
|
||||
if i == max-1 {
|
||||
return fmt.Errorf("gave up waiting for image %q from %q to be deleted. %v", blockImage, poolName, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -560,7 +560,7 @@ func (k8sh *K8sHelper) GetEventsFromNamespace(namespace, testName, platformName
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
args := append([]string{"get", "events", "-n", namespace})
|
||||
args := []string{"get", "events", "-n", namespace}
|
||||
events, err := k8sh.Kubectl(args...)
|
||||
if err != nil {
|
||||
logger.Errorf("failed to get events. %v. %v", args, err)
|
||||
|
||||
Reference in new issue
Block a user