Skip to content

Commit

Permalink
chore: tests for tenant restore progress; definition of API types
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Sep 20, 2023
1 parent 90f4d2d commit 012dde3
Show file tree
Hide file tree
Showing 30 changed files with 1,441 additions and 257 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,13 @@ resources:
defaulting: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: oceanbase.com
group: oceanbase
kind: OBTenantOperation
path: github.com/oceanbase/ob-operator/api/v1alpha1
version: v1alpha1
version: "3"
37 changes: 37 additions & 0 deletions api/constants/tenant.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright (c) 2023 OceanBase
ob-operator is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/

package constants

type TenantRole string

const (
TenantRolePrimary TenantRole = "PRIMARY"
TenantRoleStandby TenantRole = "STANDBY"
)

type TenantOperationType string

const (
TenantOpSwitchover TenantOperationType = "SWITCHOVER"
TenantOpFailover = "FAILOVER"
TenantOpChangePwd = "CHANGE_PASSWORD"
)

type TenantOperationStatus string

const (
TenantOpStarting TenantOperationStatus = "STARTING"
TenantOpRunning = "RUNNING"
TenantOpSuccessful = "SUCCESSFUL"
TenantOpFailed = "FAILED"
)
67 changes: 67 additions & 0 deletions api/v1alpha1/obtenant_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ limitations under the License.
package v1alpha1

