Skip to content

Commit 7144add

Browse files
author
Robin Sonefors
committed
Fix events view to take clusters into account
We should only get events for the current cluster - we used to search all clusters, and if another cluster had the same object then we'd show incorrect events. This makes the new, correct object ref kind introduced in #2765 the only object ref used in our APIs, and then copy-pastes the client creation code from c3a407a.
1 parent 3977758 commit 7144add

File tree

10 files changed

+401
-495
lines changed

10 files changed

+401
-495
lines changed

api/core/core.proto

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ message ListEventsResponse {
239239
}
240240

241241
message SyncFluxObjectRequest {
242-
repeated ClusteredObjRef objects = 1;
243-
bool withSource = 2;
242+
repeated ObjectRef objects = 1;
243+
bool withSource = 2;
244244
}
245245

246246
message SyncFluxObjectResponse {
@@ -264,8 +264,8 @@ message GetFeatureFlagsResponse {
264264
}
265265

266266
message ToggleSuspendResourceRequest {
267-
repeated ClusteredObjRef objects = 1;
268-
bool suspend = 2;
267+
repeated ObjectRef objects = 1;
268+
bool suspend = 2;
269269
}
270270

271271
message ToggleSuspendResourceResponse {

api/core/core.swagger.json

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
"in": "query",
8787
"required": false,
8888
"type": "string"
89+
},
90+
{
91+
"name": "involvedObject.clusterName",
92+
"in": "query",
93+
"required": false,
94+
"type": "string"
8995
}
9096
],
9197
"tags": [
@@ -493,23 +499,6 @@
493499
}
494500
}
495501
},
496-
"v1ClusteredObjRef": {
497-
"type": "object",
498-
"properties": {
499-
"kind": {
500-
"type": "string"
501-
},
502-
"name": {
503-
"type": "string"
504-
},
505-
"namespace": {
506-
"type": "string"
507-
},
508-
"clusterName": {
509-
"type": "string"
510-
}
511-
}
512-
},
513502
"v1Condition": {
514503
"type": "object",
515504
"properties": {
@@ -888,6 +877,9 @@
888877
},
889878
"namespace": {
890879
"type": "string"
880+
},
881+
"clusterName": {
882+
"type": "string"
891883
}
892884
}
893885
},
@@ -897,7 +889,7 @@
897889
"objects": {
898890
"type": "array",
899891
"items": {
900-
"$ref": "#/definitions/v1ClusteredObjRef"
892+
"$ref": "#/definitions/v1ObjectRef"
901893
}
902894
},
903895
"withSource": {
@@ -914,7 +906,7 @@
914906
"objects": {
915907
"type": "array",
916908
"items": {
917-
"$ref": "#/definitions/v1ClusteredObjRef"
909+
"$ref": "#/definitions/v1ObjectRef"
918910
}
919911
},
920912
"suspend": {

api/core/types.proto

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ message ObjectRef {
3232
string kind = 1;
3333
string name = 2;
3434
string namespace = 3;
35-
}
36-
37-
message ClusteredObjRef {
38-
string kind = 1;
39-
string name = 2;
40-
string namespace = 3;
4135
string clusterName = 4;
4236
}
4337

core/server/events.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@ import (
1616
)
1717

1818
func (cs *coreServer) ListEvents(ctx context.Context, msg *pb.ListEventsRequest) (*pb.ListEventsResponse, error) {
19-
k8s, err := cs.clustersManager.GetImpersonatedClient(ctx, auth.Principal(ctx))
20-
if err != nil {
21-
return nil, doClientError(err)
22-
}
19+
var clustersClient clustersmngr.Client
20+
var err error
2321

2422
if msg.InvolvedObject == nil {
2523
return nil, status.Errorf(codes.InvalidArgument, "bad request: no object was specified")
2624
}
2725

26+
if msg.InvolvedObject.ClusterName != "" {
27+
clustersClient, err = cs.clustersManager.GetImpersonatedClientForCluster(ctx, auth.Principal(ctx), msg.InvolvedObject.ClusterName)
28+
} else {
29+
clustersClient, err = cs.clustersManager.GetImpersonatedClient(ctx, auth.Principal(ctx))
30+
}
31+
32+
if err != nil {
33+
return nil, doClientError(err)
34+
}
35+
2836
clist := clustersmngr.NewClusteredList(func() client.ObjectList {
2937
return &corev1.EventList{}
3038
})
@@ -42,7 +50,7 @@ func (cs *coreServer) ListEvents(ctx context.Context, msg *pb.ListEventsRequest)
4250
"involvedObject.namespace": msg.InvolvedObject.Namespace,
4351
}
4452

45-
if err := list(ctx, k8s, temporarilyEmptyAppName, msg.InvolvedObject.Namespace, clist, fields); err != nil {
53+
if err := list(ctx, clustersClient, temporarilyEmptyAppName, msg.InvolvedObject.Namespace, clist, fields); err != nil {
4654
return nil, fmt.Errorf("could not get events: %w", err)
4755
}
4856

pkg/api/core/core.pb.go

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

0 commit comments

Comments
 (0)