Skip to content

Commit 67a1a4a

Browse files
authored
Show policies without results (#471)
* Update Dependencies Signed-off-by: Frank Jogeleit <[email protected]> * Show Policies without results when using a source plugin Signed-off-by: Frank Jogeleit <[email protected]> --------- Signed-off-by: Frank Jogeleit <[email protected]>
1 parent 3d5a245 commit 67a1a4a

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

backend/pkg/server/api/handler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ func (h *Handler) Policies(ctx *gin.Context) {
363363
if err != nil {
364364
zap.L().Error("failed to load policies from plugin", zap.String("cluster", ctx.Param("cluster")), zap.String("plugin", source), zap.Error(err))
365365
} else {
366-
ctx.JSON(http.StatusOK, MapPluginPolicies(policies, list))
366+
ctx.JSON(http.StatusOK, MapPluginPolicies(source, policies, list))
367367
return
368368
}
369369
}

backend/pkg/server/api/mapper.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
plugin "github.com/kyverno/policy-reporter-plugins/sdk/api"
88

99
"github.com/kyverno/policy-reporter-ui/pkg/api/core"
10+
"github.com/kyverno/policy-reporter-ui/pkg/service"
1011
"github.com/kyverno/policy-reporter-ui/pkg/utils"
1112
)
1213

@@ -118,7 +119,7 @@ func MapPoliciesFromCore(policies []core.Policy) map[string][]Policy {
118119
return results
119120
}
120121

121-
func MapPluginPolicies(policies []plugin.PolicyListItem, coreList []core.Policy) map[string][]Policy {
122+
func MapPluginPolicies(source string, policies []plugin.PolicyListItem, coreList []core.Policy) map[string][]Policy {
122123
results := make(map[string][]Policy)
123124

124125
if len(coreList) == 0 {
@@ -135,15 +136,25 @@ func MapPluginPolicies(policies []plugin.PolicyListItem, coreList []core.Policy)
135136

136137
for _, policy := range policies {
137138
if _, ok := cache[policy.Category]; !ok {
138-
continue
139+
cache[policy.Category] = make(map[string]*core.Policy)
139140
}
140141

141142
corePolicy := cache[policy.Category][policyID(policy)]
142143
if corePolicy == nil {
143144
corePolicy = cache[policy.Category][policy.Name]
144145
}
145146
if corePolicy == nil {
146-
continue
147+
corePolicy = &core.Policy{
148+
Name: policy.Name,
149+
Source: source,
150+
Results: map[string]int{
151+
service.StatusPass: 0,
152+
service.StatusFail: 0,
153+
service.StatusError: 0,
154+
service.StatusWarn: 0,
155+
service.StatusSkip: 0,
156+
},
157+
}
147158
}
148159

149160
category := policy.Category

frontend/modules/core/components/policy/Item.vue

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<v-list-item-title>
99
{{ item.title }}
1010
</v-list-item-title>
11+
<v-list-item-subtitle v-if="item.namespace">
12+
{{ item.namespace }}
13+
</v-list-item-subtitle>
1114
<template v-slot:append v-if="summary">
1215
<ResultChip :to="{ name: 'policies-source-policy', params: { source: item.source, policy: item.name }, query: { kinds: route.query?.kinds, 'cluster-kinds': route.query['cluster-kinds'] }}" class="ml-2" :status="Status.SUMMARY" :count="count" tooltip="results" />
1316
</template>

frontend/modules/core/components/policy/SourceGroup.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<v-card-text>
1313
<GraphBarPerCategory :source="source.chart" />
1414
</v-card-text>
15-
<policy-list v-for="item in source.categories"
15+
<policy-list v-for="item in categories"
1616
:key="item"
1717
:category="item"
1818
:pending="pending as boolean"
@@ -47,6 +47,8 @@ const { data, refresh, pending } = useAPI(
4747
{ default: () => ({}) }
4848
);
4949
50+
const categories = computed(() => Object.keys(data.value || {}))
51+
5052
watch(combinedFilter, onChange(refresh))
5153
5254
useStatusProvider(ref({ status: props.source.status }))

0 commit comments

Comments
 (0)