Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Change Log

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

## [1.0.2](https://github.com/arangodb/kube-arangodb/tree/1.0.2) (2020-04-16)
- Added additional checks in UpToDate condition
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/deployment/v1/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ const (
ActionTypePVCResized ActionType = "PVCResized"
// UpToDateUpdateResized define up to date annotation in spec
UpToDateUpdate ActionType = "UpToDateUpdate"
// ActionTypeBackupRestore restore plan
ActionTypeBackupRestore ActionType = "BackupRestore"
// ActionTypeBackupRestoreClean restore plan
ActionTypeBackupRestoreClean ActionType = "BackupRestoreClean"
)

const (
Expand Down
134 changes: 0 additions & 134 deletions pkg/deployment/backup/handler.go

This file was deleted.

3 changes: 0 additions & 3 deletions pkg/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import (
"k8s.io/client-go/tools/record"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/arangodb/kube-arangodb/pkg/deployment/backup"
"github.com/arangodb/kube-arangodb/pkg/deployment/chaos"
"github.com/arangodb/kube-arangodb/pkg/deployment/reconcile"
"github.com/arangodb/kube-arangodb/pkg/deployment/resilience"
Expand Down Expand Up @@ -112,7 +111,6 @@ type Deployment struct {
reconciler *reconcile.Reconciler
resilience *resilience.Resilience
resources *resources.Resources
backup *backup.BackupHandler
chaosMonkey *chaos.Monkey
syncClientCache client.ClientCache
haveServiceMonitorCRD bool
Expand All @@ -135,7 +133,6 @@ func New(config Config, deps Dependencies, apiObject *api.ArangoDeployment) (*De
d.reconciler = reconcile.NewReconciler(deps.Log, d)
d.resilience = resilience.NewResilience(deps.Log, d)
d.resources = resources.NewResources(deps.Log, d)
d.backup = backup.NewHandler(deps.Log, d)
if d.status.last.AcceptedSpec == nil {
// We've validated the spec, so let's use it from now.
d.status.last.AcceptedSpec = apiObject.Spec.DeepCopy()
Expand Down
4 changes: 0 additions & 4 deletions pkg/deployment/deployment_inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ func (d *Deployment) inspectDeploymentWithError(ctx context.Context, lastInterva
return minInspectionInterval, errors.Wrapf(err, "Removed member cleanup failed")
}

if err := d.backup.CheckRestore(); err != nil {
return minInspectionInterval, errors.Wrapf(err, "Restore operation failed")
}

// At the end of the inspect, we cleanup terminated pods.
if x, err := d.resources.CleanupTerminatedPods(); err != nil {
return minInspectionInterval, errors.Wrapf(err, "Pod cleanup failed")
Expand Down
123 changes: 123 additions & 0 deletions pkg/deployment/reconcile/action_backup_restore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
//
// DISCLAIMER
//
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Adam Janikowski
//

package reconcile

import (
"context"

"github.com/arangodb/go-driver"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/rs/zerolog"
)

func init() {
registerAction(api.ActionTypeBackupRestore, newBackupRestoreAction)
}

func newBackupRestoreAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionBackupRestore{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, backupRestoreTimeout)

return a
}

// actionBackupRestore implements an BackupRestore.
type actionBackupRestore struct {
// actionImpl implement timeout and member id functions
actionImpl

actionEmptyCheckProgress
}

func (a actionBackupRestore) Start(ctx context.Context) (bool, error) {
spec := a.actionCtx.GetSpec()
status := a.actionCtx.GetStatus()

if spec.RestoreFrom == nil {
return true, nil
}

if status.Restore != nil {
a.log.Warn().Msg("Backup restore status should not be nil")
return true, nil
}

dbc, err := a.actionCtx.GetDatabaseClient(ctx)
if err != nil {
return false, err
}

backupResource, err := a.actionCtx.GetBackup(*spec.RestoreFrom)
if err != nil {
a.log.Error().Err(err).Msg("Unable to find backup")
return true, nil
}

if backupResource.Status.Backup == nil {
a.log.Error().Msg("Backup ID is not set")
return true, nil
}

if err := a.actionCtx.WithStatusUpdate(func(s *api.DeploymentStatus) bool {
result := &api.DeploymentRestoreResult{
RequestedFrom: spec.GetRestoreFrom(),
}

result.State = api.DeploymentRestoreStateRestoring

s.Restore = result

return true
}, true); err != nil {
return false, err
}

restoreError := dbc.Backup().Restore(ctx, driver.BackupID(backupResource.Status.Backup.ID), nil)
if restoreError != nil {
a.log.Error().Err(restoreError).Msg("Restore failed")
}

if err := a.actionCtx.WithStatusUpdate(func(s *api.DeploymentStatus) bool {
result := &api.DeploymentRestoreResult{
RequestedFrom: spec.GetRestoreFrom(),
}

if restoreError != nil {
result.State = api.DeploymentRestoreStateRestoreFailed
result.Message = restoreError.Error()
} else {
result.State = api.DeploymentRestoreStateRestored
}

s.Restore = result

return true
}); err != nil {
a.log.Error().Err(err).Msg("Unable to ser restored state")
return false, err
}

return true, nil
}
65 changes: 65 additions & 0 deletions pkg/deployment/reconcile/action_backup_restore_clean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// DISCLAIMER
//
// Copyright 2020 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//
// Author Adam Janikowski
//

package reconcile

import (
"context"

api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
"github.com/rs/zerolog"
)

func init() {
registerAction(api.ActionTypeBackupRestoreClean, newBackupRestoreCleanAction)
}

func newBackupRestoreCleanAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
a := &actionBackupRestoreClean{}

a.actionImpl = newActionImplDefRef(log, action, actionCtx, backupRestoreTimeout)

return a
}

// actionBackupRestoreClean implements an BackupRestoreClean.
type actionBackupRestoreClean struct {
// actionImpl implement timeout and member id functions
actionImpl

actionEmptyCheckProgress
}

func (a actionBackupRestoreClean) Start(ctx context.Context) (bool, error) {
if err := a.actionCtx.WithStatusUpdate(func(s *api.DeploymentStatus) bool {
if s.Restore == nil {
return false
}

s.Restore = nil
return true
}, true); err != nil {
return false, err
}

return true, nil
}
Loading