Skip to content

Commit

Permalink
fix: Makefile typo & backup_policy delete logic
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI committed Sep 26, 2023
1 parent a354d0e commit 8be5c6c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,15 @@ commit-hook: $(GOLANGCI_LINT) ## Install commit hook.
.PHONY: connect
connect:
ifdef TENANT
mysq -h$(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}') -P2881 -A -uroot@${TENANT}
mysql -h$(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}') -P2881 -A -uroot@${TENANT}
else
mysql -h$(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}') -P2881 -A -uroot -p
endif

.PHONY: connectob
connectob:
ifdef TENANT
mysq -h$(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}') -P2881 -A -uroot@${TENANT} -Doceanbase
mysql -h$(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}') -P2881 -A -uroot@${TENANT} -Doceanbase
else
mysql -h$(shell kubectl get pods -o jsonpath='{.items[0].status.podIP}') -P2881 -A -uroot -p -Doceanbase
endif
47 changes: 41 additions & 6 deletions pkg/resource/obtenantbackuppolicy_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/pkg/errors"
"github.com/robfig/cron/v3"
corev1 "k8s.io/api/core/v1"
kubeerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/retry"
Expand Down Expand Up @@ -58,15 +59,35 @@ func (m *ObTenantBackupPolicyManager) IsDeleting() bool {
func (m *ObTenantBackupPolicyManager) CheckAndUpdateFinalizers() error {
policy := m.BackupPolicy
finalizerName := "obtenantbackuppolicy.finalizers.oceanbase.com"
finalizerFinished := false
if controllerutil.ContainsFinalizer(policy, finalizerName) {
err := m.StopBackup()
obcluster, err := m.getOBCluster()
if err != nil {
return err
if kubeerrors.IsNotFound(err) {
m.Logger.Info("OBCluster is deleted, no need to wait finalizer")
finalizerFinished = true
} else {
m.Logger.Error(err, "query obcluster failed")
return errors.Wrap(err, "Get obcluster failed")
}
} else if !obcluster.ObjectMeta.DeletionTimestamp.IsZero() {
m.Logger.Info("OBCluster is deleting, no need to wait finalizer")
finalizerFinished = true
}
// remove our finalizer from the list and update it.
controllerutil.RemoveFinalizer(policy, finalizerName)
if err := m.Client.Update(m.Ctx, policy); err != nil {
return err

if !finalizerFinished {
err := m.StopBackup()
if err != nil {
return err
}
finalizerFinished = true
}
if finalizerFinished {
// remove our finalizer from the list and update it.
controllerutil.RemoveFinalizer(policy, finalizerName)
if err := m.Client.Update(m.Ctx, policy); err != nil {
return err
}
}
}
return nil
Expand Down Expand Up @@ -260,3 +281,17 @@ func (m *ObTenantBackupPolicyManager) PrintErrEvent(err error) {
m.Logger.Error(err, "Print event")
m.Recorder.Event(m.BackupPolicy, corev1.EventTypeWarning, "task exec failed", err.Error())
}

func (m *ObTenantBackupPolicyManager) getOBCluster() (*v1alpha1.OBCluster, error) {
clusterName := m.BackupPolicy.Spec.ObClusterName
obcluster := &v1alpha1.OBCluster{}
err := m.Client.Get(m.Ctx, types.NamespacedName{
Namespace: m.BackupPolicy.Namespace,
Name: clusterName,
}, obcluster)
if err != nil {
m.Logger.Error(err, "get obcluster failed", "clusterName", clusterName, "namespaced", m.BackupPolicy.Namespace)
return nil, errors.Wrap(err, "get obcluster failed")
}
return obcluster, nil
}

0 comments on commit 8be5c6c

Please sign in to comment.