@@ -36,14 +36,14 @@ type GlobalRouterSpec struct {
3636 // Description is the description of the global router.
3737 Description string `json:"description"`
3838
39- // EntityType is the entity type for the global router. Should equal "alerts".
40- // +kubebuilder:validation:Enum=alerts
41- EntityType string `json:"entityType"`
42-
4339 // EntityLabels are optional labels to attach to the global router.
4440 // +optional
4541 EntityLabels map [string ]string `json:"entityLabels,omitempty"`
4642
43+ // EntityLabelMatcher is an optional label matcher to filter entities for the global router.
44+ // +optional
45+ EntityLabelMatcher * map [string ]string `json:"entityLabelMatcher,omitempty"`
46+
4747 // Fallback is the fallback routing target for the global router.
4848 // +optional
4949 Fallback []RoutingTarget `json:"fallback,omitempty"`
@@ -57,6 +57,11 @@ type RoutingRule struct {
5757 // Name is the name of the routing rule.
5858 Name string `json:"name"`
5959
60+ // EntityType is the entity type for the global router.
61+ // +kubebuilder:validation:Enum=alerts
62+ // +optional
63+ EntityType * string `json:"entityType,omitempty"`
64+
6065 // CustomDetails are optional custom details to attach to the routing rule.
6166 // +optional
6267 CustomDetails map [string ]string `json:"customDetails,omitempty"`
@@ -93,7 +98,7 @@ type NCRef struct {
9398}
9499
95100var (
96- schemaToOpenApiRoutersEntityType = map [string ]globalrouters.NotificationCenterEntityType {
101+ EntityTypeSchemaToOpenAPI = map [string ]globalrouters.NotificationCenterEntityType {
97102 "alerts" : globalrouters .NOTIFICATIONCENTERENTITYTYPE_ALERTS ,
98103 }
99104)
@@ -110,12 +115,11 @@ func (g *GlobalRouter) ExtractGlobalRouter(ctx context.Context) (*globalrouters.
110115 }
111116
112117 return & globalrouters.GlobalRouter {
113- Id : ptr .To ("router_default" ),
114- EntityType : schemaToOpenApiRoutersEntityType [g .Spec .EntityType ].Ptr (),
115- Name : globalrouters .PtrString (g .Spec .Name ),
116- Description : globalrouters .PtrString (g .Spec .Description ),
117- Fallback : fallback ,
118- Rules : rules ,
118+ Name : globalrouters .PtrString (g .Spec .Name ),
119+ Description : globalrouters .PtrString (g .Spec .Description ),
120+ EntityLabelMatcher : g .Spec .EntityLabelMatcher ,
121+ Fallback : fallback ,
122+ Rules : rules ,
119123 }, nil
120124}
121125
@@ -144,11 +148,21 @@ func extractRoutingRule(ctx context.Context, namespace string, rule RoutingRule)
144148 return nil , err
145149 }
146150
147- return & globalrouters.RoutingRule {
148- Name : ptr . To (rule .Name ),
151+ routingRule := & globalrouters.RoutingRule {
152+ Name : globalrouters . PtrString (rule .Name ),
149153 Condition : globalrouters .PtrString (rule .Condition ),
150154 Targets : targets ,
151- }, nil
155+ }
156+
157+ if rule .EntityType != nil {
158+ entityType , ok := EntityTypeSchemaToOpenAPI [* rule .EntityType ]
159+ if ! ok {
160+ return nil , fmt .Errorf ("invalid entity type: %s" , * rule .EntityType )
161+ }
162+ routingRule .EntityType = entityType .Ptr ()
163+ }
164+
165+ return routingRule , nil
152166}
153167
154168func extractRoutingTargets (ctx context.Context , namespace string , targets []RoutingTarget ) ([]globalrouters.RoutingTarget , error ) {
0 commit comments