Skip to content

Commit

Permalink
fix: make magic numbers & strings constants; move type definitions in…
Browse files Browse the repository at this point in the history
… api constants to a specific package
  • Loading branch information
powerfooI committed Oct 9, 2023
1 parent 796ea8e commit 24edf80
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 136 deletions.
67 changes: 26 additions & 41 deletions api/constants/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,47 @@ See the Mulan PSL v2 for more details.

package constants

type BackupJobType string
import "github.com/oceanbase/ob-operator/api/types"

const (
BackupJobTypeFull BackupJobType = "FULL"
BackupJobTypeIncr BackupJobType = "INC"
BackupJobTypeClean BackupJobType = "CLEAN"
BackupJobTypeArchive BackupJobType = "ARCHIVE"
BackupJobTypeFull types.BackupJobType = "FULL"
BackupJobTypeIncr types.BackupJobType = "INC"
BackupJobTypeClean types.BackupJobType = "CLEAN"
BackupJobTypeArchive types.BackupJobType = "ARCHIVE"
)

type BackupJobStatus string

const (
BackupJobStatusRunning BackupJobStatus = "RUNNING"
BackupJobStatusInitializing BackupJobStatus = "INITIALIZING"
BackupJobStatusSuccessful BackupJobStatus = "SUCCESSFUL"
BackupJobStatusFailed BackupJobStatus = "FAILED"
BackupJobStatusCanceled BackupJobStatus = "CANCELED"
BackupJobStatusStopped BackupJobStatus = "STOPPED"
BackupJobStatusSuspend BackupJobStatus = "SUSPEND"
BackupJobStatusRunning types.BackupJobStatus = "RUNNING"
BackupJobStatusInitializing types.BackupJobStatus = "INITIALIZING"
BackupJobStatusSuccessful types.BackupJobStatus = "SUCCESSFUL"
BackupJobStatusFailed types.BackupJobStatus = "FAILED"
BackupJobStatusCanceled types.BackupJobStatus = "CANCELED"
BackupJobStatusStopped types.BackupJobStatus = "STOPPED"
BackupJobStatusSuspend types.BackupJobStatus = "SUSPEND"
)

type BackupPolicyStatusType string

const (
BackupPolicyStatusPreparing BackupPolicyStatusType = "PREPARING"
BackupPolicyStatusPrepared BackupPolicyStatusType = "PREPARED"
BackupPolicyStatusRunning BackupPolicyStatusType = "RUNNING"
BackupPolicyStatusFailed BackupPolicyStatusType = "FAILED"
BackupPolicyStatusPausing BackupPolicyStatusType = "PAUSING"
BackupPolicyStatusPaused BackupPolicyStatusType = "PAUSED"
BackupPolicyStatusStopped BackupPolicyStatusType = "STOPPED"
BackupPolicyStatusResuming BackupPolicyStatusType = "RESUMING"
BackupPolicyStatusPreparing types.BackupPolicyStatusType = "PREPARING"
BackupPolicyStatusPrepared types.BackupPolicyStatusType = "PREPARED"
BackupPolicyStatusRunning types.BackupPolicyStatusType = "RUNNING"
BackupPolicyStatusFailed types.BackupPolicyStatusType = "FAILED"
BackupPolicyStatusPausing types.BackupPolicyStatusType = "PAUSING"
BackupPolicyStatusPaused types.BackupPolicyStatusType = "PAUSED"
BackupPolicyStatusStopped types.BackupPolicyStatusType = "STOPPED"
BackupPolicyStatusResuming types.BackupPolicyStatusType = "RESUMING"
)

type BackupDestination struct {
Type BackupDestType `json:"type,omitempty"`
Path string `json:"path,omitempty"`
}

type BackupDestType string

const (
BackupDestTypeOSS BackupDestType = "OSS"
BackupDestTypeNFS BackupDestType = "NFS"
BackupDestTypeOSS types.BackupDestType = "OSS"
BackupDestTypeNFS types.BackupDestType = "NFS"
)

type LogArchiveDestState string

