forked from kumahq/kuma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(meshservices): api for listing matching DPPs (kumahq#11850)
## Motivation We want to list matching DPPs in the UI ## Implementation information We already had a code for it for policies. In the case of MeshServices, the matching is different. I extracted "boilerplate" of parsing, marshaling request and validating the access to "generic function", so won't duplicate the logic and whether we have a change it matches both. When it comes to OAPI, we already have a definition for it https://github.com/kumahq/kuma/blob/2adb7f53026f3ab38f5967b21f507e6674ce893d/api/openapi/specs/api.yaml#L122 not sure we can do anything more here ## Supporting documentation Fix kumahq#10244 Signed-off-by: Jakub Dyszkiewicz <jakub.dyszkiewicz@gmail.com>
- Loading branch information
1 parent
b0fc6be
commit e02c7b4
Showing
6 changed files
with
211 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package api_server | ||
|
||
import ( | ||
"github.com/emicklei/go-restful/v3" | ||
|
||
"github.com/kumahq/kuma/pkg/core/resources/access" | ||
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh" | ||
"github.com/kumahq/kuma/pkg/core/resources/apis/meshservice" | ||
meshservice_api "github.com/kumahq/kuma/pkg/core/resources/apis/meshservice/api/v1alpha1" | ||
"github.com/kumahq/kuma/pkg/core/resources/manager" | ||
"github.com/kumahq/kuma/pkg/core/resources/model" | ||
"github.com/kumahq/kuma/pkg/core/resources/store" | ||
) | ||
|
||
func addInspectMeshServiceEndpoints( | ||
ws *restful.WebService, | ||
rm manager.ResourceManager, | ||
resourceAccess access.ResourceAccess, | ||
) { | ||
ws.Route( | ||
ws.GET("/meshes/{mesh}/meshservices/{name}/_resources/dataplanes"). | ||
To(matchingDataplanesForMeshServices(rm, resourceAccess)). | ||
Doc("inspect dataplane configuration and stats"). | ||
Param(ws.PathParameter("name", "mesh service name").DataType("string")). | ||
Param(ws.PathParameter("mesh", "mesh name").DataType("string")), | ||
) | ||
} | ||
|
||
func matchingDataplanesForMeshServices(resManager manager.ResourceManager, resourceAccess access.ResourceAccess) restful.RouteFunction { | ||
return func(request *restful.Request, response *restful.Response) { | ||
matchingDataplanesForFilter( | ||
request, | ||
response, | ||
meshservice_api.MeshServiceResourceTypeDescriptor, | ||
resManager, | ||
resourceAccess, | ||
func(resource model.Resource) store.ListFilterFunc { | ||
meshService := resource.(*meshservice_api.MeshServiceResource) | ||
return func(rs model.Resource) bool { | ||
return meshservice.MatchesDataplane(meshService.Spec, rs.(*core_mesh.DataplaneResource)) | ||
} | ||
}, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...-server/testdata/resources/inspect/policies/_resources/dataplanes/meshservice.golden.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"items": [ | ||
{ | ||
"labels": {}, | ||
"mesh": "default", | ||
"name": "ts-01", | ||
"type": "Dataplane" | ||
}, | ||
{ | ||
"labels": {}, | ||
"mesh": "default", | ||
"name": "ts-02", | ||
"type": "Dataplane" | ||
} | ||
], | ||
"total": 2 | ||
} |
49 changes: 49 additions & 0 deletions
49
...i-server/testdata/resources/inspect/policies/_resources/dataplanes/meshservice.input.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#/meshes/default/meshservices/test-server/_resources/dataplanes 200 | ||
type: Mesh | ||
name: default | ||
--- | ||
type: MeshService | ||
name: test-server | ||
mesh: default | ||
labels: | ||
kuma.io/origin: zone | ||
kuma.io/env: universal | ||
spec: | ||
selector: | ||
dataplaneTags: | ||
kuma.io/service: test-server | ||
ports: | ||
- port: 80 | ||
targetPort: 80 | ||
appProtocol: http | ||
name: main-port | ||
--- | ||
type: Dataplane | ||
name: ts-01 | ||
mesh: default | ||
networking: | ||
address: 127.0.0.1 | ||
inbound: | ||
- port: 80 | ||
tags: | ||
kuma.io/service: test-server | ||
--- | ||
type: Dataplane | ||
name: ts-02 | ||
mesh: default | ||
networking: | ||
address: 127.0.0.2 | ||
inbound: | ||
- port: 80 | ||
tags: | ||
kuma.io/service: test-server | ||
--- | ||
type: Dataplane | ||
name: not-ts-01 | ||
mesh: default | ||
networking: | ||
address: 127.0.0.2 | ||
inbound: | ||
- port: 80 | ||
tags: | ||
kuma.io/service: not-test-server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters