-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Frank Jogeleit <[email protected]>
- Loading branch information
Frank Jogeleit
committed
Feb 28, 2024
1 parent
92191d8
commit 824115b
Showing
12 changed files
with
273 additions
and
2 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
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,70 @@ | ||
# Policy Reporter UI - Custom Boards | ||
|
||
CustomBoards allows you to configure additional dashboards with a custom subset of sources and namespaces, selected via a list and/or label selector | ||
|
||
## Example CustomBoard Config | ||
|
||
![Custom Boards](https://github.com/kyverno/policy-reporter/blob/3.x/docs/images/custom-boards/list.png) | ||
|
||
```yaml | ||
ui: | ||
enabled: true | ||
|
||
customBoards: | ||
- name: System | ||
namespaces: | ||
list: | ||
- kube-system | ||
- kyverno | ||
- policy-reporter | ||
``` | ||
### CustomBoard with NamespaceSelector | ||
![Custom Boards](https://github.com/kyverno/policy-reporter/blob/3.x/docs/images/custom-boards/selector.png) | ||
```yaml | ||
ui: | ||
enabled: true | ||
|
||
customBoards: | ||
- name: System | ||
namespaces: | ||
selector: | ||
group: system | ||
``` | ||
### CustomBoard with ClusterResources | ||
![Custom Boards](https://github.com/kyverno/policy-reporter/blob/3.x/docs/images/custom-boards/cluster.png) | ||
```yaml | ||
ui: | ||
enabled: true | ||
|
||
customBoards: | ||
- name: System | ||
clusterScope: | ||
enabled: true | ||
namespaces: | ||
selector: | ||
group: system | ||
``` | ||
### CustomBoard with Source List | ||
![Custom Boards](https://github.com/kyverno/policy-reporter/blob/3.x/docs/images/custom-boards/source.png) | ||
```yaml | ||
ui: | ||
enabled: true | ||
|
||
customBoards: | ||
- name: System | ||
clusterScope: | ||
enabled: true | ||
namespaces: | ||
selector: | ||
group: system | ||
sources: | ||
list: [kyverno] | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package api_test | ||
|
||
import ( | ||
"errors" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/kyverno/policy-reporter/pkg/api" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHealthCheckSuccess(t *testing.T) { | ||
check := func() error { | ||
return nil | ||
} | ||
|
||
gin.SetMode(gin.ReleaseMode) | ||
|
||
server := api.NewServer(gin.New(), api.WithHealthChecks([]api.HealthCheck{check})) | ||
|
||
req, _ := http.NewRequest("GET", "/healthz", nil) | ||
w := httptest.NewRecorder() | ||
|
||
server.Serve(w, req) | ||
|
||
assert := assert.New(t) | ||
assert.Equal(http.StatusOK, w.Code) | ||
} | ||
|
||
func TestHealthCheckError(t *testing.T) { | ||
check := func() error { | ||
return nil | ||
} | ||
|
||
err := func() error { | ||
return errors.New("unhealthy") | ||
} | ||
|
||
gin.SetMode(gin.ReleaseMode) | ||
|
||
server := api.NewServer(gin.New(), api.WithHealthChecks([]api.HealthCheck{check, err})) | ||
|
||
req, _ := http.NewRequest("GET", "/healthz", nil) | ||
w := httptest.NewRecorder() | ||
|
||
server.Serve(w, req) | ||
|
||
assert := assert.New(t) | ||
assert.Equal(http.StatusServiceUnavailable, w.Code) | ||
} | ||
|
||
func TestReadyCheckSuccess(t *testing.T) { | ||
check := func() error { | ||
return nil | ||
} | ||
|
||
gin.SetMode(gin.ReleaseMode) | ||
|
||
server := api.NewServer(gin.New(), api.WithHealthChecks([]api.HealthCheck{check})) | ||
|
||
req, _ := http.NewRequest("GET", "/ready", nil) | ||
w := httptest.NewRecorder() | ||
|
||
server.Serve(w, req) | ||
|
||
assert := assert.New(t) | ||
assert.Equal(http.StatusOK, w.Code) | ||
} |
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,60 @@ | ||
package api_test | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/kyverno/policy-reporter/pkg/api" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMetrics(t *testing.T) { | ||
gin.SetMode(gin.ReleaseMode) | ||
|
||
server := api.NewServer(gin.New(), api.WithMetrics()) | ||
|
||
req, _ := http.NewRequest("GET", "/metrics", nil) | ||
w := httptest.NewRecorder() | ||
|
||
server.Serve(w, req) | ||
|
||
assert := assert.New(t) | ||
assert.Equal(http.StatusOK, w.Code) | ||
} | ||
|
||
func TestMetricsWithBasicAuthError(t *testing.T) { | ||
gin.SetMode(gin.ReleaseMode) | ||
|
||
server := api.NewServer(gin.New(), api.WithBasicAuth(api.BasicAuth{ | ||
Username: "user", | ||
Password: "password", | ||
}), api.WithMetrics()) | ||
|
||
req, _ := http.NewRequest("GET", "/metrics", nil) | ||
w := httptest.NewRecorder() | ||
|
||
server.Serve(w, req) | ||
|
||
assert := assert.New(t) | ||
assert.Equal(http.StatusUnauthorized, w.Code) | ||
} | ||
|
||
func TestMetricsWithBasicAuthSuccess(t *testing.T) { | ||
gin.SetMode(gin.ReleaseMode) | ||
|
||
server := api.NewServer(gin.New(), api.WithBasicAuth(api.BasicAuth{ | ||
Username: "user", | ||
Password: "password", | ||
}), api.WithMetrics()) | ||
|
||
req, _ := http.NewRequest("GET", "/metrics", nil) | ||
req.SetBasicAuth("user", "password") | ||
w := httptest.NewRecorder() | ||
|
||
server.Serve(w, req) | ||
|
||
assert := assert.New(t) | ||
assert.Equal(http.StatusOK, w.Code) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package api_test | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/kyverno/policy-reporter/pkg/api" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var check = func() error { | ||
return nil | ||
} | ||
|
||
func TestWithoutGZIP(t *testing.T) { | ||
gin.SetMode(gin.ReleaseMode) | ||
|
||
engine := gin.New() | ||
|
||
server := api.NewServer(engine, api.WithHealthChecks([]api.HealthCheck{check})) | ||
|
||
req, _ := http.NewRequest("GET", "/healthz", nil) | ||
req.Header.Add("Accept-Encoding", "gzip") | ||
w := httptest.NewRecorder() | ||
|
||
server.Serve(w, req) | ||
|
||
assert := assert.New(t) | ||
assert.Equal(http.StatusOK, w.Code) | ||
assert.Equal("", w.Header().Get("Content-Encoding")) | ||
} | ||
|
||
func TestWithGZIP(t *testing.T) { | ||
gin.SetMode(gin.ReleaseMode) | ||
|
||
server := api.NewServer(gin.New(), api.WithGZIP(), api.WithHealthChecks([]api.HealthCheck{check})) | ||
|
||
req, _ := http.NewRequest("GET", "/healthz", nil) | ||
req.Header.Add("Accept-Encoding", "gzip") | ||
w := httptest.NewRecorder() | ||
|
||
server.Serve(w, req) | ||
|
||
assert := assert.New(t) | ||
assert.Equal(http.StatusOK, w.Code) | ||
assert.Equal("gzip", w.Header().Get("Content-Encoding")) | ||
} | ||
|
||
func TestWithProfiling(t *testing.T) { | ||
gin.SetMode(gin.ReleaseMode) | ||
|
||
server := api.NewServer(gin.New(), api.WithProfiling()) | ||
|
||
req, _ := http.NewRequest("GET", "/debug/pprof/", nil) | ||
w := httptest.NewRecorder() | ||
|
||
server.Serve(w, req) | ||
|
||
assert := assert.New(t) | ||
assert.Equal(http.StatusOK, w.Code) | ||
} |
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