Skip to content

Commit

Permalink
clean up various logging/error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Kriss <steve@heptio.com>
  • Loading branch information
skriss committed Oct 10, 2017
1 parent feef34b commit dff665c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (ib *realItemBackupper) backupItem(ctx *backupContext, item map[string]inte
}

if !ctx.resourceIncludesExcludes.ShouldInclude(groupResource.String()) {
ctx.infof("Excluding item %s because resource %s is excluded", name, groupResource)
ctx.infof("Excluding item %s because resource %s is excluded", name, groupResource.String())
return nil
}

Expand All @@ -420,14 +420,14 @@ func (ib *realItemBackupper) backupItem(ctx *backupContext, item map[string]inte
delete(item, "status")

if action, hasAction := ctx.actions[groupResource]; hasAction {
ctx.infof("Executing action on %s, ns=%s, name=%s", groupResource, namespace, name)
ctx.infof("Executing action on %s, ns=%s, name=%s", groupResource.String(), namespace, name)

if err := action.Execute(ctx, item, ib); err != nil {
return err
}
}

ctx.infof("Backing up resource=%s, ns=%s, name=%s", groupResource, namespace, name)
ctx.infof("Backing up resource=%s, ns=%s, name=%s", groupResource.String(), namespace, name)

var filePath string
if namespace != "" {
Expand Down
30 changes: 17 additions & 13 deletions pkg/backup/backup_pv_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package backup

import (
"github.com/pkg/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

Expand All @@ -37,39 +39,41 @@ func NewBackupPVAction() Action {
// Execute finds the PersistentVolume referenced by the provided
// PersistentVolumeClaim and backs it up
func (a *backupPVAction) Execute(ctx *backupContext, pvc map[string]interface{}, backupper itemBackupper) error {
ctx.infof("running GetPVAction")
pvcName, err := collections.GetString(pvc, "metadata.name")
if err != nil {
ctx.infof("unable to get metadata.name for PersistentVolumeClaim: %v", err)
return err
}

volumeName, err := collections.GetString(pvc, "spec.volumeName")
if err != nil {
ctx.infof("unable to get spec.volumeName for PersistentVolumeClaim %s: %v", pvcName, err)
return err
}

// resolve the GVR (need to use kb.discoveryHelper)
ctx.infof("getting GVR for PersistentVolume %s\n", volumeName)
gvr, resource, err := ctx.discoveryHelper.ResourceFor(schema.GroupVersionResource{Resource: "persistentvolumes"})
if err != nil {
ctx.infof("error getting GVR: %s\n", err)
ctx.infof("error getting GroupVersionResource for PersistentVolumes: %v", err)
return err
}
gr := gvr.GroupResource()

// get a dynamic client
ctx.infof("getting client for GVR & Resource %s & %s\n", gvr.String(), resource.String())
client, err := ctx.dynamicFactory.ClientForGroupVersionResource(gvr, resource, "")
if err != nil {
ctx.infof("error getting client: %s\n", err)
ctx.infof("error getting client for GroupVersionResource=%s, Resource=%s: %v", gvr.String(), resource, err)
return err
}

// get the item
ctx.infof("getting PV %s\n", volumeName)
pv, err := client.Get(volumeName, metav1.GetOptions{})
if err != nil {
ctx.infof("error getting PV: %s\n", err)
ctx.infof("error getting PersistentVolume %s: %v", volumeName, err)
return errors.WithStack(err)
}

// back it up
ctx.infof("backing up PV %s\n", volumeName)
ctx.infof("backing up PersistentVolume %s for PersistentVolumeClaim %s", volumeName, pvcName)
if err := backupper.backupItem(ctx, pv.UnstructuredContent(), gr); err != nil {
ctx.infof("error backing up PV: %s\n", err)
ctx.infof("error backing up PersistentVolume %s: %v", volumeName, err)
return err
}

return nil
Expand Down
5 changes: 1 addition & 4 deletions pkg/backup/volume_snapshot_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ func (a *volumeSnapshotAction) Execute(ctx *backupContext, volume map[string]int
return nil
}

expiration := a.clock.Now().Add(backup.Spec.TTL.Duration)

ctx.infof("Backup %q: snapshotting PersistentVolume %q, volume-id %q, expiration %v", backupName, name, volumeID, expiration)

ctx.infof("Backup %q: snapshotting PersistentVolume %q, volume-id %q", backupName, name, volumeID)
snapshotID, err := a.snapshotService.CreateSnapshot(volumeID, pvFailureDomainZone)
if err != nil {
ctx.infof("error creating snapshot for backup %q, volume %q, volume-id %q: %v", backupName, name, volumeID, err)
Expand Down
3 changes: 1 addition & 2 deletions pkg/discovery/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package discovery

import (
"fmt"
"sort"
"sync"

Expand Down Expand Up @@ -83,7 +82,7 @@ func (h *helper) ResourceFor(input schema.GroupVersionResource) (schema.GroupVer

apiResource, found := h.resourcesMap[gvr]
if !found {
return schema.GroupVersionResource{}, metav1.APIResource{}, fmt.Errorf("APIResource not found for GroupVersionResource %s", gvr)
return schema.GroupVersionResource{}, metav1.APIResource{}, errors.Errorf("APIResource not found for GroupVersionResource %s", gvr)
}

return gvr, apiResource, nil
Expand Down

0 comments on commit dff665c

Please sign in to comment.