Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend CustomBoard with filters #484

Merged
merged 1 commit into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion backend/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,21 @@ type Boards struct {
AccessControl AccessControl `koanf:"accessControl"`
}

type Filter struct {
NamespaceKinds []string `koanf:"namespaceKinds"`
ClusterKinds []string `koanf:"clusterKinds"`
Results []string `koanf:"results"`
Severities []string `koanf:"severities"`
}

type CustomBoard struct {
Name string `koanf:"name"`
AccessControl AccessControl `koanf:"accessControl"`
Namespaces struct {
Filter struct {
Include Filter `koanf:"include"`
} `koanf:"filter"`
Display string `json:"display"`
Namespaces struct {
Selector map[string]string `koanf:"selector"`
List []string `koanf:"list"`
} `koanf:"namespaces"`
Expand Down
28 changes: 26 additions & 2 deletions backend/pkg/config/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ func MapCustomBoards(customBoards []CustomBoard) map[string]api.CustomBoard {
id := slug.Make(c.Name)

configs[id] = api.CustomBoard{
Name: c.Name,
ID: id,
Name: c.Name,
ID: id,
Display: c.Display,
Filter: MapFilter(c.Filter.Include),
Namespaces: api.Namespaces{
Selector: c.Namespaces.Selector,
List: c.Namespaces.List,
Expand Down Expand Up @@ -105,3 +107,25 @@ func MapClusterPermissions(c *Config) map[string]auth.Permissions {

return permissions
}

func MapFilter(f Filter) api.Includes {
if f.NamespaceKinds == nil {
f.NamespaceKinds = make([]string, 0)
}
if f.ClusterKinds == nil {
f.ClusterKinds = make([]string, 0)
}
if f.Results == nil {
f.Results = make([]string, 0)
}
if f.Severities == nil {
f.Severities = make([]string, 0)
}

return api.Includes{
NamespaceKinds: f.NamespaceKinds,
ClusterKinds: f.ClusterKinds,
Results: f.Results,
Severities: f.Severities,
}
}
24 changes: 22 additions & 2 deletions backend/pkg/server/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ func (h *Handler) GetCustomBoard(ctx *gin.Context) {
SingleSource: len(sources) == 1,
MultipleSource: len(sources) > 1,
Namespaces: make([]string, 0),
Display: config.Display,
Severities: config.Filter.Severities,
Status: config.Filter.Results,
NamespaceKinds: config.Filter.NamespaceKinds,
ClusterKinds: config.Filter.ClusterKinds,
Charts: service.Charts{
ClusterScope: make(map[string]map[string]int),
NamespaceScope: make(map[string]*service.ChartVariants),
Expand All @@ -210,7 +215,17 @@ func (h *Handler) GetCustomBoard(ctx *gin.Context) {

query["namespaces"] = namespaces

dashboard, err := h.service.Dashboard(ctx, ctx.Param("cluster"), sources, namespaces, config.ClusterScope, query)
dashboard, err := h.service.Dashboard(ctx, service.DashboardOptions{
Cluster: ctx.Param("cluster"),
Sources: sources,
Namespaces: namespaces,
Display: config.Display,
ClusterScope: config.ClusterScope,
Status: config.Filter.Results,
Severities: config.Filter.Severities,
NamespaceKinds: config.Filter.NamespaceKinds,
ClusterKinds: config.Filter.ClusterKinds,
}, query)
if err != nil {
zap.L().Error("failed to generate dashboard", zap.Error(err))
ctx.AbortWithStatus(http.StatusInternalServerError)
Expand Down Expand Up @@ -322,7 +337,12 @@ func (h *Handler) Dashboard(ctx *gin.Context) {
return
}

dashboard, err := h.service.Dashboard(ctx, ctx.Param("cluster"), sources, namespaces, true, ctx.Request.URL.Query())
dashboard, err := h.service.Dashboard(ctx, service.DashboardOptions{
Cluster: ctx.Param("cluster"),
Sources: sources,
Namespaces: namespaces,
ClusterScope: true,
}, ctx.Request.URL.Query())
if err != nil {
zap.L().Error("failed to generate dashboard", zap.Error(err))
ctx.AbortWithStatus(http.StatusInternalServerError)
Expand Down
9 changes: 9 additions & 0 deletions backend/pkg/server/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ type Excludes struct {
Severities []string `json:"severities"`
}

type Includes struct {
NamespaceKinds []string `json:"namespaceKinds"`
ClusterKinds []string `json:"clusterKinds"`
Results []string `json:"results"`
Severities []string `json:"severities"`
}

type Source struct {
Name string `json:"name"`
ViewType string `mapstructure:"type"`
Expand Down Expand Up @@ -58,6 +65,8 @@ type CustomBoard struct {
auth.Permissions `json:"-"`
Name string `json:"name"`
ID string `json:"id"`
Display string `json:"display"`
Filter Includes `json:"filter"`
ClusterScope bool `json:"-"`
Namespaces Namespaces `json:"-"`
Sources Sources `json:"-"`
Expand Down
15 changes: 15 additions & 0 deletions backend/pkg/service/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Total struct {
type Dashboard struct {
Title string `json:"title"`
Type string `json:"type"`
Display string `json:"display"`
FilterSources []string `json:"filterSources,omitempty"`
ClusterScope bool `json:"clusterScope"`
Sources []string `json:"sources"`
Expand All @@ -69,6 +70,8 @@ type Dashboard struct {
ShowResults []string `json:"showResults"`
Status []string `json:"status"`
Severities []string `json:"severities"`
NamespaceKinds []string `json:"namespaceKinds"`
ClusterKinds []string `json:"clusterKinds"`
}

type ResourceDetails struct {
Expand Down Expand Up @@ -152,3 +155,15 @@ type ExceptionRequest struct {
Category string `json:"category"`
Policies []ExceptionPolicy `json:"policies"`
}

type DashboardOptions struct {
Status []string
Severities []string
Sources []string
Namespaces []string
NamespaceKinds []string
ClusterKinds []string
Cluster string
Display string
ClusterScope bool
}
Loading
Loading