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

Add resource labels; Coordinate when sub-resource changes #212

Merged
merged 6 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions api/v1alpha1/obtenant_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/obtenantbackuppolicy_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
})
Expand Down
8 changes: 8 additions & 0 deletions api/v1alpha1/obtenantoperation_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand All @@ -90,6 +95,7 @@ func (r *OBTenantOperation) Default() {
Name: firstMeta.GetName(),
UID: firstMeta.GetUID(),
})
labels[oceanbaseconst.LabelTenantName] = firstMeta.GetName()
}

if secondaryTenantName != "" {
Expand All @@ -109,9 +115,11 @@ func (r *OBTenantOperation) Default() {
Name: secondMeta.GetName(),
UID: secondMeta.GetUID(),
})
labels[oceanbaseconst.LabelSecondaryTenant] = secondMeta.GetName()
}

r.SetOwnerReferences(references)
r.SetLabels(labels)
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
Expand Down
5 changes: 3 additions & 2 deletions internal/const/oceanbase/oceanbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ const (
)

const (
LabelTenantName = "oceanbase.oceanbase.com/tenant-name"
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 (
Expand Down
1 change: 1 addition & 0 deletions internal/controller/obcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}).
WithEventFilter(preds).
Complete(r)
}
1 change: 1 addition & 0 deletions internal/controller/obzone_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading