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

Fixed bugs found in smoke test #355

Merged
merged 8 commits into from
May 8, 2024
22 changes: 22 additions & 0 deletions internal/const/oceanbase/finalizers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
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 oceanbase

const (
FinalizerIgnoreDeletion = "finalizers.oceanbase.com/ignore-deletion"
FinalizerDeleteOBZone = "finalizers.oceanbase.com.deleteobzone"
FinalizerDeleteOBServer = "finalizers.oceanbase.com.deleteobserver"
FinalizerOBServer = "observer.oceanbase.com.finalizers"
FinalizerDeleteOBTenant = "finalizers.oceanbase.com.deleteobtenant"
FinalizerBackupPolicy = "obtenantbackuppolicy.finalizers.oceanbase.com"
)
5 changes: 3 additions & 2 deletions internal/controller/observer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package controller

import (
"context"
"fmt"
"strings"
"time"

"github.com/pkg/errors"
Expand All @@ -31,6 +31,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"

v1alpha1 "github.com/oceanbase/ob-operator/api/v1alpha1"
oceanbaseconst "github.com/oceanbase/ob-operator/internal/const/oceanbase"
resobserver "github.com/oceanbase/ob-operator/internal/resource/observer"
"github.com/oceanbase/ob-operator/internal/telemetry"
"github.com/oceanbase/ob-operator/pkg/coordinator"
Expand Down Expand Up @@ -87,7 +88,7 @@ func (r *OBServerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
}

// execute finalizers
finalizerName := fmt.Sprintf("observer.oceanbase.com.finalizers.%s", observer.Name)
finalizerName := strings.Join([]string{oceanbaseconst.FinalizerOBServer, observer.Name}, ".")
if !observer.ObjectMeta.DeletionTimestamp.IsZero() {
needExecuteFinalizer := false
for _, finalizer := range observer.ObjectMeta.Finalizers {
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/obtenant_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"

v1alpha1 "github.com/oceanbase/ob-operator/api/v1alpha1"
oceanbaseconst "github.com/oceanbase/ob-operator/internal/const/oceanbase"
resobtenant "github.com/oceanbase/ob-operator/internal/resource/obtenant"
"github.com/oceanbase/ob-operator/internal/telemetry"
"github.com/oceanbase/ob-operator/pkg/coordinator"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (r *OBTenantReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
}

if obtenant.ObjectMeta.DeletionTimestamp.IsZero() {
finalizerName := "finalizers.oceanbase.com.deleteobtenant"
finalizerName := oceanbaseconst.FinalizerDeleteOBTenant
if !controllerutil.ContainsFinalizer(obtenant, finalizerName) {
controllerutil.AddFinalizer(obtenant, finalizerName)
err := r.Client.Update(ctx, obtenant)
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/obtenantbackuppolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"

"github.com/oceanbase/ob-operator/api/v1alpha1"
oceanbaseconst "github.com/oceanbase/ob-operator/internal/const/oceanbase"
resbackuppolicy "github.com/oceanbase/ob-operator/internal/resource/obtenantbackuppolicy"
"github.com/oceanbase/ob-operator/internal/telemetry"
"github.com/oceanbase/ob-operator/pkg/coordinator"
Expand Down Expand Up @@ -57,7 +58,7 @@ func (r *OBTenantBackupPolicyReconciler) Reconcile(ctx context.Context, req ctrl
return ctrl.Result{}, client.IgnoreNotFound(err)
}

finalizerName := "obtenantbackuppolicy.finalizers.oceanbase.com"
finalizerName := oceanbaseconst.FinalizerBackupPolicy
// examine DeletionTimestamp to determine if the policy is under deletion
if policy.ObjectMeta.DeletionTimestamp.IsZero() {
if !controllerutil.ContainsFinalizer(policy, finalizerName) {
Expand Down
12 changes: 7 additions & 5 deletions internal/dashboard/generated/bindata/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions internal/resource/obcluster/obcluster_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
"github.com/go-logr/logr"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

apitypes "github.com/oceanbase/ob-operator/api/types"
v1alpha1 "github.com/oceanbase/ob-operator/api/v1alpha1"
Expand Down Expand Up @@ -240,6 +242,21 @@ func (m *OBClusterManager) UpdateStatus() error {
}
}
m.Logger.V(oceanbaseconst.LogLevelTrace).Info("Update obcluster status", "status", m.OBCluster.Status)
ignoreDel, ok := resourceutils.GetAnnotationField(m.OBCluster, oceanbaseconst.AnnotationsIgnoreDeletion)
if ok && ignoreDel == "true" && !controllerutil.ContainsFinalizer(m.OBCluster, oceanbaseconst.FinalizerIgnoreDeletion) {
controllerutil.AddFinalizer(m.OBCluster, oceanbaseconst.FinalizerIgnoreDeletion)
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
return m.Client.Update(m.Ctx, m.OBCluster)
})
} else if (!ok || ignoreDel != "true") && controllerutil.ContainsFinalizer(m.OBCluster, oceanbaseconst.FinalizerIgnoreDeletion) {
controllerutil.RemoveFinalizer(m.OBCluster, oceanbaseconst.FinalizerIgnoreDeletion)
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
return m.Client.Update(m.Ctx, m.OBCluster)
})
}
if err != nil {
m.Logger.Error(err, "Failed to update finalizers of OBCluster")
}
err = m.retryUpdateStatus()
if err != nil {
m.Logger.Error(err, "Got error when update obcluster status")
Expand Down
2 changes: 1 addition & 1 deletion internal/resource/obcluster/obcluster_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func CreateOBZone(m *OBClusterManager) tasktypes.TaskError {
labels := make(map[string]string)
labels[oceanbaseconst.LabelRefUID] = string(m.OBCluster.GetUID())
labels[oceanbaseconst.LabelRefOBCluster] = m.OBCluster.Name
finalizerName := "finalizers.oceanbase.com.deleteobzone"
finalizerName := oceanbaseconst.FinalizerDeleteOBZone
finalizers := []string{finalizerName}
obzone := &v1alpha1.OBZone{
ObjectMeta: metav1.ObjectMeta{
Expand Down
26 changes: 11 additions & 15 deletions internal/resource/obtenant/obtenant_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ See the Mulan PSL v2 for more details.
package obtenant

import (
"fmt"
"reflect"
"time"

Expand Down Expand Up @@ -59,19 +58,19 @@ func CheckPoolAndConfig(m *OBTenantManager) tasktypes.TaskError {
tenantName := m.OBTenant.Spec.TenantName
client, err := m.getClusterSysClient()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Get sys client when checking and applying tenant '%s' pool and config", tenantName))
return errors.Wrapf(err, "Get sys client when checking and applying tenant '%s' pool and config", tenantName)
}
params, err := client.GetParameter(m.Ctx, "__min_full_resource_pool_memory", nil)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Get parameter __min_full_resource_pool_memory when checking and applying tenant '%s' pool and config", tenantName))
return errors.Wrapf(err, "Get parameter __min_full_resource_pool_memory when checking and applying tenant '%s' pool and config", tenantName)
}
if len(params) == 0 {
return errors.New("Getting parameter __min_full_resource_pool_memory returns empty result")
}
minPoolMemory := params[0].Value
minPoolMemoryQuant, err := resource.ParseQuantity(minPoolMemory)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Parse quantity when checking and applying tenant '%s' pool and config", tenantName))
return errors.Wrapf(err, "Parse quantity when checking and applying tenant '%s' pool and config", tenantName)
}
for _, pool := range m.OBTenant.Spec.Pools {
unitName := m.generateUnitName(pool.Zone)
Expand Down Expand Up @@ -169,30 +168,27 @@ func MaintainUnitConfig(m *OBTenantManager) tasktypes.TaskError {
func DeleteTenant(m *OBTenantManager) tasktypes.TaskError {
var err error
tenantName := m.OBTenant.Spec.TenantName
m.Logger.Info("Delete Tenant", "tenantName", tenantName)
err = m.deleteTenant()
if err != nil {
return err
}
m.Logger.Info("Delete Pool", "tenantName", tenantName)
err = m.deletePool()
if err != nil {
return err
}
m.Logger.Info("Delete Unit", "tenantName", tenantName)
err = m.deleteUnitConfig()
if err != nil {
return err
}
m.Logger.Info("Delete Tenant Success", "tenantName", tenantName)
m.Logger.Info("Delete tenant successfully", "tenantName", tenantName)
return nil
}

func CheckAndApplyCharset(m *OBTenantManager) tasktypes.TaskError {
tenantName := m.OBTenant.Spec.TenantName
oceanbaseOperationManager, err := m.getClusterSysClient()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Get Sql Operator When Checking and Applying Tenant '%s' Charset ", tenantName))
return errors.Wrapf(err, "Get sql operator when checking and applying tenant '%s' charset ", tenantName)
}
specCharset := m.OBTenant.Spec.Charset
if specCharset == "" {
Expand Down Expand Up @@ -414,7 +410,7 @@ func CheckAndApplyUnitNum(m *OBTenantManager) tasktypes.TaskError {
tenantName := m.OBTenant.Spec.TenantName
oceanbaseOperationManager, err := m.getClusterSysClient()
if err != nil {
return errors.Wrap(err, fmt.Sprint("Get Sql Operator When Checking And Applying Tenant UnitNum", tenantName))
return errors.Wrapf(err, "Get sql operator when checking and applying unitnum of tenant %s", tenantName)
}

if m.OBTenant.Spec.UnitNumber != m.OBTenant.Status.TenantRecordInfo.UnitNumber {
Expand All @@ -430,7 +426,7 @@ func CheckAndApplyWhiteList(m *OBTenantManager) tasktypes.TaskError {
tenantName := m.OBTenant.Spec.TenantName
oceanbaseOperationManager, err := m.getClusterSysClient()
if err != nil {
return errors.Wrap(err, fmt.Sprint("Get Sql Operator When Checking And Applying ob_tcp_invited_nodes For Tenant ", tenantName))
return errors.Wrapf(err, "Get sql operator when checking and applying ob_tcp_invited_nodes for tenant %s", tenantName)
}

specWhiteList := m.OBTenant.Spec.ConnectWhiteList
Expand Down Expand Up @@ -458,7 +454,7 @@ func CheckAndApplyPrimaryZone(m *OBTenantManager) tasktypes.TaskError {
tenantName := m.OBTenant.Spec.TenantName
oceanbaseOperationManager, err := m.getClusterSysClient()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Get Sql Operator When Prcoessing Tenant '%s' Priority ", tenantName))
return errors.Wrapf(err, "Get sql operator when processing priority of tenant %s", tenantName)
}

specPrimaryZone := m.generateSpecPrimaryZone(m.OBTenant.Spec.Pools)
Expand All @@ -482,7 +478,7 @@ func CheckAndApplyLocality(m *OBTenantManager) tasktypes.TaskError {
tenantName := m.OBTenant.Spec.TenantName
oceanbaseOperationManager, err := m.getClusterSysClient()
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Get Sql Operator When Prcoessing Tenant '%s' Locality ", tenantName))
return errors.Wrapf(err, "Get sql operator when prcoessing tenant '%s' locality ", tenantName)
}
specLocalityMap := m.generateSpecLocalityMap(m.OBTenant.Spec.Pools)
statusLocalityMap := m.generateStatusLocalityMap(m.OBTenant.Status.Pools)
Expand All @@ -501,13 +497,13 @@ func CheckAndApplyLocality(m *OBTenantManager) tasktypes.TaskError {
check := func() (bool, error) {
exist, err := oceanbaseOperationManager.CheckRsJobExistByTenantID(m.Ctx, m.OBTenant.Status.TenantRecordInfo.TenantID)
if err != nil {
return false, errors.Wrap(err, fmt.Sprintf("Get RsJob %s", tenantName))
return false, errors.Wrapf(err, "Get RsJob %s", tenantName)
}
return !exist, nil
}
err = resourceutils.CheckJobWithTimeout(check)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Failed to wait for 'ALTER_TENANT' job of adding pool task to finish %s", tenantName))
return errors.Wrapf(err, "Failed to wait for 'ALTER_TENANT' job of adding pool task to finish %s", tenantName)
}
m.Logger.V(oceanbaseconst.LogLevelDebug).Info("'ALTER_TENANT' job of adding pool task succeeded", "tenantName", tenantName)
return nil
Expand Down
Loading
Loading