Skip to content

Commit

Permalink
fix(finalizer): collect finalizers into oceanbase const
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed May 7, 2024
1 parent 11db158 commit e889031
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (m *ObTenantBackupPolicyManager) GetStatus() string {

func (m *ObTenantBackupPolicyManager) CheckAndUpdateFinalizers() error {
policy := m.BackupPolicy
finalizerName := "obtenantbackuppolicy.finalizers.oceanbase.com"
finalizerName := oceanbaseconst.FinalizerBackupPolicy
finalizerFinished := false
if controllerutil.ContainsFinalizer(policy, finalizerName) {
obcluster, err := m.getOBCluster()
Expand Down
2 changes: 1 addition & 1 deletion internal/resource/obzone/obzone_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func CreateOBServer(m *OBZoneManager) tasktypes.TaskError {
migrateAnnoVal, migrateAnnoExist := resourceutils.GetAnnotationField(m.OBZone, oceanbaseconst.AnnotationsSourceClusterAddress)
for i := currentReplica; i < m.OBZone.Spec.Topology.Replica; i++ {
serverName := m.generateServerName()
finalizerName := "finalizers.oceanbase.com.deleteobserver"
finalizerName := oceanbaseconst.FinalizerDeleteOBServer
finalizers := []string{finalizerName}
labels := make(map[string]string)
cluster, _ := m.OBZone.Labels[oceanbaseconst.LabelRefOBCluster]
Expand Down

0 comments on commit e889031

Please sign in to comment.