From f40da3e1e95133b5620796c1518ca05c4ac7cce3 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 22 Feb 2024 10:03:20 +0800 Subject: [PATCH 1/6] fix(operation): add labels when creating obtenant operations --- api/v1alpha1/obtenantbackuppolicy_webhook.go | 2 +- api/v1alpha1/obtenantoperation_webhook.go | 8 ++++++++ internal/const/oceanbase/oceanbase.go | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/api/v1alpha1/obtenantbackuppolicy_webhook.go b/api/v1alpha1/obtenantbackuppolicy_webhook.go index 9db2dda91..f86691987 100644 --- a/api/v1alpha1/obtenantbackuppolicy_webhook.go +++ b/api/v1alpha1/obtenantbackuppolicy_webhook.go @@ -111,7 +111,7 @@ func (r *OBTenantBackupPolicy) Default() { }}) r.SetLabels(map[string]string{ - oceanbaseconst.LabelTenantName: r.Spec.TenantName, + oceanbaseconst.LabelTenantName: r.Spec.TenantCRName, oceanbaseconst.LabelRefOBCluster: r.Spec.ObClusterName, oceanbaseconst.LabelRefUID: string(tenant.GetObjectMeta().GetUID()), }) diff --git a/api/v1alpha1/obtenantoperation_webhook.go b/api/v1alpha1/obtenantoperation_webhook.go index 373e69b7f..25a3a04f1 100644 --- a/api/v1alpha1/obtenantoperation_webhook.go +++ b/api/v1alpha1/obtenantoperation_webhook.go @@ -36,6 +36,7 @@ import ( "github.com/oceanbase/ob-operator/api/constants" apitypes "github.com/oceanbase/ob-operator/api/types" + oceanbaseconst "github.com/oceanbase/ob-operator/internal/const/oceanbase" ) // log is for logging in this package. @@ -73,6 +74,10 @@ func (r *OBTenantOperation) Default() { targetTenantName = *r.Spec.TargetTenant } references := r.GetOwnerReferences() + labels := r.GetLabels() + if labels == nil { + labels = make(map[string]string) + } if targetTenantName != "" { err := clt.Get(context.Background(), types.NamespacedName{ @@ -90,6 +95,7 @@ func (r *OBTenantOperation) Default() { Name: firstMeta.GetName(), UID: firstMeta.GetUID(), }) + labels[oceanbaseconst.LabelTenantName] = firstMeta.GetName() } if secondaryTenantName != "" { @@ -109,9 +115,11 @@ func (r *OBTenantOperation) Default() { Name: secondMeta.GetName(), UID: secondMeta.GetUID(), }) + labels[oceanbaseconst.LabelSecondTenant] = secondMeta.GetName() } r.SetOwnerReferences(references) + r.SetLabels(labels) } // TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation. diff --git a/internal/const/oceanbase/oceanbase.go b/internal/const/oceanbase/oceanbase.go index e97dcd380..57e128f72 100644 --- a/internal/const/oceanbase/oceanbase.go +++ b/internal/const/oceanbase/oceanbase.go @@ -144,8 +144,9 @@ const ( ) const ( - LabelTenantName = "oceanbase.oceanbase.com/tenant-name" - LabelBackupType = "oceanbase.oceanbase.com/backup-type" + LabelTenantName = "oceanbase.oceanbase.com/tenant-name" + LabelSecondTenant = "oceanbase.oceanbase.com/second-tenant" + LabelBackupType = "oceanbase.oceanbase.com/backup-type" ) const ( From 6228c1b67bff89fb49f5f20efd7721f4a3ec8e9e Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 22 Feb 2024 16:13:18 +0800 Subject: [PATCH 2/6] fix(tenant): add ref-obcluster label when creating tenant --- api/v1alpha1/obtenant_webhook.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/v1alpha1/obtenant_webhook.go b/api/v1alpha1/obtenant_webhook.go index 16165f96e..1906efbdf 100644 --- a/api/v1alpha1/obtenant_webhook.go +++ b/api/v1alpha1/obtenant_webhook.go @@ -66,12 +66,19 @@ func (r *OBTenant) Default() { if err != nil { tenantlog.Error(err, "Failed to get cluster") } else { + clusterMeta := cluster.GetObjectMeta() r.SetOwnerReferences([]metav1.OwnerReference{{ APIVersion: cluster.APIVersion, Kind: cluster.Kind, - Name: cluster.GetObjectMeta().GetName(), - UID: cluster.GetObjectMeta().GetUID(), + Name: clusterMeta.GetName(), + UID: clusterMeta.GetUID(), }}) + labels := r.GetLabels() + if labels == nil { + labels = make(map[string]string) + } + labels[oceanbaseconst.LabelRefOBCluster] = clusterMeta.GetName() + r.SetLabels(labels) } if r.Spec.TenantRole == "" { From 13a1d18e826c05c5e99d54b91853227aa115b080 Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 26 Feb 2024 19:59:45 +0800 Subject: [PATCH 3/6] fix(ctrl): #199 add Owns for OBCluster and OBZone controller to accelerate reconciling --- internal/controller/obcluster_controller.go | 1 + internal/controller/obzone_controller.go | 1 + 2 files changed, 2 insertions(+) diff --git a/internal/controller/obcluster_controller.go b/internal/controller/obcluster_controller.go index dbe2ca88f..c41cdd5d8 100644 --- a/internal/controller/obcluster_controller.go +++ b/internal/controller/obcluster_controller.go @@ -97,6 +97,7 @@ func (r *OBClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( func (r *OBClusterReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&v1alpha1.OBCluster{}). + Owns(&v1alpha1.OBZone{}).Owns(&v1alpha1.OBParameter{}). WithEventFilter(preds). Complete(r) } diff --git a/internal/controller/obzone_controller.go b/internal/controller/obzone_controller.go index 60e639d74..9d959814c 100644 --- a/internal/controller/obzone_controller.go +++ b/internal/controller/obzone_controller.go @@ -87,6 +87,7 @@ func (r *OBZoneReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr func (r *OBZoneReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&v1alpha1.OBZone{}). + Owns(&v1alpha1.OBServer{}). WithEventFilter(preds). Complete(r) } From ac508597b244d4193bfc3c509ae6431fbd4b63d0 Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 27 Feb 2024 19:05:14 +0800 Subject: [PATCH 4/6] fix(backup): backup policy cannot be deleted in paused status --- .../obtenantbackuppolicy/obtenantbackuppolicy_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/resource/obtenantbackuppolicy/obtenantbackuppolicy_manager.go b/internal/resource/obtenantbackuppolicy/obtenantbackuppolicy_manager.go index eb44a8dff..f2a7eadcb 100644 --- a/internal/resource/obtenantbackuppolicy/obtenantbackuppolicy_manager.go +++ b/internal/resource/obtenantbackuppolicy/obtenantbackuppolicy_manager.go @@ -168,7 +168,7 @@ func (m *ObTenantBackupPolicyManager) UpdateStatus() error { m.BackupPolicy.Status.OperationContext = nil } else if !m.BackupPolicy.Spec.Suspend && m.BackupPolicy.Status.Status == constants.BackupPolicyStatusPaused { m.BackupPolicy.Status.Status = constants.BackupPolicyStatusResuming - } else if m.IsDeleting() && m.BackupPolicy.Status.Status == constants.BackupPolicyStatusRunning { + } else if m.IsDeleting() && (m.BackupPolicy.Status.Status == constants.BackupPolicyStatusRunning || m.BackupPolicy.Status.Status == constants.BackupPolicyStatusPaused) { m.BackupPolicy.Status.Status = constants.BackupPolicyStatusDeleting m.BackupPolicy.Status.OperationContext = nil } else if m.BackupPolicy.Status.Status == constants.BackupPolicyStatusRunning { From f192ecbf8cbb01d1c651bf2e08c66b8fe020c9a6 Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 28 Feb 2024 20:11:42 +0800 Subject: [PATCH 5/6] fix(ctrl): remove owns(obparameter) in obcluster controller --- internal/controller/obcluster_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/controller/obcluster_controller.go b/internal/controller/obcluster_controller.go index c41cdd5d8..cc2f3772c 100644 --- a/internal/controller/obcluster_controller.go +++ b/internal/controller/obcluster_controller.go @@ -97,7 +97,7 @@ func (r *OBClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( func (r *OBClusterReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). For(&v1alpha1.OBCluster{}). - Owns(&v1alpha1.OBZone{}).Owns(&v1alpha1.OBParameter{}). + Owns(&v1alpha1.OBZone{}). WithEventFilter(preds). Complete(r) } From a0c096a7be4cce9300033687fed0c4803c4f55e6 Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 28 Feb 2024 20:22:22 +0800 Subject: [PATCH 6/6] fix(naming): label second-tenant --> secondary-tenant --- api/v1alpha1/obtenantoperation_webhook.go | 2 +- internal/const/oceanbase/oceanbase.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/v1alpha1/obtenantoperation_webhook.go b/api/v1alpha1/obtenantoperation_webhook.go index 25a3a04f1..78554cd22 100644 --- a/api/v1alpha1/obtenantoperation_webhook.go +++ b/api/v1alpha1/obtenantoperation_webhook.go @@ -115,7 +115,7 @@ func (r *OBTenantOperation) Default() { Name: secondMeta.GetName(), UID: secondMeta.GetUID(), }) - labels[oceanbaseconst.LabelSecondTenant] = secondMeta.GetName() + labels[oceanbaseconst.LabelSecondaryTenant] = secondMeta.GetName() } r.SetOwnerReferences(references) diff --git a/internal/const/oceanbase/oceanbase.go b/internal/const/oceanbase/oceanbase.go index 57e128f72..8411d8229 100644 --- a/internal/const/oceanbase/oceanbase.go +++ b/internal/const/oceanbase/oceanbase.go @@ -144,9 +144,9 @@ const ( ) const ( - LabelTenantName = "oceanbase.oceanbase.com/tenant-name" - LabelSecondTenant = "oceanbase.oceanbase.com/second-tenant" - LabelBackupType = "oceanbase.oceanbase.com/backup-type" + LabelTenantName = "oceanbase.oceanbase.com/tenant-name" + LabelSecondaryTenant = "oceanbase.oceanbase.com/secondary-tenant" + LabelBackupType = "oceanbase.oceanbase.com/backup-type" ) const (