cleanup: Modifies Wrapcheck linter

Wrapcheck is a  simple Go linter to check that errors
from external packages are wrapped during return to
help identify the error source during debugging.
This commit addresses the wrapcheck error

Updates:#2025

Signed-off-by: Yati Padia <ypadia@redhat.com>
This commit is contained in:
Yati Padia 2021-05-11 14:58:56 +05:30 committed by mergify[bot]
parent 591ba3f580
commit 847b996501
14 changed files with 72 additions and 57 deletions

View File

@ -24,7 +24,7 @@ func validateSubvolumegroup(f *framework.Framework, subvolgrp string) error {
cmd := fmt.Sprintf("ceph fs subvolumegroup getpath myfs %s", subvolgrp) cmd := fmt.Sprintf("ceph fs subvolumegroup getpath myfs %s", subvolgrp)
stdOut, stdErr, err := execCommandInToolBoxPod(f, cmd, rookNamespace) stdOut, stdErr, err := execCommandInToolBoxPod(f, cmd, rookNamespace)
if err != nil { if err != nil {
return err return fmt.Errorf("failed to exec command in toolbox: %w", err)
} }
if stdErr != "" { if stdErr != "" {
return fmt.Errorf("failed to getpath for subvolumegroup %s with error %v", subvolgrp, stdErr) return fmt.Errorf("failed to getpath for subvolumegroup %s with error %v", subvolgrp, stdErr)
@ -106,12 +106,12 @@ func unmountCephFSVolume(f *framework.Framework, appName, pvcName string) error
pod, err := f.ClientSet.CoreV1().Pods(f.UniqueName).Get(context.TODO(), appName, metav1.GetOptions{}) pod, err := f.ClientSet.CoreV1().Pods(f.UniqueName).Get(context.TODO(), appName, metav1.GetOptions{})
if err != nil { if err != nil {
e2elog.Logf("Error occurred getting pod %s in namespace %s", appName, f.UniqueName) e2elog.Logf("Error occurred getting pod %s in namespace %s", appName, f.UniqueName)
return err return fmt.Errorf("failed to get pod: %w", err)
} }
pvc, err := f.ClientSet.CoreV1().PersistentVolumeClaims(f.UniqueName).Get(context.TODO(), pvcName, metav1.GetOptions{}) pvc, err := f.ClientSet.CoreV1().PersistentVolumeClaims(f.UniqueName).Get(context.TODO(), pvcName, metav1.GetOptions{})
if err != nil { if err != nil {
e2elog.Logf("Error occurred getting PVC %s in namespace %s", pvcName, f.UniqueName) e2elog.Logf("Error occurred getting PVC %s in namespace %s", pvcName, f.UniqueName)
return err return fmt.Errorf("failed to get pvc: %w", err)
} }
cmd := fmt.Sprintf("umount /var/lib/kubelet/pods/%s/volumes/kubernetes.io~csi/%s/mount", pod.UID, pvc.Spec.VolumeName) cmd := fmt.Sprintf("umount /var/lib/kubelet/pods/%s/volumes/kubernetes.io~csi/%s/mount", pod.UID, pvc.Spec.VolumeName)
_, stdErr, err := execCommandInDaemonsetPod(f, cmd, cephfsDeamonSetName, pod.Spec.NodeName, cephfsContainerName, cephCSINamespace) _, stdErr, err := execCommandInDaemonsetPod(f, cmd, cephfsDeamonSetName, pod.Spec.NodeName, cephfsContainerName, cephCSINamespace)
@ -179,11 +179,11 @@ func getSnapName(snapNamespace, snapName string) (string, error) {
} }
snap, err := sclient.SnapshotV1beta1().VolumeSnapshots(snapNamespace).Get(context.TODO(), snapName, metav1.GetOptions{}) snap, err := sclient.SnapshotV1beta1().VolumeSnapshots(snapNamespace).Get(context.TODO(), snapName, metav1.GetOptions{})
if err != nil { if err != nil {
return "", err return "", fmt.Errorf("failed to get volumesnapshot: %w", err)
} }
sc, err := sclient.SnapshotV1beta1().VolumeSnapshotContents().Get(context.TODO(), *snap.Status.BoundVolumeSnapshotContentName, metav1.GetOptions{}) sc, err := sclient.SnapshotV1beta1().VolumeSnapshotContents().Get(context.TODO(), *snap.Status.BoundVolumeSnapshotContentName, metav1.GetOptions{})
if err != nil { if err != nil {
return "", err return "", fmt.Errorf("failed to get volumesnapshotcontent: %w", err)
} }
snapIDRegex := regexp.MustCompile(`(\w+\-?){5}$`) snapIDRegex := regexp.MustCompile(`(\w+\-?){5}$`)
snapID := snapIDRegex.FindString(*sc.Status.SnapshotHandle) snapID := snapIDRegex.FindString(*sc.Status.SnapshotHandle)

View File

@ -68,7 +68,7 @@ func createConfigMap(pluginPath string, c kubernetes.Interface, f *framework.Fra
if err == nil { if err == nil {
_, updateErr := c.CoreV1().ConfigMaps(cephCSINamespace).Update(context.TODO(), &cm, metav1.UpdateOptions{}) _, updateErr := c.CoreV1().ConfigMaps(cephCSINamespace).Update(context.TODO(), &cm, metav1.UpdateOptions{})
if updateErr != nil { if updateErr != nil {
return updateErr return fmt.Errorf("failed to update configmap: %w", updateErr)
} }
} }
if apierrs.IsNotFound(err) { if apierrs.IsNotFound(err) {
@ -116,5 +116,8 @@ func createCustomConfigMap(c kubernetes.Interface, pluginPath string, subvolgrpI
cm.Namespace = cephCSINamespace cm.Namespace = cephCSINamespace
// since a configmap is already created, update the existing configmap // since a configmap is already created, update the existing configmap
_, err = c.CoreV1().ConfigMaps(cephCSINamespace).Update(context.TODO(), &cm, metav1.UpdateOptions{}) _, err = c.CoreV1().ConfigMaps(cephCSINamespace).Update(context.TODO(), &cm, metav1.UpdateOptions{})
return err if err != nil {
return fmt.Errorf("failed to update configmap: %w", err)
}
return nil
} }

View File

@ -24,7 +24,7 @@ func createNamespace(c kubernetes.Interface, name string) error {
} }
_, err := c.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{}) _, err := c.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{})
if err != nil && !apierrs.IsAlreadyExists(err) { if err != nil && !apierrs.IsAlreadyExists(err) {
return err return fmt.Errorf("failed to create namespace: %w", err)
} }
return wait.PollImmediate(poll, timeout, func() (bool, error) { return wait.PollImmediate(poll, timeout, func() (bool, error) {
@ -47,7 +47,7 @@ func deleteNamespace(c kubernetes.Interface, name string) error {
timeout := time.Duration(deployTimeout) * time.Minute timeout := time.Duration(deployTimeout) * time.Minute
err := c.CoreV1().Namespaces().Delete(context.TODO(), name, metav1.DeleteOptions{}) err := c.CoreV1().Namespaces().Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil && !apierrs.IsNotFound(err) { if err != nil && !apierrs.IsNotFound(err) {
return err return fmt.Errorf("failed to delete namespace: %w", err)
} }
return wait.PollImmediate(poll, timeout, func() (bool, error) { return wait.PollImmediate(poll, timeout, func() (bool, error) {
_, err = c.CoreV1().Namespaces().Get(context.TODO(), name, metav1.GetOptions{}) _, err = c.CoreV1().Namespaces().Get(context.TODO(), name, metav1.GetOptions{})

View File

@ -3,6 +3,7 @@ package e2e
import ( import (
"context" "context"
"errors" "errors"
"fmt"
core "k8s.io/api/core/v1" core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -15,7 +16,7 @@ func createNodeLabel(f *framework.Framework, labelKey, labelValue string) error
// the same label values, which is fine for the test // the same label values, which is fine for the test
nodes, err := f.ClientSet.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}) nodes, err := f.ClientSet.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to list node: %w", err)
} }
for i := range nodes.Items { for i := range nodes.Items {
framework.AddOrUpdateLabelOnNode(f.ClientSet, nodes.Items[i].Name, labelKey, labelValue) framework.AddOrUpdateLabelOnNode(f.ClientSet, nodes.Items[i].Name, labelKey, labelValue)
@ -26,7 +27,7 @@ func createNodeLabel(f *framework.Framework, labelKey, labelValue string) error
func deleteNodeLabel(c kubernetes.Interface, labelKey string) error { func deleteNodeLabel(c kubernetes.Interface, labelKey string) error {
nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}) nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to list node: %w", err)
} }
for i := range nodes.Items { for i := range nodes.Items {
framework.RemoveLabelOffNode(c, nodes.Items[i].Name, labelKey) framework.RemoveLabelOffNode(c, nodes.Items[i].Name, labelKey)
@ -37,7 +38,7 @@ func deleteNodeLabel(c kubernetes.Interface, labelKey string) error {
func checkNodeHasLabel(c kubernetes.Interface, labelKey, labelValue string) error { func checkNodeHasLabel(c kubernetes.Interface, labelKey, labelValue string) error {
nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}) nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to list node: %w", err)
} }
for i := range nodes.Items { for i := range nodes.Items {
framework.ExpectNodeHasLabel(c, nodes.Items[i].Name, labelKey, labelValue) framework.ExpectNodeHasLabel(c, nodes.Items[i].Name, labelKey, labelValue)
@ -50,7 +51,7 @@ func checkNodeHasLabel(c kubernetes.Interface, labelKey, labelValue string) erro
func getKubeletIP(c kubernetes.Interface) (string, error) { func getKubeletIP(c kubernetes.Interface) (string, error) {
nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{}) nodes, err := c.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{})
if err != nil { if err != nil {
return "", err return "", fmt.Errorf("failed to list node: %w", err)
} }
for _, address := range nodes.Items[0].Status.Addresses { for _, address := range nodes.Items[0].Status.Addresses {

View File

@ -257,7 +257,7 @@ func loadApp(path string) (*v1.Pod, error) {
func createApp(c kubernetes.Interface, app *v1.Pod, timeout int) error { func createApp(c kubernetes.Interface, app *v1.Pod, timeout int) error {
_, err := c.CoreV1().Pods(app.Namespace).Create(context.TODO(), app, metav1.CreateOptions{}) _, err := c.CoreV1().Pods(app.Namespace).Create(context.TODO(), app, metav1.CreateOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to create app: %w", err)
} }
return waitForPodInRunningState(app.Name, app.Namespace, c, timeout) return waitForPodInRunningState(app.Name, app.Namespace, c, timeout)
} }
@ -269,7 +269,7 @@ func waitForPodInRunningState(name, ns string, c kubernetes.Interface, t int) er
return wait.PollImmediate(poll, timeout, func() (bool, error) { return wait.PollImmediate(poll, timeout, func() (bool, error) {
pod, err := c.CoreV1().Pods(ns).Get(context.TODO(), name, metav1.GetOptions{}) pod, err := c.CoreV1().Pods(ns).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil { if err != nil {
return false, err return false, fmt.Errorf("failed to get app: %w", err)
} }
switch pod.Status.Phase { switch pod.Status.Phase {
case v1.PodRunning: case v1.PodRunning:
@ -286,7 +286,7 @@ func deletePod(name, ns string, c kubernetes.Interface, t int) error {
timeout := time.Duration(t) * time.Minute timeout := time.Duration(t) * time.Minute
err := c.CoreV1().Pods(ns).Delete(context.TODO(), name, metav1.DeleteOptions{}) err := c.CoreV1().Pods(ns).Delete(context.TODO(), name, metav1.DeleteOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to delete app: %w", err)
} }
start := time.Now() start := time.Now()
e2elog.Logf("Waiting for pod %v to be deleted", name) e2elog.Logf("Waiting for pod %v to be deleted", name)
@ -298,7 +298,7 @@ func deletePod(name, ns string, c kubernetes.Interface, t int) error {
} }
e2elog.Logf("%s app to be deleted (%d seconds elapsed)", name, int(time.Since(start).Seconds())) e2elog.Logf("%s app to be deleted (%d seconds elapsed)", name, int(time.Since(start).Seconds()))
if err != nil { if err != nil {
return false, err return false, fmt.Errorf("failed to get app: %w", err)
} }
return false, nil return false, nil
}) })

View File

@ -32,7 +32,7 @@ func createPVCAndvalidatePV(c kubernetes.Interface, pvc *v1.PersistentVolumeClai
var err error var err error
_, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{}) _, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to create pvc: %w", err)
} }
if timeout == 0 { if timeout == 0 {
return nil return nil
@ -52,7 +52,7 @@ func createPVCAndvalidatePV(c kubernetes.Interface, pvc *v1.PersistentVolumeClai
if apierrs.IsNotFound(err) { if apierrs.IsNotFound(err) {
return false, nil return false, nil
} }
return false, err return false, fmt.Errorf("failed to get pvc: %w", err)
} }
if pvc.Spec.VolumeName == "" { if pvc.Spec.VolumeName == "" {
@ -61,7 +61,7 @@ func createPVCAndvalidatePV(c kubernetes.Interface, pvc *v1.PersistentVolumeClai
pv, err = c.CoreV1().PersistentVolumes().Get(context.TODO(), pvc.Spec.VolumeName, metav1.GetOptions{}) pv, err = c.CoreV1().PersistentVolumes().Get(context.TODO(), pvc.Spec.VolumeName, metav1.GetOptions{})
if err != nil { if err != nil {
return false, err return false, fmt.Errorf("failed to get pv: %w", err)
} }
if apierrs.IsNotFound(err) { if apierrs.IsNotFound(err) {
return false, nil return false, nil
@ -77,20 +77,23 @@ func createPVCAndvalidatePV(c kubernetes.Interface, pvc *v1.PersistentVolumeClai
func createPVCAndPV(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) error { func createPVCAndPV(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume) error {
_, err := c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{}) _, err := c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to create pvc: %w", err)
} }
_, err = c.CoreV1().PersistentVolumes().Create(context.TODO(), pv, metav1.CreateOptions{}) _, err = c.CoreV1().PersistentVolumes().Create(context.TODO(), pv, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("failed to create pv: %w", err)
}
return err return err
} }
func deletePVCAndPV(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume, t int) error { func deletePVCAndPV(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, pv *v1.PersistentVolume, t int) error {
err := c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(context.TODO(), pvc.Name, metav1.DeleteOptions{}) err := c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(context.TODO(), pvc.Name, metav1.DeleteOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to delete pvc: %w", err)
} }
err = c.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{}) err = c.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to delete pv: %w", err)
} }
timeout := time.Duration(t) * time.Minute timeout := time.Duration(t) * time.Minute
@ -116,7 +119,7 @@ func deletePVCAndPV(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, pv *v
return true, nil return true, nil
}) })
if err != nil { if err != nil {
return err return fmt.Errorf("failed to poll: %w", err)
} }
start = time.Now() start = time.Now()
@ -159,11 +162,11 @@ func deletePVCAndValidatePV(c kubernetes.Interface, pvc *v1.PersistentVolumeClai
pvc, err = c.CoreV1().PersistentVolumeClaims(nameSpace).Get(context.TODO(), name, metav1.GetOptions{}) pvc, err = c.CoreV1().PersistentVolumeClaims(nameSpace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to get pvc: %w", err)
} }
pv, err := c.CoreV1().PersistentVolumes().Get(context.TODO(), pvc.Spec.VolumeName, metav1.GetOptions{}) pv, err := c.CoreV1().PersistentVolumes().Get(context.TODO(), pvc.Spec.VolumeName, metav1.GetOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to get pv: %w", err)
} }
err = c.CoreV1().PersistentVolumeClaims(nameSpace).Delete(context.TODO(), name, metav1.DeleteOptions{}) err = c.CoreV1().PersistentVolumeClaims(nameSpace).Delete(context.TODO(), name, metav1.DeleteOptions{})
@ -201,12 +204,15 @@ func getBoundPV(client kubernetes.Interface, pvc *v1.PersistentVolumeClaim) (*v1
// Get new copy of the claim // Get new copy of the claim
claim, err := client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(context.TODO(), pvc.Name, metav1.GetOptions{}) claim, err := client.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(context.TODO(), pvc.Name, metav1.GetOptions{})
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to get pvc: %w", err)
} }
// Get the bound PV // Get the bound PV
pv, err := client.CoreV1().PersistentVolumes().Get(context.TODO(), claim.Spec.VolumeName, metav1.GetOptions{}) pv, err := client.CoreV1().PersistentVolumes().Get(context.TODO(), claim.Spec.VolumeName, metav1.GetOptions{})
return pv, err if err != nil {
return nil, fmt.Errorf("failed to get pv: %w", err)
}
return pv, nil
} }
func checkPVSelectorValuesForPVC(f *framework.Framework, pvc *v1.PersistentVolumeClaim) error { func checkPVSelectorValuesForPVC(f *framework.Framework, pvc *v1.PersistentVolumeClaim) error {

View File

@ -157,12 +157,12 @@ func getImageInfoFromPVC(pvcNamespace, pvcName string, f *framework.Framework) (
c := f.ClientSet.CoreV1() c := f.ClientSet.CoreV1()
pvc, err := c.PersistentVolumeClaims(pvcNamespace).Get(context.TODO(), pvcName, metav1.GetOptions{}) pvc, err := c.PersistentVolumeClaims(pvcNamespace).Get(context.TODO(), pvcName, metav1.GetOptions{})
if err != nil { if err != nil {
return imageData, err return imageData, fmt.Errorf("failed to get pvc: %w", err)
} }
pv, err := c.PersistentVolumes().Get(context.TODO(), pvc.Spec.VolumeName, metav1.GetOptions{}) pv, err := c.PersistentVolumes().Get(context.TODO(), pvc.Spec.VolumeName, metav1.GetOptions{})
if err != nil { if err != nil {
return imageData, err return imageData, fmt.Errorf("failed to get pv: %w", err)
} }
imageIDRegex := regexp.MustCompile(`(\w+\-?){5}$`) imageIDRegex := regexp.MustCompile(`(\w+\-?){5}$`)

View File

@ -40,7 +40,7 @@ func expandPVCSize(c kubernetes.Interface, pvc *v1.PersistentVolumeClaim, size s
if isRetryableAPIError(err) { if isRetryableAPIError(err) {
return false, nil return false, nil
} }
return false, err return false, fmt.Errorf("failed to get pvc: %w", err)
} }
pvcConditions := updatedPVC.Status.Conditions pvcConditions := updatedPVC.Status.Conditions
if len(pvcConditions) > 0 { if len(pvcConditions) > 0 {
@ -92,7 +92,7 @@ func resizePVCAndValidateSize(pvcPath, appPath string, f *framework.Framework) e
pvc, err = f.ClientSet.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(context.TODO(), pvc.Name, metav1.GetOptions{}) pvc, err = f.ClientSet.CoreV1().PersistentVolumeClaims(pvc.Namespace).Get(context.TODO(), pvc.Name, metav1.GetOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to get pvc: %w", err)
} }
if *pvc.Spec.VolumeMode == v1.PersistentVolumeFilesystem { if *pvc.Spec.VolumeMode == v1.PersistentVolumeFilesystem {
err = checkDirSize(app, f, &opt, size) err = checkDirSize(app, f, &opt, size)

View File

@ -49,7 +49,7 @@ func createSnapshot(snap *snapapi.VolumeSnapshot, t int) error {
} }
_, err = sclient.SnapshotV1beta1().VolumeSnapshots(snap.Namespace).Create(context.TODO(), snap, metav1.CreateOptions{}) _, err = sclient.SnapshotV1beta1().VolumeSnapshots(snap.Namespace).Create(context.TODO(), snap, metav1.CreateOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to create volumesnapshot: %w", err)
} }
e2elog.Logf("snapshot with name %v created in %v namespace", snap.Name, snap.Namespace) e2elog.Logf("snapshot with name %v created in %v namespace", snap.Name, snap.Namespace)
@ -69,7 +69,7 @@ func createSnapshot(snap *snapapi.VolumeSnapshot, t int) error {
if apierrs.IsNotFound(err) { if apierrs.IsNotFound(err) {
return false, nil return false, nil
} }
return false, err return false, fmt.Errorf("failed to get volumesnapshot: %w", err)
} }
if snaps.Status == nil || snaps.Status.ReadyToUse == nil { if snaps.Status == nil || snaps.Status.ReadyToUse == nil {
return false, nil return false, nil
@ -89,7 +89,7 @@ func deleteSnapshot(snap *snapapi.VolumeSnapshot, t int) error {
} }
err = sclient.SnapshotV1beta1().VolumeSnapshots(snap.Namespace).Delete(context.TODO(), snap.Name, metav1.DeleteOptions{}) err = sclient.SnapshotV1beta1().VolumeSnapshots(snap.Namespace).Delete(context.TODO(), snap.Name, metav1.DeleteOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to delete volumesnapshot: %w", err)
} }
timeout := time.Duration(t) * time.Minute timeout := time.Duration(t) * time.Minute
@ -166,6 +166,9 @@ func createCephFSSnapshotClass(f *framework.Framework) error {
return err return err
} }
_, err = sclient.SnapshotV1beta1().VolumeSnapshotClasses().Create(context.TODO(), &sc, metav1.CreateOptions{}) _, err = sclient.SnapshotV1beta1().VolumeSnapshotClasses().Create(context.TODO(), &sc, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("failed to create volumesnapshotclass: %w", err)
}
return err return err
} }
@ -176,12 +179,12 @@ func getVolumeSnapshotContent(namespace, snapshotName string) (*snapapi.VolumeSn
} }
snapshot, err := sclient.SnapshotV1beta1().VolumeSnapshots(namespace).Get(context.TODO(), snapshotName, metav1.GetOptions{}) snapshot, err := sclient.SnapshotV1beta1().VolumeSnapshots(namespace).Get(context.TODO(), snapshotName, metav1.GetOptions{})
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to get volumesnapshot: %w", err)
} }
volumeSnapshotContent, err := sclient.SnapshotV1beta1().VolumeSnapshotContents().Get(context.TODO(), *snapshot.Status.BoundVolumeSnapshotContentName, metav1.GetOptions{}) volumeSnapshotContent, err := sclient.SnapshotV1beta1().VolumeSnapshotContents().Get(context.TODO(), *snapshot.Status.BoundVolumeSnapshotContentName, metav1.GetOptions{})
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to get volumesnapshotcontent: %w", err)
} }
return volumeSnapshotContent, nil return volumeSnapshotContent, nil
} }

