Skip to content

Commit

Permalink
refactor: route-reconciler
Browse files Browse the repository at this point in the history
Signed-off-by: Bence Csati <bence.csati@axoflow.com>
  • Loading branch information
csatib02 committed Oct 22, 2024
1 parent 6e2b77d commit 4210a35
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions internal/controller/telemetry/route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func (r *RouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
logger := log.FromContext(ctx)

tenant := &v1alpha1.Tenant{}

logger.Info(fmt.Sprintf("getting tenant: %q", req.NamespacedName.Name))

if err := r.Get(ctx, req.NamespacedName, tenant); client.IgnoreNotFound(err) != nil {
Expand All @@ -66,13 +65,11 @@ func (r *RouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
return ctrl.Result{}, err
}

logger.Info(fmt.Sprintf("reconciling tenant: %q", tenant.Name))

originalTenantStatus := tenant.Status
logger.Info(fmt.Sprintf("reconciling tenant: %q", tenant.Name))

subscriptionsForTenant, updateList, err := r.getSubscriptionsForTenant(ctx, tenant)
if err != nil {

tenant.Status.State = v1alpha1.TenantState(v1alpha1.StateFailed)

Check failure on line 73 in internal/controller/telemetry/route_controller.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary conversion (unconvert)
logger.Error(errors.WithStack(err), "failed to get subscriptions for tenant", "tenant", tenant.Name)
if updateErr := r.Status().Update(ctx, tenant); updateErr != nil {
Expand All @@ -84,17 +81,13 @@ func (r *RouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl

// add all newly updated subscriptions here
subscriptionsForTenant = append(subscriptionsForTenant, r.updateSubscriptionsForTenant(ctx, tenant.Name, updateList)...)

subscriptionsToDisown := r.getSubscriptionsReferencingTenantButNotSelected(ctx, tenant, subscriptionsForTenant)

r.disownSubscriptions(ctx, subscriptionsToDisown)

subscriptionNames := getSubscriptionNamesFromSubscription(subscriptionsForTenant)

cmp := func(a, b v1alpha1.NamespacedName) int {
return strings.Compare(a.String(), b.String())
}

slices.SortFunc(subscriptionNames, cmp)
tenant.Status.Subscriptions = subscriptionNames

Expand Down Expand Up @@ -130,12 +123,10 @@ func (r *RouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
}
return ctrl.Result{}, err
}

slices.Sort(logsourceNamespacesForTenant)
tenant.Status.LogSourceNamespaces = logsourceNamespacesForTenant

tenant.Status.State = v1alpha1.TenantState(v1alpha1.StateReady)

Check failure on line 129 in internal/controller/telemetry/route_controller.go

View workflow job for this annotation

GitHub Actions / Lint

unnecessary conversion (unconvert)

if !reflect.DeepEqual(originalTenantStatus, tenant.Status) {
logger.Info("tenant status changed")
if err := r.Status().Update(ctx, tenant); err != nil {
Expand Down

0 comments on commit 4210a35

Please sign in to comment.