Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Restore tenant from backup and archive #74

Merged
merged 23 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
012dde3
chore: tests for tenant restore progress; definition of API types
powerfooI Sep 20, 2023
6c330c8
fix: add type for const var list
powerfooI Sep 20, 2023
9608fa8
chore: update fields of Tenant Source
powerfooI Sep 21, 2023
d95afe0
chore: adjust definition of restoreSource.until fields
powerfooI Sep 21, 2023
5bed661
chore: merge origin/2.0.x_dev, solve the conflicts
powerfooI Sep 21, 2023
1da79f5
fix: goimports -ed lint error
powerfooI Sep 21, 2023
9a535d6
fix: golangci lint var-name, modify Id to ID
powerfooI Sep 21, 2023
10644dc
chore: fix lint error, finish partial implementation of restore
powerfooI Sep 21, 2023
9a4793d
chore: integrate golangci-lint into makefile
powerfooI Sep 21, 2023
8ccf0d0
fix: obtenantbackup job refresh interval
powerfooI Sep 22, 2023
1988255
chore: finish coding, ready to test
powerfooI Sep 22, 2023
48868ea
fix tenant add replica, optimize resource update with retry
chris-sun-star Sep 22, 2023
591d3f0
fix: obteanntbackup job refresh (#71)
powerfooI Sep 22, 2023
e834dba
Merge pull request #72 from chris-sun-star/optimize_upgrade
powerfooI Sep 22, 2023
c608989
Merge remote-tracking branch 'origin/2.0.0_release' into feature/tena…
powerfooI Sep 22, 2023
f68a0e4
fix: task not registered
powerfooI Sep 22, 2023
5534d68
fix: event recorder unintialized
powerfooI Sep 25, 2023
19d4648
feat: restore tenant from backup, activate or replay
powerfooI Sep 25, 2023
4928eed
chore: add gap between triggering restore job and canceling restore
powerfooI Sep 25, 2023
a354d0e
Merge remote-tracking branch 'origin/2.0.x_dev' into feature/tenant-r…
powerfooI Sep 25, 2023
8be5c6c
fix: Makefile typo & backup_policy delete logic
powerfooI Sep 26, 2023
22e184c
chore: address some problems in PR comments
powerfooI Sep 27, 2023
6cc128c
fix: typo in Makefile
powerfooI Sep 27, 2023
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
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,20 @@ commit-hook: $(GOLANGCI_LINT) ## Install commit hook.
touch .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
echo "#!/bin/sh" > .git/hooks/pre-commit
echo "make lint" >> .git/hooks/pre-commit
echo "make lint" >> .git/hooks/pre-commit

.PHONY: connect
connect:
ifdef TENANT
mysql -h$(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}') -P2881 -A -uroot@${TENANT}
else
mysql -h$(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}') -P2881 -A -uroot -p
endif

.PHONY: connectob
connectob:
ifdef TENANT
mysql -h$(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}') -P2881 -A -uroot@${TENANT} -Doceanbase
else
mysql -h$(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}') -P2881 -A -uroot -p -Doceanbase
endif
4 changes: 3 additions & 1 deletion api/constants/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const (
RestoreJobStarting RestoreJobStatus = "STARTING"
RestoreJobRunning RestoreJobStatus = "RUNNING"
RestoreJobFailed RestoreJobStatus = "FAILED"
RestoreJobCanceling RestoreJobStatus = "CANCELING"
RestoreJobSuccessful RestoreJobStatus = "SUCCESSFUL"
RestoreJobCanceled RestoreJobStatus = "CANCELED"

RestoreJobStatusActivating RestoreJobStatus = "ACTIVATING"
RestoreJobStatusReplaying RestoreJobStatus = "REPLAYING"
)
4 changes: 3 additions & 1 deletion api/v1alpha1/obtenant_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type RestoreSourceSpec struct {
Until RestoreUntilConfig `json:"until"`
Description *string `json:"description,omitempty"`
ReplayLogUntil *RestoreUntilConfig `json:"replayLogUntil,omitempty"`
Cancel bool `json:"cancel,omitempty"`
}

type RestoreUntilConfig struct {
Expand Down Expand Up @@ -194,7 +195,8 @@ type TenantRecordInfo struct {
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="status",type="string",JSONPath=".status.status"
//+kubebuilder:printcolumn:name="clusterName",type="string",JSONPath=".spec.clusterName"
//+kubebuilder:printcolumn:name="tenantName",type="string",JSONPath=".spec.tenantName"
//+kubebuilder:printcolumn:name="clusterName",type="string",JSONPath=".spec.obcluster"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:printcolumn:name="locality",type="string",JSONPath=".status.tenantRecordInfo.locality",priority=1
//+kubebuilder:printcolumn:name="primaryZone",type="string",JSONPath=".status.tenantRecordInfo.primaryZone",priority=1
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/obtenant_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ func (r *OBTenant) validateMutation() error {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("tenantRole"), r.Spec.TenantRole, "Standby must have a source option, but both restore and tenantRef are nil now"))
}
}
// 2. Restore until with some limit must have a limit key
if r.Spec.Source != nil && r.Spec.Source.Restore != nil {
untilSpec := r.Spec.Source.Restore.Until
if !untilSpec.Unlimited && untilSpec.Scn == nil && untilSpec.Timestamp == nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec").Child("source").Child("restore").Child("until"), untilSpec, "Restore until must have a limit key, scn and timestamp are both nil now"))
}
}