View File

@ -152,12 +152,12 @@ func validateRBDStaticPV(f *framework.Framework, appPath string, isBlock bool) e
err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(context.TODO(), pvc.Name, metav1.DeleteOptions{}) err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(context.TODO(), pvc.Name, metav1.DeleteOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to delete pvc: %w", err)
} }
err = c.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{}) err = c.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to delete pv: %w", err)
} }
cmd = fmt.Sprintf("rbd rm %s %s", rbdImageName, rbdOptions(defaultRBDPool)) cmd = fmt.Sprintf("rbd rm %s %s", rbdImageName, rbdOptions(defaultRBDPool))
@ -208,7 +208,7 @@ func validateCephFsStaticPV(f *framework.Framework, appPath, scPath string) erro
return err return err
} }
if e != "" { if e != "" {
return fmt.Errorf("failed to create subvolumegroup %s", e) return fmt.Errorf("failed to create subvolumegroup: %s", e)
} }
// create subvolume // create subvolume
@ -218,7 +218,7 @@ func validateCephFsStaticPV(f *framework.Framework, appPath, scPath string) erro
return err return err
} }
if e != "" { if e != "" {
return fmt.Errorf("failed to create subvolume %s", e) return fmt.Errorf("failed to create subvolume: %s", e)
} }
// get rootpath // get rootpath
@ -251,7 +251,7 @@ func validateCephFsStaticPV(f *framework.Framework, appPath, scPath string) erro
secret.Namespace = cephCSINamespace secret.Namespace = cephCSINamespace
_, err = c.CoreV1().Secrets(cephCSINamespace).Create(context.TODO(), &secret, metav1.CreateOptions{}) _, err = c.CoreV1().Secrets(cephCSINamespace).Create(context.TODO(), &secret, metav1.CreateOptions{})
if err != nil { if err != nil {
return fmt.Errorf("failed to create secret, error %w", err) return fmt.Errorf("failed to create secret: %w", err)
} }
opt["clusterID"] = fsID opt["clusterID"] = fsID
@ -261,45 +261,45 @@ func validateCephFsStaticPV(f *framework.Framework, appPath, scPath string) erro
pv := getStaticPV(pvName, pvName, "4Gi", secretName, cephCSINamespace, sc, "cephfs.csi.ceph.com", false, opt) pv := getStaticPV(pvName, pvName, "4Gi", secretName, cephCSINamespace, sc, "cephfs.csi.ceph.com", false, opt)
_, err = c.CoreV1().PersistentVolumes().Create(context.TODO(), pv, metav1.CreateOptions{}) _, err = c.CoreV1().PersistentVolumes().Create(context.TODO(), pv, metav1.CreateOptions{})
if err != nil { if err != nil {
return fmt.Errorf("failed to create PV, error %w", err) return fmt.Errorf("failed to create PV: %w", err)
} }
pvc := getStaticPVC(pvcName, pvName, size, namespace, sc, false) pvc := getStaticPVC(pvcName, pvName, size, namespace, sc, false)
_, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{}) _, err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Create(context.TODO(), pvc, metav1.CreateOptions{})
if err != nil { if err != nil {
return fmt.Errorf("failed to create PVC, error %w", err) return fmt.Errorf("failed to create PVC: %w", err)
} }
// bind pvc to app // bind pvc to app
app, err := loadApp(appPath) app, err := loadApp(appPath)
if err != nil { if err != nil {
return fmt.Errorf("failed to load app, error %w", err) return fmt.Errorf("failed to load app: %w", err)
} }
app.Namespace = namespace app.Namespace = namespace
app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcName app.Spec.Volumes[0].PersistentVolumeClaim.ClaimName = pvcName
err = createApp(f.ClientSet, app, deployTimeout) err = createApp(f.ClientSet, app, deployTimeout)
if err != nil { if err != nil {
return fmt.Errorf("failed to create pod, error %w", err) return fmt.Errorf("failed to create pod: %w", err)
} }
err = deletePod(app.Name, namespace, f.ClientSet, deployTimeout) err = deletePod(app.Name, namespace, f.ClientSet, deployTimeout)
if err != nil { if err != nil {
return fmt.Errorf("failed to delete pod, error %w", err) return fmt.Errorf("failed to delete pod: %w", err)
} }
err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(context.TODO(), pvc.Name, metav1.DeleteOptions{}) err = c.CoreV1().PersistentVolumeClaims(pvc.Namespace).Delete(context.TODO(), pvc.Name, metav1.DeleteOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to delete pvc: %w", err)
} }
err = c.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{}) err = c.CoreV1().PersistentVolumes().Delete(context.TODO(), pv.Name, metav1.DeleteOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to delete pv: %w", err)
} }
err = c.CoreV1().Secrets(cephCSINamespace).Delete(context.TODO(), secret.Name, metav1.DeleteOptions{}) err = c.CoreV1().Secrets(cephCSINamespace).Delete(context.TODO(), secret.Name, metav1.DeleteOptions{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to delete secret: %w", err)
} }
// delete subvolume // delete subvolume

