Skip to content

Commit cde4f13

Browse files
Dipta Dastamalsaha
authored andcommitted
Remove restic-dependency from recovery (#258)
* Update cli.SetupEnv() * Update recovery api * Update recovery job * Fix tests * Update recovery volumes * Rename RecoveryVoume -> RecoveredVolume, removed Name field * Make VolumeSource inline
1 parent 6e59985 commit cde4f13

20 files changed

Lines changed: 194 additions & 95 deletions

apis/stash/types.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,12 @@ type Recovery struct {
155155
}
156156

157157
type RecoverySpec struct {
158-
Restic string `json:"restic,omitempty"`
159-
Workload LocalTypedReference `json:"workload,omitempty"`
160-
PodOrdinal string `json:"podOrdinal,omitempty"`
161-
NodeName string `json:"nodeName,omitempty"`
162-
Volumes []core.Volume `json:"volumes,omitempty"`
158+
Backend Backend `json:"backend,omitempty"`
159+
Paths []string `json:"paths,omitempty"`
160+
Workload LocalTypedReference `json:"workload,omitempty"`
161+
PodOrdinal string `json:"podOrdinal,omitempty"`
162+
NodeName string `json:"nodeName,omitempty"`
163+
RecoveredVolumes []RecoveredVolume `json:"recoveredVolumes,omitempty"`
163164
}
164165

165166
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -170,6 +171,12 @@ type RecoveryList struct {
170171
Items []Recovery `json:"items,omitempty"`
171172
}
172173

174+
type RecoveredVolume struct {
175+
VolumeSource core.VolumeSource `json:",inline"`
176+
MountPath string `json:"mountPath,omitempty"`
177+
SubPath string `json:"subPath,omitempty"`
178+
}
179+
173180
// LocalTypedReference contains enough information to let you inspect or modify the referred object.
174181
type LocalTypedReference struct {
175182
// Kind of the referent.

apis/stash/v1alpha1/types.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,12 @@ type Recovery struct {
155155
}
156156

157157
type RecoverySpec struct {
158-
Restic string `json:"restic,omitempty"`
159-
Workload LocalTypedReference `json:"workload,omitempty"`
160-
PodOrdinal string `json:"podOrdinal,omitempty"`
161-
NodeName string `json:"nodeName,omitempty"`
162-
Volumes []core.Volume `json:"volumes,omitempty"`
158+
Backend Backend `json:"backend,omitempty"`
159+
Paths []string `json:"paths,omitempty"`
160+
Workload LocalTypedReference `json:"workload,omitempty"`
161+
PodOrdinal string `json:"podOrdinal,omitempty"`
162+
NodeName string `json:"nodeName,omitempty"`
163+
RecoveredVolumes []RecoveredVolume `json:"recoveredVolumes,omitempty"`
163164
}
164165

165166
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -170,6 +171,12 @@ type RecoveryList struct {
170171
Items []Recovery `json:"items,omitempty"`
171172
}
172173

174+
type RecoveredVolume struct {
175+
VolumeSource core.VolumeSource `json:",inline"`
176+
MountPath string `json:"mountPath,omitempty"`
177+
SubPath string `json:"subPath,omitempty"`
178+
}
179+
173180
// LocalTypedReference contains enough information to let you inspect or modify the referred object.
174181
type LocalTypedReference struct {
175182
// Kind of the referent.

apis/stash/v1alpha1/validator.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ func (r Restic) IsValid() error {
3535
}
3636

3737
func (r Recovery) IsValid() error {
38-
if r.Spec.Restic == "" {
39-
return fmt.Errorf("missing restic name")
38+
if r.Spec.Backend.StorageSecretName == "" {
39+
return fmt.Errorf("missing repository secret name")
40+
}
41+
if len(r.Spec.Paths) == 0 {
42+
return fmt.Errorf("missing filegroup paths")
4043
}
41-
if len(r.Spec.Volumes) == 0 {
42-
return fmt.Errorf("missing target vollume")
44+
if len(r.Spec.RecoveredVolumes) == 0 {
45+
return fmt.Errorf("missing recovery vollume")
4346
}
4447

4548
if err := r.Spec.Workload.Canonicalize(); err != nil {

apis/stash/v1alpha1/zz_generated.conversion.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ func RegisterConversions(scheme *runtime.Scheme) error {
5252
Convert_stash_LocalSpec_To_v1alpha1_LocalSpec,
5353
Convert_v1alpha1_LocalTypedReference_To_stash_LocalTypedReference,
5454
Convert_stash_LocalTypedReference_To_v1alpha1_LocalTypedReference,
55+
Convert_v1alpha1_RecoveredVolume_To_stash_RecoveredVolume,
56+
Convert_stash_RecoveredVolume_To_v1alpha1_RecoveredVolume,
5557
Convert_v1alpha1_Recovery_To_stash_Recovery,
5658
Convert_stash_Recovery_To_v1alpha1_Recovery,
5759
Convert_v1alpha1_RecoveryList_To_stash_RecoveryList,
@@ -247,6 +249,30 @@ func Convert_stash_LocalTypedReference_To_v1alpha1_LocalTypedReference(in *stash
247249
return autoConvert_stash_LocalTypedReference_To_v1alpha1_LocalTypedReference(in, out, s)
248250
}
249251

252+
func autoConvert_v1alpha1_RecoveredVolume_To_stash_RecoveredVolume(in *RecoveredVolume, out *stash.RecoveredVolume, s conversion.Scope) error {
253+
out.VolumeSource = in.VolumeSource
254+
out.MountPath = in.MountPath
255+
out.SubPath = in.SubPath
256+
return nil
257+
}
258+
259+
// Convert_v1alpha1_RecoveredVolume_To_stash_RecoveredVolume is an autogenerated conversion function.
260+
func Convert_v1alpha1_RecoveredVolume_To_stash_RecoveredVolume(in *RecoveredVolume, out *stash.RecoveredVolume, s conversion.Scope) error {
261+
return autoConvert_v1alpha1_RecoveredVolume_To_stash_RecoveredVolume(in, out, s)
262+
}
263+
264+
func autoConvert_stash_RecoveredVolume_To_v1alpha1_RecoveredVolume(in *stash.RecoveredVolume, out *RecoveredVolume, s conversion.Scope) error {
265+
out.VolumeSource = in.VolumeSource
266+
out.MountPath = in.MountPath
267+
out.SubPath = in.SubPath
268+
return nil
269+
}
270+
271+
// Convert_stash_RecoveredVolume_To_v1alpha1_RecoveredVolume is an autogenerated conversion function.
272+
func Convert_stash_RecoveredVolume_To_v1alpha1_RecoveredVolume(in *stash.RecoveredVolume, out *RecoveredVolume, s conversion.Scope) error {
273+
return autoConvert_stash_RecoveredVolume_To_v1alpha1_RecoveredVolume(in, out, s)
274+
}
275+
250276
func autoConvert_v1alpha1_Recovery_To_stash_Recovery(in *Recovery, out *stash.Recovery, s conversion.Scope) error {
251277
out.ObjectMeta = in.ObjectMeta
252278
if err := Convert_v1alpha1_RecoverySpec_To_stash_RecoverySpec(&in.Spec, &out.Spec, s); err != nil {
@@ -302,13 +328,16 @@ func Convert_stash_RecoveryList_To_v1alpha1_RecoveryList(in *stash.RecoveryList,
302328
}
303329

304330
func autoConvert_v1alpha1_RecoverySpec_To_stash_RecoverySpec(in *RecoverySpec, out *stash.RecoverySpec, s conversion.Scope) error {
305-
out.Restic = in.Restic
331+
if err := Convert_v1alpha1_Backend_To_stash_Backend(&in.Backend, &out.Backend, s); err != nil {
332+
return err
333+
}
334+
out.Paths = *(*[]string)(unsafe.Pointer(&in.Paths))
306335
if err := Convert_v1alpha1_LocalTypedReference_To_stash_LocalTypedReference(&in.Workload, &out.Workload, s); err != nil {
307336
return err
308337
}
309338
out.PodOrdinal = in.PodOrdinal
310339
out.NodeName = in.NodeName
311-
out.Volumes = *(*[]v1.Volume)(unsafe.Pointer(&in.Volumes))
340+
out.RecoveredVolumes = *(*[]stash.RecoveredVolume)(unsafe.Pointer(&in.RecoveredVolumes))
312341
return nil
313342
}
314343

@@ -318,13 +347,16 @@ func Convert_v1alpha1_RecoverySpec_To_stash_RecoverySpec(in *RecoverySpec, out *
318347
}
319348

320349
func autoConvert_stash_RecoverySpec_To_v1alpha1_RecoverySpec(in *stash.RecoverySpec, out *RecoverySpec, s conversion.Scope) error {
321-
out.Restic = in.Restic
350+
if err := Convert_stash_Backend_To_v1alpha1_Backend(&in.Backend, &out.Backend, s); err != nil {
351+
return err
352+
}
353+
out.Paths = *(*[]string)(unsafe.Pointer(&in.Paths))
322354
if err := Convert_stash_LocalTypedReference_To_v1alpha1_LocalTypedReference(&in.Workload, &out.Workload, s); err != nil {
323355
return err
324356
}
325357
out.PodOrdinal = in.PodOrdinal
326358
out.NodeName = in.NodeName
327-
out.Volumes = *(*[]v1.Volume)(unsafe.Pointer(&in.Volumes))
359+
out.RecoveredVolumes = *(*[]RecoveredVolume)(unsafe.Pointer(&in.RecoveredVolumes))
328360
return nil
329361
}
330362

apis/stash/v1alpha1/zz_generated.deepcopy.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func RegisterDeepCopies(scheme *runtime.Scheme) error {
6767
in.(*LocalTypedReference).DeepCopyInto(out.(*LocalTypedReference))
6868
return nil
6969
}, InType: reflect.TypeOf(&LocalTypedReference{})},
70+
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
71+
in.(*RecoveredVolume).DeepCopyInto(out.(*RecoveredVolume))
72+
return nil
73+
}, InType: reflect.TypeOf(&RecoveredVolume{})},
7074
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
7175
in.(*Recovery).DeepCopyInto(out.(*Recovery))
7276
return nil
@@ -285,6 +289,23 @@ func (in *LocalTypedReference) DeepCopy() *LocalTypedReference {
285289
return out
286290
}
287291

292+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
293+
func (in *RecoveredVolume) DeepCopyInto(out *RecoveredVolume) {
294+
*out = *in
295+
in.VolumeSource.DeepCopyInto(&out.VolumeSource)
296+
return
297+
}
298+
299+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RecoveredVolume.
300+
func (in *RecoveredVolume) DeepCopy() *RecoveredVolume {
301+
if in == nil {
302+
return nil
303+
}
304+
out := new(RecoveredVolume)
305+
in.DeepCopyInto(out)
306+
return out
307+
}
308+
288309
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
289310
func (in *Recovery) DeepCopyInto(out *Recovery) {
290311
*out = *in
@@ -351,10 +372,16 @@ func (in *RecoveryList) DeepCopyObject() runtime.Object {
351372
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
352373
func (in *RecoverySpec) DeepCopyInto(out *RecoverySpec) {
353374
*out = *in
375+
in.Backend.DeepCopyInto(&out.Backend)
376+
if in.Paths != nil {
377+
in, out := &in.Paths, &out.Paths
378+
*out = make([]string, len(*in))
379+
copy(*out, *in)
380+
}
354381
out.Workload = in.Workload
355-
if in.Volumes != nil {
356-
in, out := &in.Volumes, &out.Volumes
357-
*out = make([]v1.Volume, len(*in))
382+
if in.RecoveredVolumes != nil {
383+
in, out := &in.RecoveredVolumes, &out.RecoveredVolumes
384+
*out = make([]RecoveredVolume, len(*in))
358385
for i := range *in {
359386
(*in)[i].DeepCopyInto(&(*out)[i])
360387
}

apis/stash/zz_generated.deepcopy.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func RegisterDeepCopies(scheme *runtime.Scheme) error {
6767
in.(*LocalTypedReference).DeepCopyInto(out.(*LocalTypedReference))
6868
return nil
6969
}, InType: reflect.TypeOf(&LocalTypedReference{})},
70+
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
71+
in.(*RecoveredVolume).DeepCopyInto(out.(*RecoveredVolume))
72+
return nil
73+
}, InType: reflect.TypeOf(&RecoveredVolume{})},
7074
conversion.GeneratedDeepCopyFunc{Fn: func(in interface{}, out interface{}, c *conversion.Cloner) error {
7175
in.(*Recovery).DeepCopyInto(out.(*Recovery))
7276
return nil
@@ -285,6 +289,23 @@ func (in *LocalTypedReference) DeepCopy() *LocalTypedReference {
285289
return out
286290
}
287291

292+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
293+
func (in *RecoveredVolume) DeepCopyInto(out *RecoveredVolume) {
294+
*out = *in
295+
in.VolumeSource.DeepCopyInto(&out.VolumeSource)
296+
return
297+
}
298+
299+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RecoveredVolume.
300+
func (in *RecoveredVolume) DeepCopy() *RecoveredVolume {
301+
if in == nil {
302+
return nil
303+
}
304+
out := new(RecoveredVolume)
305+
in.DeepCopyInto(out)
306+
return out
307+
}
308+
288309
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
289310
func (in *Recovery) DeepCopyInto(out *Recovery) {
290311
*out = *in
@@ -351,10 +372,16 @@ func (in *RecoveryList) DeepCopyObject() runtime.Object {
351372
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
352373
func (in *RecoverySpec) DeepCopyInto(out *RecoverySpec) {
353374
*out = *in
375+
in.Backend.DeepCopyInto(&out.Backend)
376+
if in.Paths != nil {
377+
in, out := &in.Paths, &out.Paths
378+
*out = make([]string, len(*in))
379+
copy(*out, *in)
380+
}
354381
out.Workload = in.Workload
355-
if in.Volumes != nil {
356-
in, out := &in.Volumes, &out.Volumes
357-
*out = make([]v1.Volume, len(*in))
382+
if in.RecoveredVolumes != nil {
383+
in, out := &in.RecoveredVolumes, &out.RecoveredVolumes
384+
*out = make([]RecoveredVolume, len(*in))
358385
for i := range *in {
359386
(*in)[i].DeepCopyInto(&(*out)[i])
360387
}

pkg/backup/backup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (c *Controller) setup() (*api.Restic, error) {
158158
log.Infof("Found repository secret %s\n", secret.Name)
159159

160160
// setup restic-cli
161-
if err = c.resticCLI.SetupEnv(resource, secret, c.opt.SmartPrefix); err != nil {
161+
if err = c.resticCLI.SetupEnv(resource.Spec.Backend, secret, c.opt.SmartPrefix); err != nil {
162162
return nil, err
163163
}
164164
if err = c.resticCLI.InitRepositoryIfAbsent(); err != nil {

pkg/backup/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func (c *Controller) runOnceForScheduler() error {
153153
}
154154

155155
// setup restic again, previously done in setup()
156-
if err = c.resticCLI.SetupEnv(resource, secret, c.opt.SmartPrefix); err != nil {
156+
if err = c.resticCLI.SetupEnv(resource.Spec.Backend, secret, c.opt.SmartPrefix); err != nil {
157157
return err
158158
}
159159
if err = c.resticCLI.InitRepositoryIfAbsent(); err != nil {

pkg/check/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (c *Controller) Run() (err error) {
7474
}
7575

7676
cli := cli.New("/tmp", false, c.opt.HostName)
77-
if err = cli.SetupEnv(restic, secret, c.opt.SmartPrefix); err != nil {
77+
if err = cli.SetupEnv(restic.Spec.Backend, secret, c.opt.SmartPrefix); err != nil {
7878
return
7979
}
8080

pkg/cli/env.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ const (
5454
OS_AUTH_TOKEN = "OS_AUTH_TOKEN"
5555
)
5656

57-
func (w *ResticWrapper) SetupEnv(resource *api.Restic, secret *core.Secret, autoPrefix string) error {
57+
func (w *ResticWrapper) SetupEnv(backend api.Backend, secret *core.Secret, autoPrefix string) error {
5858
if v, ok := secret.Data[RESTIC_PASSWORD]; !ok {
59-
return errors.New("Missing repository password")
59+
return errors.New("missing repository password")
6060
} else {
6161
w.sh.SetEnv(RESTIC_PASSWORD, string(v))
6262
}
@@ -67,7 +67,6 @@ func (w *ResticWrapper) SetupEnv(resource *api.Restic, secret *core.Secret, auto
6767
}
6868
w.sh.SetEnv(TMPDIR, tmpDir)
6969

70-
backend := resource.Spec.Backend
7170
if backend.Local != nil {
7271
r := filepath.Join(backend.Local.Path, autoPrefix)
7372
if err := os.MkdirAll(r, 0755); err != nil {

0 commit comments

Comments
 (0)