Skip to content

Commit

Permalink
fix: report correct tenant state on bridge failure
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 Nov 12, 2024
1 parent 14bf7f4 commit cfbd86b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/controller/telemetry/collector_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (r *CollectorReconciler) buildConfigInputForCollector(ctx context.Context,

for _, tenant := range tenants {
if tenant.Status.State == v1alpha1.StateFailed {
logger.Info("tenant %q is in failed state, retrying later", tenant.Name)
logger.Info(fmt.Sprintf("tenant %q is in failed state, retrying later", tenant.Name))
return otelcolconfgen.OtelColConfigInput{}, ErrTenantFailed
}

Expand Down Expand Up @@ -196,6 +196,11 @@ func (r *CollectorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}

if err := otelConfigInput.ValidateConfig(); err != nil {
if errors.Is(err, otelcolconfgen.ErrNoResources) {
logger.Info(err.Error())
return ctrl.Result{}, nil
}

collector.Status.State = v1alpha1.StateFailed
logger.Error(errors.WithStack(err), "invalid otel config input")
return ctrl.Result{}, err
Expand Down
40 changes: 40 additions & 0 deletions internal/controller/telemetry/route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ func (r *RouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
sort.Strings(bridgesForTenantNames)
tenant.Status.ConnectedBridges = bridgesForTenantNames

for _, bridge := range bridgesForTenant {
if err := r.checkBridgeConnection(ctx, tenant.Name, &bridge); err != nil {
tenant.Status.State = v1alpha1.StateFailed
logger.Error(errors.WithStack(err), "failed to check bridge connection", "bridge", bridge.Name)
if updateErr := r.Status().Update(ctx, tenant); updateErr != nil {
logger.Error(errors.WithStack(updateErr), "failed update tenant status", "tenant", tenant.Name)
return ctrl.Result{}, err
}
return ctrl.Result{}, err
}
}

logsourceNamespacesForTenant, err := r.getLogsourceNamespaceNamesForTenant(ctx, tenant)
if err != nil {
tenant.Status.State = v1alpha1.StateFailed
Expand Down Expand Up @@ -452,6 +464,34 @@ func (r *RouteReconciler) getBridgesForTenant(ctx context.Context, tenantName st
return
}

func (r *RouteReconciler) getTenants(ctx context.Context, listOpts *client.ListOptions) ([]v1alpha1.Tenant, error) {
var tenants v1alpha1.TenantList
if err := r.Client.List(ctx, &tenants, listOpts); client.IgnoreNotFound(err) != nil {
return nil, err
}

return tenants.Items, nil
}

func (r *RouteReconciler) checkBridgeConnection(ctx context.Context, tenantName string, bridge *v1alpha1.Bridge) error {
for _, tenant := range []string{bridge.Spec.SourceTenant, bridge.Spec.TargetTenant} {
if tenant != tenantName {
listOpts := &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(tenantNameField, tenant),
}
tenant, err := r.getTenants(ctx, listOpts)
if err != nil {
return err
}
if len(tenant) == 0 {
return errors.Errorf("bridge %s has a dangling tenant reference %s", bridge.Name, tenant)
}
}
}

return nil
}

func normalizeNamespaceSlice(inputList []apiv1.Namespace) []apiv1.Namespace {
allKeys := make(map[string]bool)
uniqueList := []apiv1.Namespace{}
Expand Down

0 comments on commit cfbd86b

Please sign in to comment.