if len(allErrs) == 0 {
return nil
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/obtenantbackuppolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,7 @@ func (in *JobOverview) DeepCopy() *JobOverview {
in.DeepCopyInto(out)
return out
}

func (in *OBTenantBackupPolicy) CopyStatus(out *OBTenantBackupPolicy) {
in.Status = out.Status
}
8 changes: 7 additions & 1 deletion api/v1alpha1/obtenantrestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ type OBTenantRestoreSpec struct {
TargetTenant string `json:"targetTenant"`
TargetCluster string `json:"targetCluster"`
RestoreRole constants.TenantRole `json:"restoreRole"`
Source TenantSourceSpec `json:"source"`
Source RestoreSourceSpec `json:"source"`
Option string `json:"restoreOption"`
}

// +kubebuilder:object:generate=false
Expand Down Expand Up @@ -59,6 +60,11 @@ func (in *OBTenantRestoreStatus) DeepCopyInto(out *OBTenantRestoreStatus) {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status`
//+kubebuilder:printcolumn:name="TargetTenant",type=string,JSONPath=`.spec.targetTenant`
//+kubebuilder:printcolumn:name="TargetCluster",type=string,JSONPath=`.spec.targetCluster`
//+kubebuilder:printcolumn:name="RestoreRole",type=string,JSONPath=`.spec.restoreRole`
//+kubebuilder:printcolumn:name="StatusInDB",type=string,JSONPath=`.status.restoreProgress.status`

// OBTenantRestore is the Schema for the obtenantrestores API
// An instance of OBTenantRestore stands for a tenant restore job
Expand Down
10 changes: 6 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ func main() {
// os.Exit(1)
// }
if err = (&controller.OBTenantBackupPolicyReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(config.OBTenantBackupPolicyControllerName),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "OBTenantBackupPolicy")
os.Exit(1)
Expand All @@ -200,8 +201,9 @@ func main() {
os.Exit(1)
}
if err = (&controller.OBTenantOperationReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor(config.OBTenantOperationControllerName),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "OBTenantOperation")
os.Exit(1)
Expand Down
69 changes: 42 additions & 27 deletions config/crd/bases/oceanbase.oceanbase.com_obtenantrestores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@ spec:
singular: obtenantrestore
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- jsonPath: .status.status
name: Status
type: string
- jsonPath: .spec.targetTenant
name: TargetTenant
type: string
- jsonPath: .spec.targetCluster
name: TargetCluster
type: string
- jsonPath: .spec.restoreRole
name: RestoreRole
type: string
- jsonPath: .status.restoreProgress.status
name: StatusInDB
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: OBTenantRestore is the Schema for the obtenantrestores API An
Expand All @@ -35,47 +51,46 @@ spec:
spec:
description: OBTenantRestoreSpec defines the desired state of OBTenantRestore
properties:
restoreOption:
type: string
restoreRole:
type: string
source:
description: Source for restoring or creating standby
properties:
restore:
cancel:
type: boolean
description:
type: string
replayLogUntil:
properties:
description:
scn:
type: string
replayLogUntil:
properties:
scn:
type: string
timestamp:
type: string
unlimited:
type: boolean
type: object
sourceUri:
timestamp:
type: string
until:
properties:
scn:
type: string
timestamp:
type: string
unlimited:
type: boolean
type: object
required:
- sourceUri
- until
unlimited:
type: boolean
type: object
tenant:
sourceUri:
type: string
until:
properties:
scn:
type: string
timestamp:
type: string
unlimited:
type: boolean
type: object
required:
- sourceUri
- until
type: object
targetCluster:
type: string
targetTenant:
type: string
required:
- restoreOption
- restoreRole
- source
- targetCluster
Expand Down
7 changes: 6 additions & 1 deletion config/crd/bases/oceanbase.oceanbase.com_obtenants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ spec:
- jsonPath: .status.status
name: status
type: string
- jsonPath: .spec.clusterName
- jsonPath: .spec.tenantName
name: tenantName
type: string
- jsonPath: .spec.obcluster
name: clusterName
type: string
- jsonPath: .metadata.creationTimestamp
Expand Down Expand Up @@ -153,6 +156,8 @@ spec:
properties:
restore:
properties:
cancel:
type: boolean
description:
type: string
replayLogUntil:
Expand Down
4 changes: 2 additions & 2 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ patchesStrategicMerge:
# - patches/webhook_in_obzones.yaml
# - patches/webhook_in_observers.yaml
# - patches/webhook_in_obparameters.yaml
# - patches/webhook_in_obtenants.yaml
- patches/webhook_in_obtenants.yaml
# - patches/webhook_in_obunits.yaml
# - patches/webhook_in_obclusterbackups.yaml
# - patches/webhook_in_obtenantbackups.yaml
Expand All @@ -39,7 +39,7 @@ patchesStrategicMerge:
# - patches/cainjection_in_obzones.yaml
# - patches/cainjection_in_observers.yaml
# - patches/cainjection_in_obparameters.yaml
# - patches/cainjection_in_obtenants.yaml
- patches/cainjection_in_obtenants.yaml
# - patches/cainjection_in_obunits.yaml
# - patches/cainjection_in_obclusterbackups.yaml
# - patches/cainjection_in_obtenantbackups.yaml
Expand Down
1 change: 1 addition & 0 deletions config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ spec:
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=127.0.0.1:8080"
- "--leader-elect"
- "--manager-namespace=oceanbase-system"
4 changes: 2 additions & 2 deletions deploy/backup_policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ metadata:
namespace: oceanbase
spec:
obClusterName: "test"
tenantName: "obtenant_test"
tenantSecret: "obtenant_test-credential"
tenantName: "t1"
tenantSecret: "t1-credential"
jobKeepWindow: "1d"
dataClean:
recoveryWindow: "8d"
Expand Down
Loading