Skip to content

Commit 4f9c5fa

Browse files
authored
[Feature] Restore as Plan (#560)
1 parent 9af8c8d commit 4f9c5fa

File tree

15 files changed

+298
-142
lines changed

15 files changed

+298
-142
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
4-
- Prevent deletion not known PVC's
4+
- Prevent deletion of not known PVC's
5+
- Move Restore as Plan
56

67
## [1.0.2](https://github.com/arangodb/kube-arangodb/tree/1.0.2) (2020-04-16)
78
- Added additional checks in UpToDate condition

pkg/apis/deployment/v1/plan.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ const (
7575
ActionTypePVCResized ActionType = "PVCResized"
7676
// UpToDateUpdateResized define up to date annotation in spec
7777
UpToDateUpdate ActionType = "UpToDateUpdate"
78+
// ActionTypeBackupRestore restore plan
79+
ActionTypeBackupRestore ActionType = "BackupRestore"
80+
// ActionTypeBackupRestoreClean restore plan
81+
ActionTypeBackupRestoreClean ActionType = "BackupRestoreClean"
7882
)
7983

8084
const (

pkg/deployment/backup/handler.go

Lines changed: 0 additions & 134 deletions
This file was deleted.

pkg/deployment/deployment.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import (
3939
"k8s.io/client-go/tools/record"
4040

4141
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
42-
"github.com/arangodb/kube-arangodb/pkg/deployment/backup"
4342
"github.com/arangodb/kube-arangodb/pkg/deployment/chaos"
4443
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile"
4544
"github.com/arangodb/kube-arangodb/pkg/deployment/resilience"
@@ -112,7 +111,6 @@ type Deployment struct {
112111
reconciler *reconcile.Reconciler
113112
resilience *resilience.Resilience
114113
resources *resources.Resources
115-
backup *backup.BackupHandler
116114
chaosMonkey *chaos.Monkey
117115
syncClientCache client.ClientCache
118116
haveServiceMonitorCRD bool
@@ -135,7 +133,6 @@ func New(config Config, deps Dependencies, apiObject *api.ArangoDeployment) (*De
135133
d.reconciler = reconcile.NewReconciler(deps.Log, d)
136134
d.resilience = resilience.NewResilience(deps.Log, d)
137135
d.resources = resources.NewResources(deps.Log, d)
138-
d.backup = backup.NewHandler(deps.Log, d)
139136
if d.status.last.AcceptedSpec == nil {
140137
// We've validated the spec, so let's use it from now.
141138
d.status.last.AcceptedSpec = apiObject.Spec.DeepCopy()

pkg/deployment/deployment_inspector.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,6 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
236236
return minInspectionInterval, errors.Wrapf(err, "Removed member cleanup failed")
237237
}
238238

239-
if err := d.backup.CheckRestore(); err != nil {
240-
return minInspectionInterval, errors.Wrapf(err, "Restore operation failed")
241-
}
242-
243239
// At the end of the inspect, we cleanup terminated pods.
244240
if x, err := d.resources.CleanupTerminatedPods(); err != nil {
245241
return minInspectionInterval, errors.Wrapf(err, "Pod cleanup failed")
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Adam Janikowski
21+
//
22+
23+
package reconcile
24+
25+
import (
26+
"context"
27+
28+
"github.com/arangodb/go-driver"
29+
30+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
31+
"github.com/rs/zerolog"
32+
)
33+
34+
func init() {
35+
registerAction(api.ActionTypeBackupRestore, newBackupRestoreAction)
36+
}
37+
38+
func newBackupRestoreAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
39+
a := &actionBackupRestore{}
40+
41+
a.actionImpl = newActionImplDefRef(log, action, actionCtx, backupRestoreTimeout)
42+
43+
return a
44+
}
45+
46+
// actionBackupRestore implements an BackupRestore.
47+
type actionBackupRestore struct {
48+
// actionImpl implement timeout and member id functions
49+
actionImpl
50+
51+
actionEmptyCheckProgress
52+
}
53+
54+
func (a actionBackupRestore) Start(ctx context.Context) (bool, error) {
55+
spec := a.actionCtx.GetSpec()
56+
status := a.actionCtx.GetStatus()
57+
58+
if spec.RestoreFrom == nil {
59+
return true, nil
60+
}
61+
62+
if status.Restore != nil {
63+
a.log.Warn().Msg("Backup restore status should not be nil")
64+
return true, nil
65+
}
66+
67+
dbc, err := a.actionCtx.GetDatabaseClient(ctx)
68+
if err != nil {
69+
return false, err
70+
}
71+
72+
backupResource, err := a.actionCtx.GetBackup(*spec.RestoreFrom)
73+
if err != nil {
74+
a.log.Error().Err(err).Msg("Unable to find backup")
75+
return true, nil
76+
}
77+
78+
if backupResource.Status.Backup == nil {
79+
a.log.Error().Msg("Backup ID is not set")
80+
return true, nil
81+
}
82+
83+
if err := a.actionCtx.WithStatusUpdate(func(s *api.DeploymentStatus) bool {
84+
result := &api.DeploymentRestoreResult{
85+
RequestedFrom: spec.GetRestoreFrom(),
86+
}
87+
88+
result.State = api.DeploymentRestoreStateRestoring
89+
90+
s.Restore = result
91+
92+
return true
93+
}, true); err != nil {
94+
return false, err
95+
}
96+
97+
restoreError := dbc.Backup().Restore(ctx, driver.BackupID(backupResource.Status.Backup.ID), nil)
98+
if restoreError != nil {
99+
a.log.Error().Err(restoreError).Msg("Restore failed")
100+
}
101+
102+
if err := a.actionCtx.WithStatusUpdate(func(s *api.DeploymentStatus) bool {
103+
result := &api.DeploymentRestoreResult{
104+
RequestedFrom: spec.GetRestoreFrom(),
105+
}
106+
107+
if restoreError != nil {
108+
result.State = api.DeploymentRestoreStateRestoreFailed
109+
result.Message = restoreError.Error()
110+
} else {
111+
result.State = api.DeploymentRestoreStateRestored
112+
}
113+
114+
s.Restore = result
115+
116+
return true
117+
}); err != nil {
118+
a.log.Error().Err(err).Msg("Unable to ser restored state")
119+
return false, err
120+
}
121+
122+
return true, nil
123+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Adam Janikowski
21+
//
22+
23+
package reconcile
24+
25+
import (
26+
"context"
27+
28+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
29+
"github.com/rs/zerolog"
30+
)
31+
32+
func init() {
33+
registerAction(api.ActionTypeBackupRestoreClean, newBackupRestoreCleanAction)
34+
}
35+
36+
func newBackupRestoreCleanAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
37+
a := &actionBackupRestoreClean{}
38+
39+
a.actionImpl = newActionImplDefRef(log, action, actionCtx, backupRestoreTimeout)
40+
41+
return a
42+
}
43+
44+
// actionBackupRestoreClean implements an BackupRestoreClean.
45+
type actionBackupRestoreClean struct {
46+
// actionImpl implement timeout and member id functions
47+
actionImpl
48+
49+
actionEmptyCheckProgress
50+
}
51+
52+
func (a actionBackupRestoreClean) Start(ctx context.Context) (bool, error) {
53+
if err := a.actionCtx.WithStatusUpdate(func(s *api.DeploymentStatus) bool {
54+
if s.Restore == nil {
55+
return false
56+
}
57+
58+
s.Restore = nil
59+
return true
60+
}, true); err != nil {
61+
return false, err
62+
}
63+
64+
return true, nil
65+
}

0 commit comments

Comments
 (0)