Skip to content

Commit

Permalink
fix: CR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Oct 9, 2023
1 parent 6dea4c9 commit 803d430
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 30 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ commit-hook: $(GOLANGCI_LINT) ## Install commit hook.
.PHONY: connect
connect:
ifdef TENANT
$(eval nodeHost = $(shell kubectl get pods -o jsonpath='{.items[1].status.podIP}'))
$(eval pwd = $(shell kubectl get secret $(shell kubectl get obtenant ${TENANT} -o jsonpath='{.status.credentials.root}') -o jsonpath='{.data.password}' | base64 -d))
$(if $(strip $(pwd)), mysql -h$(shell kubectl get pods -o jsonpath='{.items[1].status.podIP}') -P2881 -A -uroot@${TENANT} -p$(pwd) -Doceanbase, mysql -h$(shell kubectl get pods -o jsonpath='{.items[1].status.podIP}') -P2881 -A -uroot@${TENANT} -Doceanbase)
$(if $(strip $(pwd)), mysql -h$(nodeHost) -P2881 -A -uroot@${TENANT} -p$(pwd) -Doceanbase, mysql -h$(nodeHost) -P2881 -A -uroot@${TENANT} -Doceanbase)
else
mysql -h$(shell kubectl get pods -o jsonpath='{.items[1].status.podIP}') -P2881 -A -uroot -proot -Doceanbase
mysql -h$(shell kubectl get pods -o jsonpath='{.items[1].status.podIP}') -P2881 -A -uroot -p -Doceanbase
endif
1 change: 0 additions & 1 deletion api/v1alpha1/obcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ type OBClusterStatus struct {
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:printcolumn:name="Task",type="string",JSONPath=".status.operationContext.task"

// OBCluster is the Schema for the obclusters API
type OBCluster struct {
Expand Down
3 changes: 1 addition & 2 deletions api/v1alpha1/observer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ type OBServerStatus struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="NodeIP",type="string",JSONPath=".status.nodeIp"
//+kubebuilder:printcolumn:name="PodIP",type="string",JSONPath=".status.podIp"
//+kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.status"
//+kubebuilder:printcolumn:name="ClusterName",type="string",JSONPath=".spec.clusterName"
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:printcolumn:name="OBStatus",type="string",JSONPath=".status.obStatus"

Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/obtenant_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type OBTenantSpec struct {
//+kubebuilder:default=PRIMARY
TenantRole constants.TenantRole `json:"tenantRole,omitempty"`
Source *TenantSourceSpec `json:"source,omitempty"`
Credentials TenantCredentials `json:"credentials,omitempty"`
Credentials TenantCredentials `json:"credentials"`
}

type TenantCredentials struct {
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/obtenantoperation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type OBTenantOperationStatus struct {
//+kubebuilder:printcolumn:name="Type",type=string,JSONPath=`.spec.type`
//+kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.status`
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
//+kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=".status.primaryTenant.spec.obcluster"
//+kubebuilder:printcolumn:name="PrimaryTenant",type=string,JSONPath=".status.primaryTenant.spec.tenantName"
//+kubebuilder:printcolumn:name="SecondaryTenant",type=string,JSONPath=".status.secondaryTenant.spec.tenantName",priority=1

Expand Down
3 changes: 0 additions & 3 deletions config/crd/bases/oceanbase.oceanbase.com_obclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ spec:
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
- jsonPath: .status.operationContext.task
name: Task
type: string
name: v1alpha1
schema:
openAPIV3Schema:
Expand Down
7 changes: 2 additions & 5 deletions config/crd/bases/oceanbase.oceanbase.com_observers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ spec:
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .status.nodeIp
name: NodeIP
- jsonPath: .status.podIp
name: PodIP
type: string
- jsonPath: .status.status
name: Status
type: string
- jsonPath: .spec.clusterName
name: ClusterName
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ spec:
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
- jsonPath: .status.primaryTenant.spec.obcluster
name: Cluster
type: string
- jsonPath: .status.primaryTenant.spec.tenantName
name: PrimaryTenant
type: string
Expand Down
2 changes: 1 addition & 1 deletion pkg/resource/obtenant_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (m *OBTenantManager) GetTaskFunc(taskName string) (func() error, error) {
case taskname.CreateEmptyStandbyTenant:
return m.CreateEmptyStandbyTenant, nil
case taskname.CreateUsersByCredentials:
return m.CreateUserByCredentialSecrets, nil
return m.CreateUserWithCredentialSecrets, nil
case taskname.CheckPrimaryTenantLSIntegrity:
return m.CheckPrimaryTenantLSIntegrity, nil
default:
Expand Down
6 changes: 3 additions & 3 deletions pkg/resource/obtenant_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,12 +1078,12 @@ func (m *OBTenantManager) deleteUnitConfig() error {
return nil
}

func (m *OBTenantManager) CreateUserByCredentialSecrets() error {
func (m *OBTenantManager) CreateUserWithCredentialSecrets() error {
if m.OBTenant.Spec.TenantRole == constants.TenantRoleStandby {
// standby tenant can not need to create user
return nil
}
err := m.createUserByCredentials()
err := m.createUserWithCredentials()
if err != nil {
m.Recorder.Event(m.OBTenant, corev1.EventTypeWarning, "Failed to create user or change password", err.Error())
m.Logger.Error(err, "Failed to create user or change password, please check the credential secrets")
Expand All @@ -1092,7 +1092,7 @@ func (m *OBTenantManager) CreateUserByCredentialSecrets() error {
return nil
}

func (m *OBTenantManager) createUserByCredentials() error {
func (m *OBTenantManager) createUserWithCredentials() error {
con, err := m.getTenantClient()
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions pkg/resource/obtenantoperation_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func (m *ObTenantOperationManager) ChangeTenantRootPassword() error {
con, err := m.getTenantSysClient(m.Resource.Spec.ChangePwd.Tenant)
con, err := m.getTenantRootClient(m.Resource.Spec.ChangePwd.Tenant)
if err != nil {
return err
}
Expand Down Expand Up @@ -122,7 +122,7 @@ func (m *ObTenantOperationManager) CreateUsersForActivatedStandby() error {
// Hack:
tenantManager.OBTenant.ObjectMeta.SetNamespace(m.Resource.Namespace)
// Just reuse the logic of creating users for new coming tenant
_ = tenantManager.createUserByCredentials()
_ = tenantManager.createUserWithCredentials()
return nil
}

Expand Down Expand Up @@ -230,7 +230,7 @@ func (m *ObTenantOperationManager) SetTenantLogRestoreSource() error {
Logger: m.Logger,
OBTenant: originStandby,
}
err = tenantManager.createUserByCredentials()
err = tenantManager.createUserWithCredentials()
if err != nil {
return err
}
Expand All @@ -256,7 +256,7 @@ func (m *ObTenantOperationManager) SetTenantLogRestoreSource() error {
}

// get operation manager to exec sql
func (m *ObTenantOperationManager) getTenantSysClient(tenantName string) (*operation.OceanbaseOperationManager, error) {
func (m *ObTenantOperationManager) getTenantRootClient(tenantName string) (*operation.OceanbaseOperationManager, error) {
tenant := &v1alpha1.OBTenant{}
err := m.Client.Get(m.Ctx, types.NamespacedName{
Namespace: m.Resource.Namespace,
Expand Down
8 changes: 4 additions & 4 deletions pkg/task/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func init() {
GetRegistry().Register(flowname.RestoreAsStandbyFlow, RestoreAsStandby)

// tenant operation
GetRegistry().Register(flowname.ChangeTenantRootPasswordFlow, FlowChangeTenantRootPassword)
GetRegistry().Register(flowname.ActivateStandbyTenantFlow, FlowActivateStandbyTenantOp)
GetRegistry().Register(flowname.SwitchoverTenantsFlow, FlowSwitchoverTenants)
GetRegistry().Register(flowname.RevertSwitchoverTenantsFlow, FlowRevertSwitchoverTenants)
GetRegistry().Register(flowname.ChangeTenantRootPasswordFlow, ChangeTenantRootPassword)
GetRegistry().Register(flowname.ActivateStandbyTenantFlow, ActivateStandbyTenantOp)
GetRegistry().Register(flowname.SwitchoverTenantsFlow, SwitchoverTenants)
GetRegistry().Register(flowname.RevertSwitchoverTenantsFlow, RevertSwitchoverTenants)
}
8 changes: 4 additions & 4 deletions pkg/task/obtenant_operation_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/oceanbase/ob-operator/pkg/task/strategy"
)

func FlowChangeTenantRootPassword() *TaskFlow {
func ChangeTenantRootPassword() *TaskFlow {
return &TaskFlow{
OperationContext: &v1alpha1.OperationContext{
Name: flowname.ChangeTenantRootPasswordFlow,
Expand All @@ -35,7 +35,7 @@ func FlowChangeTenantRootPassword() *TaskFlow {
}
}

func FlowActivateStandbyTenantOp() *TaskFlow {
func ActivateStandbyTenantOp() *TaskFlow {
return &TaskFlow{
OperationContext: &v1alpha1.OperationContext{
Name: flowname.ActivateStandbyTenantFlow,
Expand All @@ -51,7 +51,7 @@ func FlowActivateStandbyTenantOp() *TaskFlow {
}
}

func FlowSwitchoverTenants() *TaskFlow {
func SwitchoverTenants() *TaskFlow {
return &TaskFlow{
OperationContext: &v1alpha1.OperationContext{
Name: flowname.SwitchoverTenantsFlow,
Expand All @@ -67,7 +67,7 @@ func FlowSwitchoverTenants() *TaskFlow {
}
}

func FlowRevertSwitchoverTenants() *TaskFlow {
func RevertSwitchoverTenants() *TaskFlow {
return &TaskFlow{
OperationContext: &v1alpha1.OperationContext{
Name: flowname.RevertSwitchoverTenantsFlow,
Expand Down

0 comments on commit 803d430

Please sign in to comment.