Skip to content

Commit 2238dd9

Browse files
committed
notification center additions
1 parent c54e5e8 commit 2238dd9

File tree

9 files changed

+96
-66
lines changed

9 files changed

+96
-66
lines changed

api/coralogix/v1alpha1/globalrouter_types.go

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

95100
var (
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

154168
func extractRoutingTargets(ctx context.Context, namespace string, targets []RoutingTarget) ([]globalrouters.RoutingTarget, error) {

api/coralogix/v1alpha1/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/coralogix-operator/templates/crds/coralogix.com_globalrouters.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ spec:
5757
description:
5858
description: Description is the description of the global router.
5959
type: string
60+
entityLabelMatcher:
61+
additionalProperties:
62+
type: string
63+
description: EntityLabelMatcher is an optional label matcher to filter
64+
entities for the global router.
65+
type: object
6066
entityLabels:
6167
additionalProperties:
6268
type: string
6369
description: EntityLabels are optional labels to attach to the global
6470
router.
6571
type: object
66-
entityType:
67-
description: EntityType is the entity type for the global router.
68-
Should equal "alerts".
69-
enum:
70-
- alerts
71-
type: string
7272
fallback:
7373
description: Fallback is the fallback routing target for the global
7474
router.
@@ -160,6 +160,11 @@ spec:
160160
description: CustomDetails are optional custom details to attach
161161
to the routing rule.
162162
type: object
163+
entityType:
164+
description: EntityType is the entity type for the global router.
165+
enum:
166+
- alerts
167+
type: string
163168
name:
164169
description: Name is the name of the routing rule.
165170
type: string
@@ -248,7 +253,6 @@ spec:
248253
type: array
249254
required:
250255
- description
251-
- entityType
252256
- name
253257
type: object
254258
status:

config/crd/bases/coralogix.com_globalrouters.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ spec:
5656
description:
5757
description: Description is the description of the global router.
5858
type: string
59+
entityLabelMatcher:
60+
additionalProperties:
61+
type: string
62+
description: EntityLabelMatcher is an optional label matcher to filter
63+
entities for the global router.
64+
type: object
5965
entityLabels:
6066
additionalProperties:
6167
type: string
6268
description: EntityLabels are optional labels to attach to the global
6369
router.
6470
type: object
65-
entityType:
66-
description: EntityType is the entity type for the global router.
67-
Should equal "alerts".
68-
enum:
69-
- alerts
70-
type: string
7171
fallback:
7272
description: Fallback is the fallback routing target for the global
7373
router.
@@ -159,6 +159,11 @@ spec:
159159
description: CustomDetails are optional custom details to attach
160160
to the routing rule.
161161
type: object
162+
entityType:
163+
description: EntityType is the entity type for the global router.
164+
enum:
165+
- alerts
166+
type: string
162167
name:
163168
description: Name is the name of the routing rule.
164169
type: string
@@ -247,7 +252,6 @@ spec:
247252
type: array
248253
required:
249254
- description
250-
- entityType
251255
- name
252256
type: object
253257
status:

config/samples/v1alpha1/globalrouters/example-router.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,8 @@ metadata:
1111
spec:
1212
name: global router
1313
description: global router example
14-
entityType: alerts
15-
fallback:
16-
- connector:
17-
resourceRef:
18-
name: slack-sample
19-
preset:
20-
backendRef:
21-
id: preset_system_slack_alerts_basic
14+
entityLabelMatcher:
15+
routing.group: global
2216
rules:
2317
- name: first-rule
2418
condition: "alertDef.priority == \"P1\""

docs/api.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10431,22 +10431,20 @@ GlobalRouterSpec defines the desired state of the Global Router.
1043110431
Description is the description of the global router.<br/>
1043210432
</td>
1043310433
<td>true</td>
10434-
</tr><tr>
10435-
<td><b>entityType</b></td>
10436-
<td>enum</td>
10437-
<td>
10438-
EntityType is the entity type for the global router. Should equal "alerts".<br/>
10439-
<br/>
10440-
<i>Enum</i>: alerts<br/>
10441-
</td>
10442-
<td>true</td>
1044310434
</tr><tr>
1044410435
<td><b>name</b></td>
1044510436
<td>string</td>
1044610437
<td>
1044710438
Name is the name of the global router.<br/>
1044810439
</td>
1044910440
<td>true</td>
10441+
</tr><tr>
10442+
<td><b>entityLabelMatcher</b></td>
10443+
<td>map[string]string</td>
10444+
<td>
10445+
EntityLabelMatcher is an optional label matcher to filter entities for the global router.<br/>
10446+
</td>
10447+
<td>false</td>
1045010448
</tr><tr>
1045110449
<td><b>entityLabels</b></td>
1045210450
<td>map[string]string</td>
@@ -10751,6 +10749,15 @@ ResourceRef is a reference to a Kubernetes resource.
1075110749
CustomDetails are optional custom details to attach to the routing rule.<br/>
1075210750
</td>
1075310751
<td>false</td>
10752+
</tr><tr>
10753+
<td><b>entityType</b></td>
10754+
<td>enum</td>
10755+
<td>
10756+
EntityType is the entity type for the global router.<br/>
10757+
<br/>
10758+
<i>Enum</i>: alerts<br/>
10759+
</td>
10760+
<td>false</td>
1075410761
</tr></tbody>
1075510762
</table>
1075610763

internal/controller/coralogix/v1alpha1/globalrouter_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ func (r *GlobalRouterReconciler) HandleCreation(ctx context.Context, log logr.Lo
6262
return fmt.Errorf("error on extracting create request: %w", err)
6363
}
6464

65-
replaceRequest := &globalrouters.ReplaceGlobalRouterRequest{
65+
createRequest := &globalrouters.CreateGlobalRouterRequest{
6666
Router: router,
6767
}
6868

69-
log.Info("Creating remote GlobalRouter", "GlobalRouter", utils.FormatJSON(replaceRequest))
69+
log.Info("Creating remote GlobalRouter", "GlobalRouter", utils.FormatJSON(createRequest))
7070
createResponse, httpResp, err := r.GlobalRoutersClient.
71-
GlobalRoutersServiceReplaceGlobalRouter(ctx).
72-
ReplaceGlobalRouterRequest(*replaceRequest).
71+
GlobalRoutersServiceCreateGlobalRouter(ctx).
72+
CreateGlobalRouterRequest(*createRequest).
7373
Execute()
7474
if err != nil {
7575
return fmt.Errorf("error on creating remote GlobalRouter: %w", cxsdk.NewAPIError(httpResp, err))
@@ -90,6 +90,7 @@ func (r *GlobalRouterReconciler) HandleUpdate(ctx context.Context, log logr.Logg
9090
return fmt.Errorf("error on extracting update request: %w", err)
9191
}
9292

93+
router.Id = globalRouter.Status.Id
9394
replaceRequest := &globalrouters.ReplaceGlobalRouterRequest{
9495
Router: router,
9596
}

tests/e2e/alert_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"fmt"
2020
"time"
2121

22+
gouuid "github.com/google/uuid"
2223
. "github.com/onsi/ginkgo/v2"
2324
. "github.com/onsi/gomega"
2425
"google.golang.org/grpc/codes"
@@ -60,7 +61,7 @@ var _ = Describe("Alert", Ordered, func() {
6061
Expect(crClient.Create(ctx, getSampleSlackPreset(presetName, testNamespace))).To(Succeed())
6162

6263
By("Creating GlobalRouter")
63-
globalRouterName := "global-router-for-alert"
64+
globalRouterName := "global-router-for-alert" + gouuid.NewString()
6465
globalRouter := getSampleGlobalRouter(globalRouterName, testNamespace, connectorName, presetName)
6566
Expect(crClient.Create(ctx, globalRouter)).To(Succeed())
6667

tests/e2e/global_router_test.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"time"
77

8+
gouuid "github.com/google/uuid"
89
. "github.com/onsi/ginkgo/v2"
910
. "github.com/onsi/gomega"
1011
"k8s.io/apimachinery/pkg/api/meta"
@@ -41,7 +42,7 @@ var _ = Describe("GlobalRouter", Ordered, func() {
4142
Expect(crClient.Create(ctx, getSampleSlackPreset(presetName, testNamespace))).To(Succeed())
4243

4344
By("Creating GlobalRouter")
44-
globalRouterName := "global-router-sample"
45+
globalRouterName := "global-router-sample" + gouuid.NewString()
4546
globalRouter = getSampleGlobalRouter(globalRouterName, testNamespace, connectorName, presetName)
4647
Expect(crClient.Create(ctx, globalRouter)).To(Succeed())
4748

@@ -100,22 +101,10 @@ func getSampleGlobalRouter(globalRouterName, testNamespace, slackConnectorName,
100101
Namespace: testNamespace,
101102
},
102103
Spec: coralogixv1alpha1.GlobalRouterSpec{
103-
Name: "global router",
104+
Name: globalRouterName,
104105
Description: "global router example",
105-
EntityType: "alerts",
106-
Fallback: []coralogixv1alpha1.RoutingTarget{
107-
{
108-
Connector: coralogixv1alpha1.NCRef{
109-
ResourceRef: &coralogixv1alpha1.ResourceRef{
110-
Name: slackConnectorName,
111-
},
112-
},
113-
Preset: &coralogixv1alpha1.NCRef{
114-
BackendRef: &coralogixv1alpha1.NCBackendRef{
115-
ID: "preset_system_slack_alerts_basic",
116-
},
117-
},
118-
},
106+
EntityLabelMatcher: &map[string]string{
107+
"routing.group": "production",
119108
},
120109
Rules: []coralogixv1alpha1.RoutingRule{
121110
{

0 commit comments

Comments
 (0)