Skip to content

Commit

Permalink
Check for snapshot existence before delete (#548)
Browse files Browse the repository at this point in the history
This PR fixes #549
Task list:
- [x] Check if snapshot exist before delete
- [x] Used `k8s.io/apimachinery/pkg/api/errors`
  • Loading branch information
Md. Emruz Hossain authored and tamalsaha committed Aug 15, 2018
1 parent a06e72b commit 1c7af39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions client/clientset/versioned/typed/stash/v1alpha1/util/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func TryUpdateRecovery(c cs.StashV1alpha1Interface, meta metav1.ObjectMeta, tran
}

func SetRecoveryStats(c cs.StashV1alpha1Interface, recovery *api.Recovery, path string, d time.Duration, phase api.RecoveryPhase) (*api.Recovery, error) {
out, _, err := PatchRecovery(c, recovery, func(in *api.Recovery) *api.Recovery {
out, err := UpdateRecoveryStatus(c, recovery, func(in *api.RecoveryStatus) *api.RecoveryStatus {
found := false
for _, stats := range in.Status.Stats {
for _, stats := range in.Stats {
if stats.Path == path {
found = true
stats.Duration = d.String()
Expand All @@ -100,7 +100,7 @@ func SetRecoveryStats(c cs.StashV1alpha1Interface, recovery *api.Recovery, path
})
}
return in
})
}, api.EnableStatusSubresource)
return out, err
}

Expand All @@ -114,16 +114,12 @@ func UpdateRecoveryStatus(
return nil, errors.Errorf("invalid value passed for useSubresource: %v", useSubresource)
}

apply := func(x *api.Recovery, copy bool) *api.Recovery {
apply := func(x *api.Recovery) *api.Recovery {
out := &api.Recovery{
TypeMeta: x.TypeMeta,
ObjectMeta: x.ObjectMeta,
Spec: x.Spec,
}
if copy {
out.Status = *transform(in.Status.DeepCopy())
} else {
out.Status = *transform(&in.Status)
Status: *transform(in.Status.DeepCopy()),
}
return out
}
Expand All @@ -134,7 +130,7 @@ func UpdateRecoveryStatus(
err = wait.PollImmediate(kutil.RetryInterval, kutil.RetryTimeout, func() (bool, error) {
attempt++
var e2 error
result, e2 = c.Recoveries(in.Namespace).UpdateStatus(apply(cur, false))
result, e2 = c.Recoveries(in.Namespace).UpdateStatus(apply(cur))
if kerr.IsConflict(e2) {
latest, e3 := c.Recoveries(in.Namespace).Get(in.Name, metav1.GetOptions{})
switch {
Expand All @@ -158,6 +154,6 @@ func UpdateRecoveryStatus(
return
}

result, _, err = PatchRecoveryObject(c, in, apply(in, true))
result, _, err = PatchRecoveryObject(c, in, apply(in))
return
}
2 changes: 1 addition & 1 deletion hack/docker/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ source "$REPO_ROOT/hack/libbuild/common/public_image.sh"

APPSCODE_ENV=${APPSCODE_ENV:-dev}
IMG=stash
RESTIC_VER=${RESTIC_VER:-0.9.1}
RESTIC_VER=${RESTIC_VER:-0.8.3}
RESTIC_BRANCH=${RESTIC_BRANCH:-stash-0.4.2}

DIST=$REPO_ROOT/dist
Expand Down

0 comments on commit 1c7af39

Please sign in to comment.