Skip to content

Commit 0fa51e3

Browse files
authored
Extend CustomBoard with filters (#484)
Signed-off-by: Frank Jogeleit <[email protected]>
1 parent 146547b commit 0fa51e3

File tree

17 files changed

+493
-82
lines changed

17 files changed

+493
-82
lines changed

backend/pkg/config/config.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,21 @@ type Boards struct {
205205
AccessControl AccessControl `koanf:"accessControl"`
206206
}
207207

208+
type Filter struct {
209+
NamespaceKinds []string `koanf:"namespaceKinds"`
210+
ClusterKinds []string `koanf:"clusterKinds"`
211+
Results []string `koanf:"results"`
212+
Severities []string `koanf:"severities"`
213+
}
214+
208215
type CustomBoard struct {
209216
Name string `koanf:"name"`
210217
AccessControl AccessControl `koanf:"accessControl"`
211-
Namespaces struct {
218+
Filter struct {
219+
Include Filter `koanf:"include"`
220+
} `koanf:"filter"`
221+
Display string `json:"display"`
222+
Namespaces struct {
212223
Selector map[string]string `koanf:"selector"`
213224
List []string `koanf:"list"`
214225
} `koanf:"namespaces"`

backend/pkg/config/mapper.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ func MapCustomBoards(customBoards []CustomBoard) map[string]api.CustomBoard {
7373
id := slug.Make(c.Name)
7474

7575
configs[id] = api.CustomBoard{
76-
Name: c.Name,
77-
ID: id,
76+
Name: c.Name,
77+
ID: id,
78+
Display: c.Display,
79+
Filter: MapFilter(c.Filter.Include),
7880
Namespaces: api.Namespaces{
7981
Selector: c.Namespaces.Selector,
8082
List: c.Namespaces.List,
@@ -105,3 +107,25 @@ func MapClusterPermissions(c *Config) map[string]auth.Permissions {
105107

106108
return permissions
107109
}
110+
111+
func MapFilter(f Filter) api.Includes {
112+
if f.NamespaceKinds == nil {
113+
f.NamespaceKinds = make([]string, 0)
114+
}
115+
if f.ClusterKinds == nil {
116+
f.ClusterKinds = make([]string, 0)
117+
}
118+
if f.Results == nil {
119+
f.Results = make([]string, 0)
120+
}
121+
if f.Severities == nil {
122+
f.Severities = make([]string, 0)
123+
}
124+
125+
return api.Includes{
126+
NamespaceKinds: f.NamespaceKinds,
127+
ClusterKinds: f.ClusterKinds,
128+
Results: f.Results,
129+
Severities: f.Severities,
130+
}
131+
}

backend/pkg/server/api/handler.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ func (h *Handler) GetCustomBoard(ctx *gin.Context) {
199199
SingleSource: len(sources) == 1,
200200
MultipleSource: len(sources) > 1,
201201
Namespaces: make([]string, 0),
202+
Display: config.Display,
203+
Severities: config.Filter.Severities,
204+
Status: config.Filter.Results,
205+
NamespaceKinds: config.Filter.NamespaceKinds,
206+
ClusterKinds: config.Filter.ClusterKinds,
202207
Charts: service.Charts{
203208
ClusterScope: make(map[string]map[string]int),
204209
NamespaceScope: make(map[string]*service.ChartVariants),
@@ -210,7 +215,17 @@ func (h *Handler) GetCustomBoard(ctx *gin.Context) {
210215

211216
query["namespaces"] = namespaces
212217

213-
dashboard, err := h.service.Dashboard(ctx, ctx.Param("cluster"), sources, namespaces, config.ClusterScope, query)
218+
dashboard, err := h.service.Dashboard(ctx, service.DashboardOptions{
219+
Cluster: ctx.Param("cluster"),
220+
Sources: sources,
221+
Namespaces: namespaces,
222+
Display: config.Display,
223+
ClusterScope: config.ClusterScope,
224+
Status: config.Filter.Results,
225+
Severities: config.Filter.Severities,
226+
NamespaceKinds: config.Filter.NamespaceKinds,
227+
ClusterKinds: config.Filter.ClusterKinds,
228+
}, query)
214229
if err != nil {
215230
zap.L().Error("failed to generate dashboard", zap.Error(err))
216231
ctx.AbortWithStatus(http.StatusInternalServerError)
@@ -322,7 +337,12 @@ func (h *Handler) Dashboard(ctx *gin.Context) {
322337
return
323338
}
324339

325-
dashboard, err := h.service.Dashboard(ctx, ctx.Param("cluster"), sources, namespaces, true, ctx.Request.URL.Query())
340+
dashboard, err := h.service.Dashboard(ctx, service.DashboardOptions{
341+
Cluster: ctx.Param("cluster"),
342+
Sources: sources,
343+
Namespaces: namespaces,
344+
ClusterScope: true,
345+
}, ctx.Request.URL.Query())
326346
if err != nil {
327347
zap.L().Error("failed to generate dashboard", zap.Error(err))
328348
ctx.AbortWithStatus(http.StatusInternalServerError)

backend/pkg/server/api/model.go

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ type Excludes struct {
2727
Severities []string `json:"severities"`
2828
}
2929

30+
type Includes struct {
31+
NamespaceKinds []string `json:"namespaceKinds"`
32+
ClusterKinds []string `json:"clusterKinds"`
33+
Results []string `json:"results"`
34+
Severities []string `json:"severities"`
35+
}
36+
3037
type Source struct {
3138
Name string `json:"name"`
3239
ViewType string `mapstructure:"type"`
@@ -58,6 +65,8 @@ type CustomBoard struct {
5865
auth.Permissions `json:"-"`
5966
Name string `json:"name"`
6067
ID string `json:"id"`
68+
Display string `json:"display"`
69+
Filter Includes `json:"filter"`
6170
ClusterScope bool `json:"-"`
6271
Namespaces Namespaces `json:"-"`
6372
Sources Sources `json:"-"`

backend/pkg/service/model.go

+15
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Total struct {
5656
type Dashboard struct {
5757
Title string `json:"title"`
5858
Type string `json:"type"`
59+
Display string `json:"display"`
5960
FilterSources []string `json:"filterSources,omitempty"`
6061
ClusterScope bool `json:"clusterScope"`
6162
Sources []string `json:"sources"`
@@ -69,6 +70,8 @@ type Dashboard struct {
6970
ShowResults []string `json:"showResults"`
7071
Status []string `json:"status"`
7172
Severities []string `json:"severities"`
73+
NamespaceKinds []string `json:"namespaceKinds"`
74+
ClusterKinds []string `json:"clusterKinds"`
7275
}
7376

7477
type ResourceDetails struct {
@@ -152,3 +155,15 @@ type ExceptionRequest struct {
152155
Category string `json:"category"`
153156
Policies []ExceptionPolicy `json:"policies"`
154157
}
158+
159+
type DashboardOptions struct {
160+
Status []string
161+
Severities []string
162+
Sources []string
163+
Namespaces []string
164+
NamespaceKinds []string
165+
ClusterKinds []string
166+
Cluster string
167+
Display string
168+
ClusterScope bool
169+
}

0 commit comments

Comments
 (0)