Merge pull request #900 from skriss/restic-restore-ns-mapping
bug: fix restic restores when using namespace mappingspull/905/head
commit
1d90d02a99
|
@ -34,7 +34,7 @@ import (
|
||||||
// Restorer can execute restic restores of volumes in a pod.
|
// Restorer can execute restic restores of volumes in a pod.
|
||||||
type Restorer interface {
|
type Restorer interface {
|
||||||
// RestorePodVolumes restores all annotated volumes in a pod.
|
// RestorePodVolumes restores all annotated volumes in a pod.
|
||||||
RestorePodVolumes(restore *arkv1api.Restore, pod *corev1api.Pod, log logrus.FieldLogger) []error
|
RestorePodVolumes(restore *arkv1api.Restore, pod *corev1api.Pod, sourceNamespace string, log logrus.FieldLogger) []error
|
||||||
}
|
}
|
||||||
|
|
||||||
type restorer struct {
|
type restorer struct {
|
||||||
|
@ -84,14 +84,14 @@ func newRestorer(
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *restorer) RestorePodVolumes(restore *arkv1api.Restore, pod *corev1api.Pod, log logrus.FieldLogger) []error {
|
func (r *restorer) RestorePodVolumes(restore *arkv1api.Restore, pod *corev1api.Pod, sourceNamespace string, log logrus.FieldLogger) []error {
|
||||||
// get volumes to restore from pod's annotations
|
// get volumes to restore from pod's annotations
|
||||||
volumesToRestore := GetPodSnapshotAnnotations(pod)
|
volumesToRestore := GetPodSnapshotAnnotations(pod)
|
||||||
if len(volumesToRestore) == 0 {
|
if len(volumesToRestore) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := r.repoEnsurer.EnsureRepo(r.ctx, restore.Namespace, pod.Namespace)
|
repo, err := r.repoEnsurer.EnsureRepo(r.ctx, restore.Namespace, sourceNamespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []error{err}
|
return []error{err}
|
||||||
}
|
}
|
||||||
|
|
|
@ -743,6 +743,7 @@ func (ctx *context) restoreResource(resource, namespace, resourcePath string) (a
|
||||||
|
|
||||||
// necessary because we may have remapped the namespace
|
// necessary because we may have remapped the namespace
|
||||||
// if the namespace is blank, don't create the key
|
// if the namespace is blank, don't create the key
|
||||||
|
originalNamespace := obj.GetNamespace()
|
||||||
if namespace != "" {
|
if namespace != "" {
|
||||||
obj.SetNamespace(namespace)
|
obj.SetNamespace(namespace)
|
||||||
}
|
}
|
||||||
|
@ -827,7 +828,7 @@ func (ctx *context) restoreResource(resource, namespace, resourcePath string) (a
|
||||||
return []error{err}
|
return []error{err}
|
||||||
}
|
}
|
||||||
|
|
||||||
if errs := ctx.resticRestorer.RestorePodVolumes(ctx.restore, pod, ctx.log); errs != nil {
|
if errs := ctx.resticRestorer.RestorePodVolumes(ctx.restore, pod, originalNamespace, ctx.log); errs != nil {
|
||||||
ctx.log.WithError(kubeerrs.NewAggregate(errs)).Error("unable to successfully complete restic restores of pod's volumes")
|
ctx.log.WithError(kubeerrs.NewAggregate(errs)).Error("unable to successfully complete restic restores of pod's volumes")
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue