Skip to content

Commit

Permalink
Merge pull request #1763 from safboukhari/implement_point_in_time_res…
Browse files Browse the repository at this point in the history
…tore_for_docdb

feat(docdb): Add restore from snapshot and point in time
  • Loading branch information
Christopher Haar committed Jun 13, 2023
2 parents f2c6a7c + 05d7a2f commit 594d12c
Show file tree
Hide file tree
Showing 7 changed files with 836 additions and 6 deletions.
76 changes: 76 additions & 0 deletions apis/docdb/v1alpha1/custom_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// RDS instance states.
Expand Down Expand Up @@ -156,6 +157,81 @@ type CustomDBClusterParameters struct {
VPCSecurityGroupIDsRefs []xpv1.Reference `json:"vpcSecurityGroupIDsRefs,omitempty"`
// TODO(haarchri): when resource is bumped to beta we will convert this field to vpcSecurityGroupIdSelector
VPCSecurityGroupIDsSelector *xpv1.Selector `json:"vpcSecurityGroupIDsSelector,omitempty"`

// RestoreFrom specifies the details of the backup to restore when creating a new DBCluster.
// +optional
RestoreFrom *RestoreDBClusterBackupConfiguration `json:"restoreFrom,omitempty"`
}

// RestoreSnapshotConfiguration defines the details of the snapshot to restore from.
type RestoreSnapshotConfiguration struct {
// SnapshotIdentifier is the identifier of the snapshot to restore.
SnapshotIdentifier string `json:"snapshotIdentifier"`
}

// RestorePointInTimeConfiguration defines the details of the time to restore from
type RestorePointInTimeConfiguration struct {
// RestoreTime is the date and time (UTC) to restore from.
// Must be before the latest restorable time for the DB instance.
// Can't be specified if the useLatestRestorableTime parameter is enabled.
// Example: 2011-09-07T23:45:00Z
// +optional
RestoreTime *metav1.Time `json:"restoreTime,omitempty"`

// UseLatestRestorableTime indicates that the DB instance is restored from the latest backup
// Can't be specified if the restoreTime parameter is provided.
// +optional
UseLatestRestorableTime *bool `json:"useLatestRestorableTime,omitempty"`

// SourceDBClusterIdentifier specifies the identifier of the source DB cluster from which to restore. Constraints:
// Must match the identifier of an existing DB instance.
// +optional
SourceDBClusterIdentifier string `json:"sourceDBClusterIdentifier"`

// The type of restore to be performed. You can specify one of the following
// values:
//
// * full-copy - The new DB cluster is restored as a full copy of the source
// DB cluster.
//
// * copy-on-write - The new DB cluster is restored as a clone of the source
// DB cluster.
//
// Constraints: You can't specify copy-on-write if the engine version of the
// source DB cluster is earlier than 1.11.
//
// If you don't specify a RestoreType value, then the new DB cluster is restored
// as a full copy of the source DB cluster.
//
// Valid for: Aurora DB clusters and Multi-AZ DB clusters
// +optional
// +kubebuilder:validation:Enum=full-copy;copy-on-write
RestoreType *string `json:"restoreType,omitempty"`
}

// RestoreSource specifies the data source for a DocumentDB restore.
type RestoreSource string

// RestoreSource values
const (
RestoreSourceSnapshot = "Snapshot"
RestoreSourcePointInTime = "PointInTime"
)

// RestoreDBClusterBackupConfiguration defines the backup to restore a new DBCluster from.
type RestoreDBClusterBackupConfiguration struct {
// Snapshot specifies the details of the snapshot to restore from.
// +optional
Snapshot *RestoreSnapshotConfiguration `json:"snapshot,omitempty"`

// PointInTime specifies the details of the point in time restore.
// +optional
PointInTime *RestorePointInTimeConfiguration `json:"pointInTime,omitempty"`

// Source is the type of the backup to restore when creating a new DBCluster or DBInstance.
// Snapshot and PointInTime are supported.
// +kubebuilder:validation:Enum=Snapshot;PointInTime
Source RestoreSource `json:"source"`
}

// CustomParameter are custom parameters for the Parameter
Expand Down
74 changes: 74 additions & 0 deletions apis/docdb/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ require (
k8s.io/api v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
sigs.k8s.io/controller-runtime v0.14.1
sigs.k8s.io/controller-tools v0.11.1
sigs.k8s.io/yaml v1.3.0
Expand Down Expand Up @@ -153,7 +154,6 @@ require (
k8s.io/component-base v0.26.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
65 changes: 65 additions & 0 deletions package/crds/docdb.aws.crossplane.io_dbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,71 @@ spec:
region:
description: Region is which region the DBCluster will be created.
type: string
restoreFrom:
description: RestoreFrom specifies the details of the backup to
restore when creating a new DBCluster.
properties:
pointInTime:
description: PointInTime specifies the details of the point
in time restore.
properties:
restoreTime:
description: 'RestoreTime is the date and time (UTC) to
restore from. Must be before the latest restorable time
for the DB instance. Can''t be specified if the useLatestRestorableTime
parameter is enabled. Example: 2011-09-07T23:45:00Z'
format: date-time
type: string
restoreType:
description: "The type of restore to be performed. You
can specify one of the following values: \n * full-copy
- The new DB cluster is restored as a full copy of the
source DB cluster. \n * copy-on-write - The new DB cluster
is restored as a clone of the source DB cluster. \n
Constraints: You can't specify copy-on-write if the
engine version of the source DB cluster is earlier than
1.11. \n If you don't specify a RestoreType value, then
the new DB cluster is restored as a full copy of the
source DB cluster. \n Valid for: Aurora DB clusters
and Multi-AZ DB clusters"
enum:
- full-copy
- copy-on-write
type: string
sourceDBClusterIdentifier:
description: 'SourceDBClusterIdentifier specifies the
identifier of the source DB cluster from which to restore.
Constraints: Must match the identifier of an existing
DB instance.'
type: string
useLatestRestorableTime:
description: UseLatestRestorableTime indicates that the
DB instance is restored from the latest backup Can't
be specified if the restoreTime parameter is provided.
type: boolean
type: object
snapshot:
description: Snapshot specifies the details of the snapshot
to restore from.
properties:
snapshotIdentifier:
description: SnapshotIdentifier is the identifier of the
snapshot to restore.
type: string
required:
- snapshotIdentifier
type: object
source:
description: Source is the type of the backup to restore when
creating a new DBCluster or DBInstance. Snapshot and PointInTime
are supported.
enum:
- Snapshot
- PointInTime
type: string
required:
- source
type: object
skipFinalSnapshot:
description: "Determines whether a final cluster snapshot is created
before the cluster is deleted. If true is specified, no cluster
Expand Down
34 changes: 34 additions & 0 deletions pkg/clients/docdb/fake/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type MockDocDBClient struct {
MockModifyDBClusterWithContext func(context.Context, *docdb.ModifyDBClusterInput, []request.Option) (*docdb.ModifyDBClusterOutput, error)
MockDeleteDBClusterWithContext func(context.Context, *docdb.DeleteDBClusterInput, []request.Option) (*docdb.DeleteDBClusterOutput, error)

MockRestoreDBClusterFromSnapshotWithContext func(context.Context, *docdb.RestoreDBClusterFromSnapshotInput, []request.Option) (*docdb.RestoreDBClusterFromSnapshotOutput, error)
MockRestoreDBClusterToPointInTimeWithContext func(context.Context, *docdb.RestoreDBClusterToPointInTimeInput, []request.Option) (*docdb.RestoreDBClusterToPointInTimeOutput, error)

Called MockDocDBClientCall
}

Expand Down Expand Up @@ -328,6 +331,34 @@ func (m *MockDocDBClient) DeleteDBClusterWithContext(ctx context.Context, i *doc
return m.MockDeleteDBClusterWithContext(ctx, i, opts)
}

// CallRestoreDBClusterFromSnapshotWithContext to log call
type CallRestoreDBClusterFromSnapshotWithContext struct {
Ctx aws.Context
I *docdb.RestoreDBClusterFromSnapshotInput
Opts []request.Option
}

// RestoreDBClusterFromSnapshotWithContext calls MockRestoreDBClusterFromSnapshotWithContext
func (m *MockDocDBClient) RestoreDBClusterFromSnapshotWithContext(ctx context.Context, i *docdb.RestoreDBClusterFromSnapshotInput, opts ...request.Option) (*docdb.RestoreDBClusterFromSnapshotOutput, error) {
m.Called.RestoreDBClusterFromSnapshotWithContext = append(m.Called.RestoreDBClusterFromSnapshotWithContext, &CallRestoreDBClusterFromSnapshotWithContext{Ctx: ctx, I: i, Opts: opts})

return m.MockRestoreDBClusterFromSnapshotWithContext(ctx, i, opts)
}

// CallRestoreDBClusterToPointInTimeWithContext to log call
type CallRestoreDBClusterToPointInTimeWithContext struct {
Ctx aws.Context
I *docdb.RestoreDBClusterToPointInTimeInput
Opts []request.Option
}

// RestoreDBClusterToPointInTimeWithContext calls MockRestoreDBClusterToPointInTimeWithContext
func (m *MockDocDBClient) RestoreDBClusterToPointInTimeWithContext(ctx context.Context, i *docdb.RestoreDBClusterToPointInTimeInput, opts ...request.Option) (*docdb.RestoreDBClusterToPointInTimeOutput, error) {
m.Called.RestoreDBClusterToPointInTimeWithContext = append(m.Called.RestoreDBClusterToPointInTimeWithContext, &CallRestoreDBClusterToPointInTimeWithContext{Ctx: ctx, I: i, Opts: opts})

return m.MockRestoreDBClusterToPointInTimeWithContext(ctx, i, opts)
}

// MockDocDBClientCall to log calls
type MockDocDBClientCall struct {
ListTagsForResource []*CallListTagsForResource
Expand All @@ -353,4 +384,7 @@ type MockDocDBClientCall struct {
CreateDBClusterWithContext []*CallCreateDBClusterWithContext
ModifyDBClusterWithContext []*CallModifyDBClusterWithContext
DeleteDBClusterWithContext []*CallDeleteDBClusterWithContext

RestoreDBClusterFromSnapshotWithContext []*CallRestoreDBClusterFromSnapshotWithContext
RestoreDBClusterToPointInTimeWithContext []*CallRestoreDBClusterToPointInTimeWithContext
}
Loading

0 comments on commit 594d12c

Please sign in to comment.