const (
LogArchiveDestStateEnable LogArchiveDestState = "ENABLE"
LogArchiveDestStateDefer LogArchiveDestState = "DEFER"
LogArchiveDestStateEnable types.LogArchiveDestState = "ENABLE"
LogArchiveDestStateDefer types.LogArchiveDestState = "DEFER"
)

type ArchiveBinding string

const (
ArchiveBindingOptional = "Optional"
ArchiveBindingMandatory = "Mandatory"
ArchiveBindingOptional types.ArchiveBinding = "Optional"
ArchiveBindingMandatory types.ArchiveBinding = "Mandatory"
)
16 changes: 8 additions & 8 deletions api/constants/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ See the Mulan PSL v2 for more details.

package constants

type RestoreJobStatus string
import "github.com/oceanbase/ob-operator/api/types"

const (
RestoreJobStarting RestoreJobStatus = "STARTING"
RestoreJobRunning RestoreJobStatus = "RUNNING"
RestoreJobFailed RestoreJobStatus = "FAILED"
RestoreJobSuccessful RestoreJobStatus = "SUCCESSFUL"
RestoreJobCanceled RestoreJobStatus = "CANCELED"
RestoreJobStarting types.RestoreJobStatus = "STARTING"
RestoreJobRunning types.RestoreJobStatus = "RUNNING"
RestoreJobFailed types.RestoreJobStatus = "FAILED"
RestoreJobSuccessful types.RestoreJobStatus = "SUCCESSFUL"
RestoreJobCanceled types.RestoreJobStatus = "CANCELED"

RestoreJobStatusActivating RestoreJobStatus = "ACTIVATING"
RestoreJobStatusReplaying RestoreJobStatus = "REPLAYING"
RestoreJobStatusActivating types.RestoreJobStatus = "ACTIVATING"
RestoreJobStatusReplaying types.RestoreJobStatus = "REPLAYING"
)
26 changes: 11 additions & 15 deletions api/constants/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,23 @@ See the Mulan PSL v2 for more details.

package constants

type TenantRole string
import "github.com/oceanbase/ob-operator/api/types"

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

type TenantOperationType string

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

type TenantOperationStatus string

const (
TenantOpStarting TenantOperationStatus = "STARTING"
TenantOpRunning TenantOperationStatus = "RUNNING"
TenantOpSuccessful TenantOperationStatus = "SUCCESSFUL"
TenantOpFailed TenantOperationStatus = "FAILED"
TenantOpReverting TenantOperationStatus = "REVERTING"
TenantOpStarting types.TenantOperationStatus = "STARTING"
TenantOpRunning types.TenantOperationStatus = "RUNNING"
TenantOpSuccessful types.TenantOperationStatus = "SUCCESSFUL"
TenantOpFailed types.TenantOperationStatus = "FAILED"
TenantOpReverting types.TenantOperationStatus = "REVERTING"
)
30 changes: 30 additions & 0 deletions api/types/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
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 types

type BackupJobType string
type BackupJobStatus string
type BackupPolicyStatusType string
type BackupDestType string
type LogArchiveDestState string
type ArchiveBinding string
type BackupDestination struct {
Type BackupDestType `json:"type,omitempty"`
Path string `json:"path,omitempty"`
}

type RestoreJobStatus string

type TenantRole string
type TenantOperationStatus string
type TenantOperationType string
14 changes: 7 additions & 7 deletions api/v1alpha1/obtenant_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/oceanbase/ob-operator/api/constants"
apitypes "github.com/oceanbase/ob-operator/api/types"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand All @@ -46,9 +46,9 @@ type OBTenantSpec struct {
Pools []ResourcePoolSpec `json:"pools"`

//+kubebuilder:default=PRIMARY
TenantRole constants.TenantRole `json:"tenantRole,omitempty"`
Source *TenantSourceSpec `json:"source,omitempty"`
Credentials TenantCredentials `json:"credentials"`
TenantRole apitypes.TenantRole `json:"tenantRole,omitempty"`
Source *TenantSourceSpec `json:"source,omitempty"`
Credentials TenantCredentials `json:"credentials"`
}