import (
"github.com/oceanbase/ob-operator/api/constants"
"github.com/oceanbase/ob-operator/pkg/oceanbase/model"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -42,6 +45,24 @@ type OBTenantSpec struct {
ConnectWhiteList string `json:"connectWhiteList,omitempty"`

Pools []ResourcePoolSpec `json:"pools"`

//+kubebuilder:default=PRIMARY
TenantRole constants.TenantRole `json:"tenantRole,omitempty"`
Source *TenantSourceSpec `json:"source,omitempty"`
Credentials []corev1.SecretReference `json:"credentials,omitempty"`
}

// Source for restoring or creating standby
type TenantSourceSpec struct {
Tenant *string `json:"tenant,omitempty"`
Restore *RestoreSource `json:"restore,omitempty"`
}

type RestoreSource struct {
SourceUri string `json:"sourceUri"`
Until string `json:"until"`
Description *string `json:"description,omitempty"`
ReplayLogUntil *string `json:"replayLogUntil,omitempty"`
}

type ResourcePoolSpec struct {
Expand Down Expand Up @@ -71,6 +92,7 @@ type UnitConfig struct {
LogDiskSize resource.Quantity `json:"logDiskSize,omitempty"`
}

// +kubebuilder:object:generate=false
// OBTenantStatus defines the observed state of OBTenant
type OBTenantStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand All @@ -79,6 +101,51 @@ type OBTenantStatus struct {
Pools []ResourcePoolStatus `json:"resourcePool"`
OperationContext *OperationContext `json:"operationContext,omitempty"`
TenantRecordInfo TenantRecordInfo `json:"tenantRecordInfo,omitempty"`

TenantRole constants.TenantRole `json:"tenantRole,omitempty"`
Source *TenantSourceStatus `json:"source,omitempty"`
}

// +kubebuilder:object:generate=false
type TenantSourceStatus struct {
Tenant *string `json:"tenant,omitempty"`
Restore *model.RestoreHistory `json:"restore,omitempty"`
}

func (in *OBTenantStatus) DeepCopyInto(out *OBTenantStatus) {
*out = *in
if in.Pools != nil {
in, out := &in.Pools, &out.Pools
*out = make([]ResourcePoolStatus, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
if in.OperationContext != nil {
in, out := &in.OperationContext, &out.OperationContext
*out = new(OperationContext)
(*in).DeepCopyInto(*out)
}
out.TenantRecordInfo = in.TenantRecordInfo
if in.Source != nil {
in, out := &in.Source, &out.Source
*out = new(TenantSourceStatus)
(*in).DeepCopyInto(*out)
}
}

func (in *TenantSourceStatus) DeepCopyInto(out *TenantSourceStatus) {
*out = *in
if in.Tenant != nil {
in, out := &in.Tenant, &out.Tenant
*out = new(string)
**out = **in
}
if in.Restore != nil {
in, out := &in.Restore, &out.Restore
*out = new(model.RestoreHistory)
**out = **in
}
}

type ResourcePoolStatus struct {
Expand Down
84 changes: 84 additions & 0 deletions api/v1alpha1/obtenantoperation_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
Copyright 2023.
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.
*/

package v1alpha1

import (
"github.com/oceanbase/ob-operator/api/constants"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// OBTenantOperationSpec defines the desired state of OBTenantOperation
type OBTenantOperationSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

Type constants.TenantOperationType `json:"type"`
Switchover *OBTenantOpSwitchoverSpec `json:"switchover,omitempty"`
Failover *OBTenantOpFailoverSpec `json:"failover,omitempty"`
ChangePwd *OBTenantOpChangePwdSpec `json:"changePwd,omitempty"`
}

type OBTenantOpSwitchoverSpec struct {
PrimaryTenant string `json:"primaryTenant"`
StandbyTenant string `json:"standbyTenant"`
}

type OBTenantOpFailoverSpec struct {
StandbyTenant string `json:"standbyTenant"`
}

type OBTenantOpChangePwdSpec struct {
Tenant string `json:"tenant"`
SecretRef corev1.SecretReference `json:"secretRef"`
}

// OBTenantOperationStatus defines the observed state of OBTenantOperation
type OBTenantOperationStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Status constants.TenantOperationStatus `json:"status"`
OperationContext *OperationContext `json:"operationContext,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// OBTenantOperation is the Schema for the obtenantoperations API
type OBTenantOperation struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec OBTenantOperationSpec `json:"spec,omitempty"`
Status OBTenantOperationStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// OBTenantOperationList contains a list of OBTenantOperation
type OBTenantOperationList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []OBTenantOperation `json:"items"`
}

func init() {
SchemeBuilder.Register(&OBTenantOperation{}, &OBTenantOperationList{})
}
33 changes: 23 additions & 10 deletions api/v1alpha1/obtenantrestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ See the Mulan PSL v2 for more details.
package v1alpha1

import (
batchv1 "k8s.io/api/batch/v1"
"github.com/oceanbase/ob-operator/api/constants"
"github.com/oceanbase/ob-operator/pkg/oceanbase/model"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -25,21 +26,33 @@ type OBTenantRestoreSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

ObClusterName string `json:"obClusterName"`
RestoreTenantName string `json:"restoreTenantName"`
Type string `json:"type"`
SourceUri string `json:"sourceUri"`
Until string `json:"until,omitempty"`
TargetTenant string `json:"targetTenant"`
RestoreRole constants.TenantRole `json:"restoreRole"`
Source TenantSourceSpec `json:"source"`
}

// +kubebuilder:object:generate=false
// OBTenantRestoreStatus defines the observed state of OBTenantRestore
type OBTenantRestoreStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Status RestoreJobStatus `json:"status"`
JobStatus batchv1.JobStatus `json:"jobStatus"`
Progress string `json:"progress"`
OperationContext *OperationContext `json:"operationContext,omitempty"`
Status RestoreJobStatus `json:"status"`
RestoreProgress *model.RestoreHistory `json:"restoreProgress,omitempty"`
OperationContext *OperationContext `json:"operationContext,omitempty"`
}

func (in *OBTenantRestoreStatus) DeepCopyInto(out *OBTenantRestoreStatus) {
*out = *in
if in.RestoreProgress != nil {
in, out := &in.RestoreProgress, &out.RestoreProgress
*out = new(model.RestoreHistory)
**out = **in
}
if in.OperationContext != nil {
in, out := &in.OperationContext, &out.OperationContext
*out = new(OperationContext)
(*in).DeepCopyInto(*out)
}
}

//+kubebuilder:object:root=true
Expand Down
Loading

0 comments on commit 012dde3

Please sign in to comment.