Skip to content

Commit

Permalink
Merge pull request #74 from PowerfooI/feature/tenant-restore
Browse files Browse the repository at this point in the history
Feature: Restore tenant from backup and archive
  • Loading branch information
powerfooI authored Sep 27, 2023
2 parents 0624ec5 + 6cc128c commit 5548768
Show file tree
Hide file tree
Showing 49 changed files with 1,383 additions and 386 deletions.
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ tools: $(YQ) $(SEMVER)

.PHONY: GOLANGCI_LINT
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
$(GOLANG_LINT):
$(GOLANGCI_LINT):
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANG_CI_VERSION}

.PHONY: lint
Expand All @@ -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

0 comments on commit 5548768

Please sign in to comment.