View File

@ -78,7 +78,7 @@ func getMons(ns string, c kubernetes.Interface) ([]string, error) {
svcList, err := c.CoreV1().Services(ns).List(context.TODO(), opt) svcList, err := c.CoreV1().Services(ns).List(context.TODO(), opt)
if err != nil { if err != nil {
return services, err return services, fmt.Errorf("failed to list services: %w", err)
} }
for i := range svcList.Items { for i := range svcList.Items {
s := fmt.Sprintf("%s.%s.svc.cluster.local:%d", svcList.Items[i].Name, svcList.Items[i].Namespace, svcList.Items[i].Spec.Ports[0].Port) s := fmt.Sprintf("%s.%s.svc.cluster.local:%d", svcList.Items[i].Name, svcList.Items[i].Namespace, svcList.Items[i].Spec.Ports[0].Port)

View File

@ -16,6 +16,8 @@ limitations under the License.
package controller package controller
import ( import (
"fmt"
"github.com/ceph/ceph-csi/internal/util" "github.com/ceph/ceph-csi/internal/util"
clientConfig "sigs.k8s.io/controller-runtime/pkg/client/config" clientConfig "sigs.k8s.io/controller-runtime/pkg/client/config"
@ -44,7 +46,7 @@ func addToManager(mgr manager.Manager, config Config) error {
for _, c := range ControllerList { for _, c := range ControllerList {
err := c.Add(mgr, config) err := c.Add(mgr, config)
if err != nil { if err != nil {
return err return fmt.Errorf("failed to add: %w", err)
} }
} }
return nil return nil

View File

@ -78,7 +78,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
// Watch for changes to PersistentVolumes // Watch for changes to PersistentVolumes
err = c.Watch(&source.Kind{Type: &corev1.PersistentVolume{}}, &handler.EnqueueRequestForObject{}) err = c.Watch(&source.Kind{Type: &corev1.PersistentVolume{}}, &handler.EnqueueRequestForObject{})
if err != nil { if err != nil {
return err return fmt.Errorf("failed to watch the changes: %w", err)
} }
return nil return nil
} }

View File

@ -243,7 +243,7 @@ func (cj *Config) Connect(monitors, namespace string, cr *util.Credentials) (*Co
cj.namespace = namespace cj.namespace = namespace
cc := &util.ClusterConnection{} cc := &util.ClusterConnection{}
if err := cc.Connect(monitors, cr); err != nil { if err := cc.Connect(monitors, cr); err != nil {
return nil, err return nil, fmt.Errorf("failed to establish the connection: %w", err)
} }
conn := &Connection{ conn := &Connection{
config: cj, config: cj,
@ -321,7 +321,7 @@ func (conn *Connection) CheckReservation(ctx context.Context,
buf64, err = hex.DecodeString(savedImagePoolIDStr) buf64, err = hex.DecodeString(savedImagePoolIDStr)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to decode string: %w", err)
} }
savedImagePoolID = int64(binary.BigEndian.Uint64(buf64)) savedImagePoolID = int64(binary.BigEndian.Uint64(buf64))
@ -470,7 +470,7 @@ func reserveOMapName(ctx context.Context, monitors string, cr *util.Credentials,
continue continue
} }
return "", err return "", fmt.Errorf("failed to create omap object for oMapNamePrefix+iterUUID=%s: %w", oMapNamePrefix+iterUUID, err)
} }
return iterUUID, nil return iterUUID, nil
@ -674,7 +674,7 @@ func (conn *Connection) GetImageAttributes(ctx context.Context, pool, objectUUID
var buf64 []byte var buf64 []byte
buf64, err = hex.DecodeString(journalPoolIDStr) buf64, err = hex.DecodeString(journalPoolIDStr)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("failed to decode string: %w", err)
} }
imageAttributes.JournalPoolID = int64(binary.BigEndian.Uint64(buf64)) imageAttributes.JournalPoolID = int64(binary.BigEndian.Uint64(buf64))
} }