Skip to content

Commit

Permalink
fix: panic on invalid bridge config
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 8, 2024
1 parent ffc3f28 commit f6acd93
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
4 changes: 2 additions & 2 deletions api/telemetry/v1alpha1/collector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ func (c CollectorSpec) GetMemoryLimit() *resource.Quantity {

// CollectorStatus defines the observed state of Collector
type CollectorStatus struct {
State State `json:"state,omitempty"`
Tenants []string `json:"tenants,omitempty"`
State State `json:"state,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:resource:scope=Cluster,categories=telemetry-all
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`
//+kubebuilder:printcolumn:name="Tenants",type=string,JSONPath=`.status.tenants`
//+kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.state`

// Collector is the Schema for the collectors API
type Collector struct {
Expand Down
34 changes: 14 additions & 20 deletions internal/controller/telemetry/route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,26 +475,20 @@ func (r *RouteReconciler) getTenants(ctx context.Context, listOpts *client.ListO
}

func (r *RouteReconciler) checkBridgeConnections(ctx context.Context, bridge *v1alpha1.Bridge) error {
listOpts := &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(tenantNameField, bridge.Spec.SourceTenant),
}
sourceTenant, err := r.getTenants(ctx, listOpts)
if err != nil {
return err
}
if len(sourceTenant) != 1 && sourceTenant[0].Name != bridge.Spec.SourceTenant {
return errors.Errorf("bridge (%s) has invalid source tenant", bridge.Name)
}

listOpts = &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(tenantNameField, bridge.Spec.TargetTenant),
}
targetTenant, err := r.getTenants(ctx, listOpts)
if err != nil {
return err
}
if len(targetTenant) != 1 && targetTenant[0].Name != bridge.Spec.TargetTenant {
return errors.Errorf("bridge (%s) has invalid target tenant", bridge.Name)
for _, tenant := range []string{bridge.Spec.SourceTenant, bridge.Spec.TargetTenant} {
listOpts := &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(tenantNameField, tenant),
}
tenants, err := r.getTenants(ctx, listOpts)
if err != nil {
return err
}
if len(tenants) == 0 {
return errors.Errorf("tenant: %s not found for bridge: %s", tenant, bridge.Name)
}
if len(tenants) != 1 || tenants[0].Name != tenant {
return errors.Errorf("bridge: %s has invalid tenant reference: %s", bridge.Name, tenant)
}
}

return nil
Expand Down

0 comments on commit f6acd93

Please sign in to comment.