type TenantCredentials struct {
Expand Down Expand Up @@ -113,9 +113,9 @@ type OBTenantStatus struct {
OperationContext *OperationContext `json:"operationContext,omitempty"`
TenantRecordInfo TenantRecordInfo `json:"tenantRecordInfo,omitempty"`

TenantRole constants.TenantRole `json:"tenantRole,omitempty"`
Source *TenantSourceStatus `json:"source,omitempty"`
Credentials TenantCredentials `json:"credentials,omitempty"`
TenantRole apitypes.TenantRole `json:"tenantRole,omitempty"`
Source *TenantSourceStatus `json:"source,omitempty"`
Credentials TenantCredentials `json:"credentials,omitempty"`
}

type TenantSourceStatus struct {
Expand Down
28 changes: 14 additions & 14 deletions api/v1alpha1/obtenantbackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

constants "github.com/oceanbase/ob-operator/api/constants"
apitypes "github.com/oceanbase/ob-operator/api/types"
"github.com/oceanbase/ob-operator/pkg/oceanbase/model"
)

Expand All @@ -30,26 +30,26 @@ type OBTenantBackupSpec struct {
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of OBTenantBackup. Edit obtenantbackup_types.go to remove/update
Type constants.BackupJobType `json:"type"`
TenantName string `json:"tenantName"`
TenantSecret string `json:"tenantSecret"`
ObClusterName string `json:"obClusterName"`
Path string `json:"path,omitempty"`
Type apitypes.BackupJobType `json:"type"`
TenantName string `json:"tenantName"`
TenantSecret string `json:"tenantSecret"`
ObClusterName string `json:"obClusterName"`
Path string `json:"path,omitempty"`
}

// +kubebuilder:object:generate=false
// OBTenantBackupStatus defines the observed state of OBTenantBackup
type OBTenantBackupStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Status constants.BackupJobStatus `json:"status"`
Progress string `json:"progress,omitempty"`
OperationContext *OperationContext `json:"operationContext,omitempty"`
StartedAt string `json:"startedAt,omitempty"`
EndedAt string `json:"endedAt,omitempty"`
BackupJob *model.OBBackupJob `json:"backupJob,omitempty"`
ArchiveLogJob *model.OBArchiveLogJob `json:"archiveLogJob,omitempty"`
DataCleanJob *model.OBBackupCleanJob `json:"dataCleanJob,omitempty"`
Status apitypes.BackupJobStatus `json:"status"`
Progress string `json:"progress,omitempty"`
OperationContext *OperationContext `json:"operationContext,omitempty"`
StartedAt string `json:"startedAt,omitempty"`
EndedAt string `json:"endedAt,omitempty"`
BackupJob *model.OBBackupJob `json:"backupJob,omitempty"`
ArchiveLogJob *model.OBArchiveLogJob `json:"archiveLogJob,omitempty"`
DataCleanJob *model.OBBackupCleanJob `json:"dataCleanJob,omitempty"`
}

// fix: implementation of DeepCopyInto needed by zz_generated.deepcopy.go
Expand Down
22 changes: 11 additions & 11 deletions api/v1alpha1/obtenantbackuppolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

constants "github.com/oceanbase/ob-operator/api/constants"
apitypes "github.com/oceanbase/ob-operator/api/types"
"github.com/oceanbase/ob-operator/pkg/oceanbase/model"
)

Expand All @@ -42,8 +42,8 @@ type OBTenantBackupPolicySpec struct {
// +kubebuilder:object:generate=false
// OBTenantBackupPolicyStatus defines the observed state of OBTenantBackupPolicy
type OBTenantBackupPolicyStatus struct {
Status constants.BackupPolicyStatusType `json:"status"`
OperationContext *OperationContext `json:"operationContext,omitempty"`
Status apitypes.BackupPolicyStatusType `json:"status"`
OperationContext *OperationContext `json:"operationContext,omitempty"`

NextFull string `json:"nextFull,omitempty"`
NextIncremental string `json:"nextIncremental,omitempty"`
Expand Down Expand Up @@ -127,18 +127,18 @@ func init() {

// LogArchiveConfig contains the configuration for log archive progress
type LogArchiveConfig struct {
Destination constants.BackupDestination `json:"destination"`
SwitchPieceInterval string `json:"switchPieceInterval"`
Binding constants.ArchiveBinding `json:"binding,omitempty"`
DestDisabled bool `json:"destDisabled,omitempty"`
Concurrency int `json:"concurrency,omitempty"`
Destination apitypes.BackupDestination `json:"destination"`
SwitchPieceInterval string `json:"switchPieceInterval"`
Binding apitypes.ArchiveBinding `json:"binding,omitempty"`
DestDisabled bool `json:"destDisabled,omitempty"`
Concurrency int `json:"concurrency,omitempty"`
}

// DataBackupConfig contains the configuration for data backup progress
type DataBackupConfig struct {
Destination constants.BackupDestination `json:"destination"`
FullCrontab string `json:"fullCrontab,omitempty"`
IncrementalCrontab string `json:"incrementalCrontab,omitempty"`
Destination apitypes.BackupDestination `json:"destination"`
FullCrontab string `json:"fullCrontab,omitempty"`
IncrementalCrontab string `json:"incrementalCrontab,omitempty"`
}

type CleanPolicy struct {
Expand Down
18 changes: 9 additions & 9 deletions api/v1alpha1/obtenantoperation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/oceanbase/ob-operator/api/constants"
apitypes "github.com/oceanbase/ob-operator/api/types"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand All @@ -30,10 +30,10 @@ 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 apitypes.TenantOperationType `json:"type"`
Switchover *OBTenantOpSwitchoverSpec `json:"switchover,omitempty"`
Failover *OBTenantOpFailoverSpec `json:"failover,omitempty"`
ChangePwd *OBTenantOpChangePwdSpec `json:"changePwd,omitempty"`
}

type OBTenantOpSwitchoverSpec struct {
Expand All @@ -54,10 +54,10 @@ type OBTenantOpChangePwdSpec struct {
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"`
PrimaryTenant *OBTenant `json:"primaryTenant,omitempty"`
SecondaryTenant *OBTenant `json:"secondaryTenant,omitempty"`
Status apitypes.TenantOperationStatus `json:"status"`
OperationContext *OperationContext `json:"operationContext,omitempty"`
PrimaryTenant *OBTenant `json:"primaryTenant,omitempty"`
SecondaryTenant *OBTenant `json:"secondaryTenant,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
21 changes: 11 additions & 10 deletions api/v1alpha1/obtenantrestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/oceanbase/ob-operator/api/constants"
apitypes "github.com/oceanbase/ob-operator/api/types"

"github.com/oceanbase/ob-operator/pkg/oceanbase/model"
)

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

TargetTenant string `json:"targetTenant"`
TargetCluster string `json:"targetCluster"`
RestoreRole constants.TenantRole `json:"restoreRole"`
Source RestoreSourceSpec `json:"source"`
Option string `json:"restoreOption"`
PrimaryTenant *string `json:"primaryTenant,omitempty"`
TargetTenant string `json:"targetTenant"`
TargetCluster string `json:"targetCluster"`
RestoreRole apitypes.TenantRole `json:"restoreRole"`
Source RestoreSourceSpec `json:"source"`
Option string `json:"restoreOption"`
PrimaryTenant *string `json:"primaryTenant,omitempty"`
}

// +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 constants.RestoreJobStatus `json:"status"`
RestoreProgress *model.RestoreHistory `json:"restoreProgress,omitempty"`
OperationContext *OperationContext `json:"operationContext,omitempty"`
Status apitypes.RestoreJobStatus `json:"status"`
RestoreProgress *model.RestoreHistory `json:"restoreProgress,omitempty"`
OperationContext *OperationContext `json:"operationContext,omitempty"`
}

func (in *OBTenantRestoreStatus) DeepCopyInto(out *OBTenantRestoreStatus) {
Expand Down
Loading

0 comments on commit 24edf80

Please sign in to comment.