mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix: namespace in kyverno-test.yaml seems to have no effect in case of exclude (#8354)
* fix: namespace in kyverno-test.yaml seems to have no effect in case of exclude Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * fix tests Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * unit tests Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> --------- Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
2ea68ccc7a
commit
dbad967150
25 changed files with 292 additions and 398 deletions
|
@ -10,6 +10,6 @@ type Test struct {
|
||||||
Resources []string `json:"resources"`
|
Resources []string `json:"resources"`
|
||||||
Variables string `json:"variables,omitempty"`
|
Variables string `json:"variables,omitempty"`
|
||||||
UserInfo string `json:"userinfo,omitempty"`
|
UserInfo string `json:"userinfo,omitempty"`
|
||||||
Results []TestResults `json:"results"`
|
Results []TestResult `json:"results"`
|
||||||
Values *values.Values `json:"values,omitempty"`
|
Values *values.Values `json:"values,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TestResults struct {
|
type TestResultBase struct {
|
||||||
// Policy mentions the name of the policy.
|
// Policy mentions the name of the policy.
|
||||||
Policy string `json:"policy"`
|
Policy string `json:"policy"`
|
||||||
// Rule mentions the name of the rule in the policy.
|
// Rule mentions the name of the rule in the policy.
|
||||||
|
@ -18,17 +18,8 @@ type TestResults struct {
|
||||||
// Result mentions the result that the user is expecting.
|
// Result mentions the result that the user is expecting.
|
||||||
// Possible values are pass, fail and skip.
|
// Possible values are pass, fail and skip.
|
||||||
Result policyreportv1alpha2.PolicyResult `json:"result"`
|
Result policyreportv1alpha2.PolicyResult `json:"result"`
|
||||||
// Status mentions the status that the user is expecting.
|
|
||||||
// Possible values are pass, fail and skip.
|
|
||||||
Status policyreportv1alpha2.PolicyResult `json:"status,omitempty"`
|
|
||||||
// Resource mentions the name of the resource on which the policy is to be applied.
|
|
||||||
Resource string `json:"resource,omitempty"`
|
|
||||||
// Resources gives us the list of resources on which the policy is going to be applied.
|
|
||||||
Resources []string `json:"resources"`
|
|
||||||
// Kind mentions the kind of the resource on which the policy is to be applied.
|
// Kind mentions the kind of the resource on which the policy is to be applied.
|
||||||
Kind string `json:"kind"`
|
Kind string `json:"kind"`
|
||||||
// Namespace mentions the namespace of the policy which has namespace scope.
|
|
||||||
Namespace string `json:"namespace,omitempty"`
|
|
||||||
// PatchedResource takes a resource configuration file in yaml format from
|
// PatchedResource takes a resource configuration file in yaml format from
|
||||||
// the user to compare it against the Kyverno mutated resource configuration.
|
// the user to compare it against the Kyverno mutated resource configuration.
|
||||||
PatchedResource string `json:"patchedResource,omitempty"`
|
PatchedResource string `json:"patchedResource,omitempty"`
|
||||||
|
@ -39,3 +30,23 @@ type TestResults struct {
|
||||||
// from the user which is meant to be cloned by the generate rule.
|
// from the user which is meant to be cloned by the generate rule.
|
||||||
CloneSourceResource string `json:"cloneSourceResource,omitempty"`
|
CloneSourceResource string `json:"cloneSourceResource,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TestResultDeprecated struct {
|
||||||
|
// Status mentions the status that the user is expecting.
|
||||||
|
// Possible values are pass, fail and skip.
|
||||||
|
// This is DEPRECATED, use `Result` instead.
|
||||||
|
Status policyreportv1alpha2.PolicyResult `json:"status,omitempty"`
|
||||||
|
// Resource mentions the name of the resource on which the policy is to be applied.
|
||||||
|
// This is DEPRECATED, use `Resources` instead.
|
||||||
|
Resource string `json:"resource,omitempty"`
|
||||||
|
// Namespace mentions the namespace of the policy which has namespace scope.
|
||||||
|
// This is DEPRECATED, use a name in the form `<namespace>/<name>` for policies and/or resources instead.
|
||||||
|
Namespace string `json:"namespace,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestResult struct {
|
||||||
|
TestResultBase `json:",inline,omitempty"`
|
||||||
|
TestResultDeprecated `json:",inline,omitempty"`
|
||||||
|
// Resources gives us the list of resources on which the policy is going to be applied.
|
||||||
|
Resources []string `json:"resources"`
|
||||||
|
}
|
||||||
|
|
|
@ -447,10 +447,7 @@ func printSkippedAndInvalidPolicies(skipInvalidPolicies SkippedInvalidPolicies)
|
||||||
}
|
}
|
||||||
|
|
||||||
func printReport(engineResponses []engineapi.EngineResponse, auditWarn bool) {
|
func printReport(engineResponses []engineapi.EngineResponse, auditWarn bool) {
|
||||||
clustered, namespaced, err := report.ComputePolicyReports(auditWarn, engineResponses...)
|
clustered, namespaced := report.ComputePolicyReports(auditWarn, engineResponses...)
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Error: failed to compute policy reports")
|
|
||||||
}
|
|
||||||
if len(clustered) > 0 || len(namespaced) > 0 {
|
if len(clustered) > 0 || len(namespaced) > 0 {
|
||||||
fmt.Println(divider)
|
fmt.Println(divider)
|
||||||
fmt.Println("POLICY REPORT:")
|
fmt.Println("POLICY REPORT:")
|
||||||
|
|
|
@ -317,7 +317,7 @@ func Test_Apply(t *testing.T) {
|
||||||
_, _, _, responses, err := tc.config.applyCommandHelper()
|
_, _, _, responses, err := tc.config.applyCommandHelper()
|
||||||
assert.NilError(t, err, desc)
|
assert.NilError(t, err, desc)
|
||||||
|
|
||||||
clustered, _, _ := report.ComputePolicyReports(tc.config.AuditWarn, responses...)
|
clustered, _ := report.ComputePolicyReports(tc.config.AuditWarn, responses...)
|
||||||
assert.Assert(t, len(clustered) > 0, "policy reports should not be empty: %s", desc)
|
assert.Assert(t, len(clustered) > 0, "policy reports should not be empty: %s", desc)
|
||||||
combined := []policyreportv1alpha2.ClusterPolicyReport{
|
combined := []policyreportv1alpha2.ClusterPolicyReport{
|
||||||
report.MergeClusterReports(clustered),
|
report.MergeClusterReports(clustered),
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
|
||||||
testapi "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/apis/test"
|
testapi "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/apis/test"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/command"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/command"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test"
|
||||||
|
@ -50,7 +49,7 @@ func Command() *cobra.Command {
|
||||||
fmt.Println(" WARNING: test has no policies")
|
fmt.Println(" WARNING: test has no policies")
|
||||||
}
|
}
|
||||||
if len(test.Resources) == 0 {
|
if len(test.Resources) == 0 {
|
||||||
fmt.Println(" WARNING: test has no policies")
|
fmt.Println(" WARNING: test has no resources")
|
||||||
}
|
}
|
||||||
for i := range test.Results {
|
for i := range test.Results {
|
||||||
result := &test.Results[i]
|
result := &test.Results[i]
|
||||||
|
@ -63,6 +62,12 @@ func Command() *cobra.Command {
|
||||||
result.Resource = ""
|
result.Resource = ""
|
||||||
needsSave = true
|
needsSave = true
|
||||||
}
|
}
|
||||||
|
if result.Namespace != "" {
|
||||||
|
fmt.Println(" WARNING: test result uses deprecated `namespace` field, replacing `policy` with a `<namespace>/<name>` pattern")
|
||||||
|
result.Policy = fmt.Sprintf("%s/%s", result.Namespace, result.Policy)
|
||||||
|
result.Namespace = ""
|
||||||
|
needsSave = true
|
||||||
|
}
|
||||||
if result.Status != "" && result.Result != "" {
|
if result.Status != "" && result.Result != "" {
|
||||||
fmt.Println(" ERROR: test result should not use both `status` and `result` fields")
|
fmt.Println(" ERROR: test result should not use both `status` and `result` fields")
|
||||||
}
|
}
|
||||||
|
@ -74,36 +79,17 @@ func Command() *cobra.Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if compress {
|
if compress {
|
||||||
compressed := map[key][]string{}
|
compressed := map[testapi.TestResultBase][]string{}
|
||||||
for _, result := range test.Results {
|
for _, result := range test.Results {
|
||||||
k := key{
|
compressed[result.TestResultBase] = append(compressed[result.TestResultBase], result.Resources...)
|
||||||
Policy: result.Policy,
|
|
||||||
Rule: result.Rule,
|
|
||||||
IsValidatingAdmissionPolicy: result.IsValidatingAdmissionPolicy,
|
|
||||||
Result: result.Result,
|
|
||||||
Kind: result.Kind,
|
|
||||||
Namespace: result.Namespace,
|
|
||||||
PatchedResource: result.PatchedResource,
|
|
||||||
GeneratedResource: result.GeneratedResource,
|
|
||||||
CloneSourceResource: result.CloneSourceResource,
|
|
||||||
}
|
|
||||||
compressed[k] = append(compressed[k], result.Resources...)
|
|
||||||
}
|
}
|
||||||
if len(compressed) != len(test.Results) {
|
if len(compressed) != len(test.Results) {
|
||||||
needsSave = true
|
needsSave = true
|
||||||
}
|
}
|
||||||
test.Results = nil
|
test.Results = nil
|
||||||
for k, v := range compressed {
|
for k, v := range compressed {
|
||||||
test.Results = append(test.Results, testapi.TestResults{
|
test.Results = append(test.Results, testapi.TestResult{
|
||||||
Policy: k.Policy,
|
TestResultBase: k,
|
||||||
Rule: k.Rule,
|
|
||||||
IsValidatingAdmissionPolicy: k.IsValidatingAdmissionPolicy,
|
|
||||||
Result: k.Result,
|
|
||||||
Kind: k.Kind,
|
|
||||||
Namespace: k.Namespace,
|
|
||||||
PatchedResource: k.PatchedResource,
|
|
||||||
GeneratedResource: k.GeneratedResource,
|
|
||||||
CloneSourceResource: k.CloneSourceResource,
|
|
||||||
Resources: v,
|
Resources: v,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -135,15 +121,3 @@ func Command() *cobra.Command {
|
||||||
cmd.Flags().BoolVar(&compress, "compress", false, "Compress test results")
|
cmd.Flags().BoolVar(&compress, "compress", false, "Compress test results")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
type key struct {
|
|
||||||
Policy string
|
|
||||||
Rule string
|
|
||||||
IsValidatingAdmissionPolicy bool
|
|
||||||
Result policyreportv1alpha2.PolicyResult
|
|
||||||
Kind string
|
|
||||||
Namespace string
|
|
||||||
PatchedResource string
|
|
||||||
GeneratedResource string
|
|
||||||
CloneSourceResource string
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,14 +17,14 @@ import (
|
||||||
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
||||||
"github.com/kyverno/kyverno/pkg/openapi"
|
"github.com/kyverno/kyverno/pkg/openapi"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"k8s.io/client-go/tools/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Command() *cobra.Command {
|
func Command() *cobra.Command {
|
||||||
var cmd *cobra.Command
|
|
||||||
var testCase string
|
var testCase string
|
||||||
var fileName, gitBranch string
|
var fileName, gitBranch string
|
||||||
var registryAccess, failOnly, removeColor, detailedResults bool
|
var registryAccess, failOnly, removeColor, detailedResults bool
|
||||||
cmd = &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "test [local folder or git repository]...",
|
Use: "test [local folder or git repository]...",
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
Short: command.FormatDescription(true, websiteUrl, false, description...),
|
Short: command.FormatDescription(true, websiteUrl, false, description...),
|
||||||
|
@ -118,7 +118,7 @@ func testCommandExecute(
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if test.Err == nil {
|
if test.Err == nil {
|
||||||
// filter results
|
// filter results
|
||||||
var filteredResults []testapi.TestResults
|
var filteredResults []testapi.TestResult
|
||||||
for _, res := range test.Test.Results {
|
for _, res := range test.Test.Results {
|
||||||
if filter.Apply(res) {
|
if filter.Apply(res) {
|
||||||
filteredResults = append(filteredResults, res)
|
filteredResults = append(filteredResults, res)
|
||||||
|
@ -154,7 +154,7 @@ func testCommandExecute(
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkResult(test testapi.TestResults, fs billy.Filesystem, resoucePath string, response engineapi.EngineResponse, rule engineapi.RuleResponse) (bool, string, string) {
|
func checkResult(test testapi.TestResult, fs billy.Filesystem, resoucePath string, response engineapi.EngineResponse, rule engineapi.RuleResponse) (bool, string, string) {
|
||||||
expected := test.Result
|
expected := test.Result
|
||||||
// fallback to the deprecated field
|
// fallback to the deprecated field
|
||||||
if expected == "" {
|
if expected == "" {
|
||||||
|
@ -179,31 +179,27 @@ func checkResult(test testapi.TestResults, fs billy.Filesystem, resoucePath stri
|
||||||
return false, "Generated resource didn't match the generated resource in the test result", "Resource diff"
|
return false, "Generated resource didn't match the generated resource in the test result", "Resource diff"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result, err := report.ComputePolicyReportResult(false, response, rule)
|
result := report.ComputePolicyReportResult(false, response, rule)
|
||||||
if err != nil {
|
|
||||||
return false, err.Error(), "Error"
|
|
||||||
}
|
|
||||||
if result.Result != expected {
|
if result.Result != expected {
|
||||||
return false, result.Message, fmt.Sprintf("Want %s, got %s", expected, result.Result)
|
return false, result.Message, fmt.Sprintf("Want %s, got %s", expected, result.Result)
|
||||||
}
|
}
|
||||||
return true, result.Message, "Ok"
|
return true, result.Message, "Ok"
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupEngineResponses(test testapi.TestResults, resourceName string, responses ...engineapi.EngineResponse) []engineapi.EngineResponse {
|
func lookupEngineResponses(test testapi.TestResult, resourceName string, responses ...engineapi.EngineResponse) []engineapi.EngineResponse {
|
||||||
var matches []engineapi.EngineResponse
|
var matches []engineapi.EngineResponse
|
||||||
for _, response := range responses {
|
for _, response := range responses {
|
||||||
policy := response.Policy()
|
policy := response.Policy()
|
||||||
resource := response.Resource
|
resource := response.Resource
|
||||||
if policy.GetName() != test.Policy {
|
pName := cache.MetaObjectToName(policy.MetaObject()).String()
|
||||||
continue
|
rName := cache.MetaObjectToName(&resource).String()
|
||||||
}
|
|
||||||
if test.Kind != resource.GetKind() {
|
if test.Kind != resource.GetKind() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if resourceName != "" && resourceName != resource.GetName() {
|
if pName != test.Policy {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if test.Namespace != "" && test.Namespace != resource.GetNamespace() {
|
if resourceName != "" && rName != resourceName && resource.GetName() != resourceName {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
matches = append(matches, response)
|
matches = append(matches, response)
|
||||||
|
@ -211,7 +207,7 @@ func lookupEngineResponses(test testapi.TestResults, resourceName string, respon
|
||||||
return matches
|
return matches
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookupRuleResponses(test testapi.TestResults, responses ...engineapi.RuleResponse) []engineapi.RuleResponse {
|
func lookupRuleResponses(test testapi.TestResult, responses ...engineapi.RuleResponse) []engineapi.RuleResponse {
|
||||||
var matches []engineapi.RuleResponse
|
var matches []engineapi.RuleResponse
|
||||||
// Since there are no rules in case of validating admission policies, responses are returned without checking rule names.
|
// Since there are no rules in case of validating admission policies, responses are returned without checking rule names.
|
||||||
if test.IsValidatingAdmissionPolicy {
|
if test.IsValidatingAdmissionPolicy {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func printTestResult(
|
func printTestResult(
|
||||||
tests []testapi.TestResults,
|
tests []testapi.TestResult,
|
||||||
responses []engineapi.EngineResponse,
|
responses []engineapi.EngineResponse,
|
||||||
rc *resultCounts,
|
rc *resultCounts,
|
||||||
failOnly bool,
|
failOnly bool,
|
||||||
|
|
|
@ -11,12 +11,9 @@ import (
|
||||||
"k8s.io/client-go/tools/cache"
|
"k8s.io/client-go/tools/cache"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ComputePolicyReportResult(auditWarn bool, engineResponse engineapi.EngineResponse, ruleResponse engineapi.RuleResponse) (policyreportv1alpha2.PolicyReportResult, error) {
|
func ComputePolicyReportResult(auditWarn bool, engineResponse engineapi.EngineResponse, ruleResponse engineapi.RuleResponse) policyreportv1alpha2.PolicyReportResult {
|
||||||
policy := engineResponse.Policy()
|
policy := engineResponse.Policy()
|
||||||
policyName, err := cache.MetaNamespaceKeyFunc(policy.MetaObject())
|
policyName := cache.MetaObjectToName(policy.MetaObject()).String()
|
||||||
if err != nil {
|
|
||||||
return policyreportv1alpha2.PolicyReportResult{}, err
|
|
||||||
}
|
|
||||||
audit := engineResponse.GetValidationFailureAction().Audit()
|
audit := engineResponse.GetValidationFailureAction().Audit()
|
||||||
scored := annotations.Scored(policy.GetAnnotations())
|
scored := annotations.Scored(policy.GetAnnotations())
|
||||||
category := annotations.Category(policy.GetAnnotations())
|
category := annotations.Category(policy.GetAnnotations())
|
||||||
|
@ -57,10 +54,10 @@ func ComputePolicyReportResult(auditWarn bool, engineResponse engineapi.EngineRe
|
||||||
result.Message = ruleResponse.Message()
|
result.Message = ruleResponse.Message()
|
||||||
result.Source = kyverno.ValueKyvernoApp
|
result.Source = kyverno.ValueKyvernoApp
|
||||||
result.Timestamp = metav1.Timestamp{Seconds: ruleResponse.Stats().Timestamp()}
|
result.Timestamp = metav1.Timestamp{Seconds: ruleResponse.Stats().Timestamp()}
|
||||||
return result, nil
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func ComputePolicyReportResultsPerPolicy(auditWarn bool, engineResponses ...engineapi.EngineResponse) (map[engineapi.GenericPolicy][]policyreportv1alpha2.PolicyReportResult, error) {
|
func ComputePolicyReportResultsPerPolicy(auditWarn bool, engineResponses ...engineapi.EngineResponse) map[engineapi.GenericPolicy][]policyreportv1alpha2.PolicyReportResult {
|
||||||
results := map[engineapi.GenericPolicy][]policyreportv1alpha2.PolicyReportResult{}
|
results := map[engineapi.GenericPolicy][]policyreportv1alpha2.PolicyReportResult{}
|
||||||
for _, engineResponse := range engineResponses {
|
for _, engineResponse := range engineResponses {
|
||||||
if len(engineResponse.PolicyResponse.Rules) == 0 {
|
if len(engineResponse.PolicyResponse.Rules) == 0 {
|
||||||
|
@ -72,26 +69,19 @@ func ComputePolicyReportResultsPerPolicy(auditWarn bool, engineResponses ...engi
|
||||||
// if ruleResponse.RuleType() != engineapi.Validation && ruleResponse.RuleType() != engineapi.ImageVerify {
|
// if ruleResponse.RuleType() != engineapi.Validation && ruleResponse.RuleType() != engineapi.ImageVerify {
|
||||||
// continue
|
// continue
|
||||||
// }
|
// }
|
||||||
result, err := ComputePolicyReportResult(auditWarn, engineResponse, ruleResponse)
|
results[policy] = append(results[policy], ComputePolicyReportResult(auditWarn, engineResponse, ruleResponse))
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
results[policy] = append(results[policy], result)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
return nil, nil
|
return nil
|
||||||
}
|
}
|
||||||
return results, nil
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
func ComputePolicyReports(auditWarn bool, engineResponses ...engineapi.EngineResponse) ([]policyreportv1alpha2.ClusterPolicyReport, []policyreportv1alpha2.PolicyReport, error) {
|
func ComputePolicyReports(auditWarn bool, engineResponses ...engineapi.EngineResponse) ([]policyreportv1alpha2.ClusterPolicyReport, []policyreportv1alpha2.PolicyReport) {
|
||||||
var clustered []policyreportv1alpha2.ClusterPolicyReport
|
var clustered []policyreportv1alpha2.ClusterPolicyReport
|
||||||
var namespaced []policyreportv1alpha2.PolicyReport
|
var namespaced []policyreportv1alpha2.PolicyReport
|
||||||
perPolicyResults, err := ComputePolicyReportResultsPerPolicy(auditWarn, engineResponses...)
|
perPolicyResults := ComputePolicyReportResultsPerPolicy(auditWarn, engineResponses...)
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
for policy, results := range perPolicyResults {
|
for policy, results := range perPolicyResults {
|
||||||
if policy.GetNamespace() == "" {
|
if policy.GetNamespace() == "" {
|
||||||
report := policyreportv1alpha2.ClusterPolicyReport{
|
report := policyreportv1alpha2.ClusterPolicyReport{
|
||||||
|
@ -118,7 +108,7 @@ func ComputePolicyReports(auditWarn bool, engineResponses ...engineapi.EngineRes
|
||||||
namespaced = append(namespaced, report)
|
namespaced = append(namespaced, report)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return clustered, namespaced, nil
|
return clustered, namespaced
|
||||||
}
|
}
|
||||||
|
|
||||||
func MergeClusterReports(clustered []policyreportv1alpha2.ClusterPolicyReport) policyreportv1alpha2.ClusterPolicyReport {
|
func MergeClusterReports(clustered []policyreportv1alpha2.ClusterPolicyReport) policyreportv1alpha2.ClusterPolicyReport {
|
||||||
|
|
|
@ -34,8 +34,7 @@ func TestComputeClusterPolicyReports(t *testing.T) {
|
||||||
"validation rule 'pods-require-limits' passed.",
|
"validation rule 'pods-require-limits' passed.",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
clustered, namespaced, err := ComputePolicyReports(false, er)
|
clustered, namespaced := ComputePolicyReports(false, er)
|
||||||
assert.NilError(t, err)
|
|
||||||
assert.Equal(t, len(clustered), 1)
|
assert.Equal(t, len(clustered), 1)
|
||||||
assert.Equal(t, len(namespaced), 0)
|
assert.Equal(t, len(namespaced), 0)
|
||||||
{
|
{
|
||||||
|
@ -69,8 +68,7 @@ func TestComputePolicyReports(t *testing.T) {
|
||||||
"validation rule 'pods-require-limits' passed.",
|
"validation rule 'pods-require-limits' passed.",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
clustered, namespaced, err := ComputePolicyReports(false, er)
|
clustered, namespaced := ComputePolicyReports(false, er)
|
||||||
assert.NilError(t, err)
|
|
||||||
assert.Equal(t, len(clustered), 0)
|
assert.Equal(t, len(clustered), 0)
|
||||||
assert.Equal(t, len(namespaced), 1)
|
assert.Equal(t, len(namespaced), 1)
|
||||||
{
|
{
|
||||||
|
@ -104,8 +102,7 @@ func TestComputePolicyReportResultsPerPolicyOld(t *testing.T) {
|
||||||
"validation rule 'pods-require-limits' passed.",
|
"validation rule 'pods-require-limits' passed.",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
results, err := ComputePolicyReportResultsPerPolicy(false, er)
|
results := ComputePolicyReportResultsPerPolicy(false, er)
|
||||||
assert.NilError(t, err)
|
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
assert.Equal(t, len(result), 2)
|
assert.Equal(t, len(result), 2)
|
||||||
for _, r := range result {
|
for _, r := range result {
|
||||||
|
@ -274,8 +271,7 @@ func TestComputePolicyReportResult(t *testing.T) {
|
||||||
}}
|
}}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := ComputePolicyReportResult(tt.auditWarn, tt.engineResponse, tt.ruleResponse)
|
got := ComputePolicyReportResult(tt.auditWarn, tt.engineResponse, tt.ruleResponse)
|
||||||
assert.NilError(t, err)
|
|
||||||
got.Timestamp = metav1.Timestamp{}
|
got.Timestamp = metav1.Timestamp{}
|
||||||
if !reflect.DeepEqual(got, tt.want) {
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
t.Errorf("ComputePolicyReportResult() = %v, want %v", got, tt.want)
|
t.Errorf("ComputePolicyReportResult() = %v, want %v", got, tt.want)
|
||||||
|
@ -300,8 +296,7 @@ func TestComputePolicyReportResultsPerPolicy(t *testing.T) {
|
||||||
}}
|
}}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := ComputePolicyReportResultsPerPolicy(tt.auditWarn, tt.engineResponses...)
|
got := ComputePolicyReportResultsPerPolicy(tt.auditWarn, tt.engineResponses...)
|
||||||
assert.NilError(t, err)
|
|
||||||
if !reflect.DeepEqual(got, tt.want) {
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
t.Errorf("ComputePolicyReportResultsPerPolicy() = %v, want %v", got, tt.want)
|
t.Errorf("ComputePolicyReportResultsPerPolicy() = %v, want %v", got, tt.want)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Filter interface {
|
type Filter interface {
|
||||||
Apply(testapi.TestResults) bool
|
Apply(testapi.TestResult) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type policy struct {
|
type policy struct {
|
||||||
value string
|
value string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f policy) Apply(result testapi.TestResults) bool {
|
func (f policy) Apply(result testapi.TestResult) bool {
|
||||||
if result.Policy == "" {
|
if result.Policy == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ type rule struct {
|
||||||
value string
|
value string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f rule) Apply(result testapi.TestResults) bool {
|
func (f rule) Apply(result testapi.TestResult) bool {
|
||||||
if result.Rule == "" {
|
if result.Rule == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ type resource struct {
|
||||||
value string
|
value string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f resource) Apply(result testapi.TestResults) bool {
|
func (f resource) Apply(result testapi.TestResult) bool {
|
||||||
if result.Resource == "" {
|
if result.Resource == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ type composite struct {
|
||||||
filters []Filter
|
filters []Filter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f composite) Apply(result testapi.TestResults) bool {
|
func (f composite) Apply(result testapi.TestResult) bool {
|
||||||
for _, f := range f.filters {
|
for _, f := range f.filters {
|
||||||
if !f.Apply(result) {
|
if !f.Apply(result) {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -12,51 +12,51 @@ func Test_policy_Apply(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
value string
|
value string
|
||||||
result testapi.TestResults
|
result testapi.TestResult
|
||||||
want bool
|
want bool
|
||||||
}{{
|
}{{
|
||||||
name: "empty result",
|
name: "empty result",
|
||||||
value: "test",
|
value: "test",
|
||||||
result: testapi.TestResults{},
|
result: testapi.TestResult{},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "empty value",
|
name: "empty value",
|
||||||
value: "",
|
value: "",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Policy: "test",
|
TestResultBase: testapi.TestResultBase{Policy: "test"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
}, {
|
}, {
|
||||||
name: "empty value and result",
|
name: "empty value and result",
|
||||||
value: "",
|
value: "",
|
||||||
result: testapi.TestResults{},
|
result: testapi.TestResult{},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "match",
|
name: "match",
|
||||||
value: "test",
|
value: "test",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Policy: "test",
|
TestResultBase: testapi.TestResultBase{Policy: "test"},
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "no match",
|
name: "no match",
|
||||||
value: "test",
|
value: "test",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Policy: "not-test",
|
TestResultBase: testapi.TestResultBase{Policy: "not-test"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
}, {
|
}, {
|
||||||
name: "wildcard match",
|
name: "wildcard match",
|
||||||
value: "disallow-*",
|
value: "disallow-*",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Policy: "disallow-latest-tag",
|
TestResultBase: testapi.TestResultBase{Policy: "disallow-latest-tag"},
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "wildcard does not match",
|
name: "wildcard does not match",
|
||||||
value: "allow-*",
|
value: "allow-*",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Policy: "disallow-latest-tag",
|
TestResultBase: testapi.TestResultBase{Policy: "disallow-latest-tag"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
}}
|
}}
|
||||||
|
@ -76,51 +76,51 @@ func Test_rule_Apply(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
value string
|
value string
|
||||||
result testapi.TestResults
|
result testapi.TestResult
|
||||||
want bool
|
want bool
|
||||||
}{{
|
}{{
|
||||||
name: "empty result",
|
name: "empty result",
|
||||||
value: "test",
|
value: "test",
|
||||||
result: testapi.TestResults{},
|
result: testapi.TestResult{},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "empty value",
|
name: "empty value",
|
||||||
value: "",
|
value: "",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Rule: "test",
|
TestResultBase: testapi.TestResultBase{Rule: "test"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
}, {
|
}, {
|
||||||
name: "empty value and result",
|
name: "empty value and result",
|
||||||
value: "",
|
value: "",
|
||||||
result: testapi.TestResults{},
|
result: testapi.TestResult{},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "match",
|
name: "match",
|
||||||
value: "test",
|
value: "test",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Rule: "test",
|
TestResultBase: testapi.TestResultBase{Rule: "test"},
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "no match",
|
name: "no match",
|
||||||
value: "test",
|
value: "test",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Rule: "not-test",
|
TestResultBase: testapi.TestResultBase{Rule: "not-test"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
}, {
|
}, {
|
||||||
name: "wildcard match",
|
name: "wildcard match",
|
||||||
value: "*-image-tag",
|
value: "*-image-tag",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Rule: "validate-image-tag",
|
TestResultBase: testapi.TestResultBase{Rule: "validate-image-tag"},
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "wildcard does not match",
|
name: "wildcard does not match",
|
||||||
value: "require-*",
|
value: "require-*",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Rule: "validate-image-tag",
|
TestResultBase: testapi.TestResultBase{Rule: "validate-image-tag"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
}}
|
}}
|
||||||
|
@ -140,51 +140,51 @@ func Test_resource_Apply(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
value string
|
value string
|
||||||
result testapi.TestResults
|
result testapi.TestResult
|
||||||
want bool
|
want bool
|
||||||
}{{
|
}{{
|
||||||
name: "empty result",
|
name: "empty result",
|
||||||
value: "test",
|
value: "test",
|
||||||
result: testapi.TestResults{},
|
result: testapi.TestResult{},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "empty value",
|
name: "empty value",
|
||||||
value: "",
|
value: "",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Resource: "test",
|
TestResultDeprecated: testapi.TestResultDeprecated{Resource: "test"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
}, {
|
}, {
|
||||||
name: "empty value and result",
|
name: "empty value and result",
|
||||||
value: "",
|
value: "",
|
||||||
result: testapi.TestResults{},
|
result: testapi.TestResult{},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "match",
|
name: "match",
|
||||||
value: "test",
|
value: "test",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Resource: "test",
|
TestResultDeprecated: testapi.TestResultDeprecated{Resource: "test"},
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "no match",
|
name: "no match",
|
||||||
value: "test",
|
value: "test",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Resource: "not-test",
|
TestResultDeprecated: testapi.TestResultDeprecated{Resource: "not-test"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
}, {
|
}, {
|
||||||
name: "wildcard match",
|
name: "wildcard match",
|
||||||
value: "good*01",
|
value: "good*01",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Resource: "good-deployment-01",
|
TestResultDeprecated: testapi.TestResultDeprecated{Resource: "good-deployment-01"},
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "wildcard does not match",
|
name: "wildcard does not match",
|
||||||
value: "good*01",
|
value: "good*01",
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Resource: "bad-deployment-01",
|
TestResultDeprecated: testapi.TestResultDeprecated{Resource: "bad-deployment-01"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
}}
|
}}
|
||||||
|
@ -204,46 +204,46 @@ func Test_composite_Apply(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
filters []Filter
|
filters []Filter
|
||||||
result testapi.TestResults
|
result testapi.TestResult
|
||||||
want bool
|
want bool
|
||||||
}{{
|
}{{
|
||||||
name: "nil",
|
name: "nil",
|
||||||
filters: nil,
|
filters: nil,
|
||||||
result: testapi.TestResults{},
|
result: testapi.TestResult{},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "empty",
|
name: "empty",
|
||||||
filters: []Filter{},
|
filters: []Filter{},
|
||||||
result: testapi.TestResults{},
|
result: testapi.TestResult{},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "policy match",
|
name: "policy match",
|
||||||
filters: []Filter{policy{"test"}},
|
filters: []Filter{policy{"test"}},
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Policy: "test",
|
TestResultBase: testapi.TestResultBase{Policy: "test"},
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "policy no match",
|
name: "policy no match",
|
||||||
filters: []Filter{policy{"test"}},
|
filters: []Filter{policy{"test"}},
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Policy: "not-test",
|
TestResultBase: testapi.TestResultBase{Policy: "not-test"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
}, {
|
}, {
|
||||||
name: "policy and resource match",
|
name: "policy and resource match",
|
||||||
filters: []Filter{policy{"test"}, resource{"resource"}},
|
filters: []Filter{policy{"test"}, resource{"resource"}},
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Policy: "test",
|
TestResultBase: testapi.TestResultBase{Policy: "test"},
|
||||||
Resource: "resource",
|
TestResultDeprecated: testapi.TestResultDeprecated{Resource: "resource"},
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
}, {
|
}, {
|
||||||
name: "policy match and resource no match",
|
name: "policy match and resource no match",
|
||||||
filters: []Filter{policy{"test"}, resource{"resource"}},
|
filters: []Filter{policy{"test"}, resource{"resource"}},
|
||||||
result: testapi.TestResults{
|
result: testapi.TestResult{
|
||||||
Policy: "test",
|
TestResultBase: testapi.TestResultBase{Policy: "test"},
|
||||||
Resource: "not-resource",
|
TestResultDeprecated: testapi.TestResultDeprecated{Resource: "not-resource"},
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
|
|
|
@ -50,18 +50,22 @@ func TestLoadTests(t *testing.T) {
|
||||||
Name: "test-registry",
|
Name: "test-registry",
|
||||||
Policies: []string{"image-example.yaml"},
|
Policies: []string{"image-example.yaml"},
|
||||||
Resources: []string{"resources.yaml"},
|
Resources: []string{"resources.yaml"},
|
||||||
Results: []testapi.TestResults{{
|
Results: []testapi.TestResult{{
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Policy: "images",
|
Policy: "images",
|
||||||
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
|
Rule: "only-allow-trusted-images",
|
||||||
|
},
|
||||||
Resources: []string{"test-pod-with-non-root-user-image"},
|
Resources: []string{"test-pod-with-non-root-user-image"},
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
|
||||||
Rule: "only-allow-trusted-images",
|
|
||||||
}, {
|
}, {
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Policy: "images",
|
Policy: "images",
|
||||||
Resources: []string{"test-pod-with-trusted-registry"},
|
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
Rule: "only-allow-trusted-images",
|
Rule: "only-allow-trusted-images",
|
||||||
|
},
|
||||||
|
Resources: []string{"test-pod-with-trusted-registry"},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
|
@ -76,20 +80,24 @@ func TestLoadTests(t *testing.T) {
|
||||||
Name: "add-quota",
|
Name: "add-quota",
|
||||||
Policies: []string{"policy.yaml"},
|
Policies: []string{"policy.yaml"},
|
||||||
Resources: []string{"resource.yaml"},
|
Resources: []string{"resource.yaml"},
|
||||||
Results: []testapi.TestResults{{
|
Results: []testapi.TestResult{{
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Namespace",
|
Kind: "Namespace",
|
||||||
Policy: "add-ns-quota",
|
Policy: "add-ns-quota",
|
||||||
Resources: []string{"hello-world-namespace"},
|
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
Rule: "generate-resourcequota",
|
Rule: "generate-resourcequota",
|
||||||
GeneratedResource: "generatedResourceQuota.yaml",
|
GeneratedResource: "generatedResourceQuota.yaml",
|
||||||
|
},
|
||||||
|
Resources: []string{"hello-world-namespace"},
|
||||||
}, {
|
}, {
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Namespace",
|
Kind: "Namespace",
|
||||||
Policy: "add-ns-quota",
|
Policy: "add-ns-quota",
|
||||||
Resources: []string{"hello-world-namespace"},
|
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
Rule: "generate-limitrange",
|
Rule: "generate-limitrange",
|
||||||
GeneratedResource: "generatedLimitRange.yaml",
|
GeneratedResource: "generatedLimitRange.yaml",
|
||||||
|
},
|
||||||
|
Resources: []string{"hello-world-namespace"},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
|
@ -104,18 +112,22 @@ func TestLoadTests(t *testing.T) {
|
||||||
Name: "test-registry",
|
Name: "test-registry",
|
||||||
Policies: []string{"image-example.yaml"},
|
Policies: []string{"image-example.yaml"},
|
||||||
Resources: []string{"resources.yaml"},
|
Resources: []string{"resources.yaml"},
|
||||||
Results: []testapi.TestResults{{
|
Results: []testapi.TestResult{{
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Policy: "images",
|
Policy: "images",
|
||||||
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
|
Rule: "only-allow-trusted-images",
|
||||||
|
},
|
||||||
Resources: []string{"test-pod-with-non-root-user-image"},
|
Resources: []string{"test-pod-with-non-root-user-image"},
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
|
||||||
Rule: "only-allow-trusted-images",
|
|
||||||
}, {
|
}, {
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Policy: "images",
|
Policy: "images",
|
||||||
Resources: []string{"test-pod-with-trusted-registry"},
|
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
Rule: "only-allow-trusted-images",
|
Rule: "only-allow-trusted-images",
|
||||||
|
},
|
||||||
|
Resources: []string{"test-pod-with-trusted-registry"},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
@ -124,20 +136,24 @@ func TestLoadTests(t *testing.T) {
|
||||||
Name: "add-quota",
|
Name: "add-quota",
|
||||||
Policies: []string{"policy.yaml"},
|
Policies: []string{"policy.yaml"},
|
||||||
Resources: []string{"resource.yaml"},
|
Resources: []string{"resource.yaml"},
|
||||||
Results: []testapi.TestResults{{
|
Results: []testapi.TestResult{{
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Namespace",
|
Kind: "Namespace",
|
||||||
Policy: "add-ns-quota",
|
Policy: "add-ns-quota",
|
||||||
Resources: []string{"hello-world-namespace"},
|
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
Rule: "generate-resourcequota",
|
Rule: "generate-resourcequota",
|
||||||
GeneratedResource: "generatedResourceQuota.yaml",
|
GeneratedResource: "generatedResourceQuota.yaml",
|
||||||
|
},
|
||||||
|
Resources: []string{"hello-world-namespace"},
|
||||||
}, {
|
}, {
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Namespace",
|
Kind: "Namespace",
|
||||||
Policy: "add-ns-quota",
|
Policy: "add-ns-quota",
|
||||||
Resources: []string{"hello-world-namespace"},
|
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
Rule: "generate-limitrange",
|
Rule: "generate-limitrange",
|
||||||
GeneratedResource: "generatedLimitRange.yaml",
|
GeneratedResource: "generatedLimitRange.yaml",
|
||||||
|
},
|
||||||
|
Resources: []string{"hello-world-namespace"},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
|
@ -185,18 +201,22 @@ func TestLoadTest(t *testing.T) {
|
||||||
Name: "test-registry",
|
Name: "test-registry",
|
||||||
Policies: []string{"image-example.yaml"},
|
Policies: []string{"image-example.yaml"},
|
||||||
Resources: []string{"resources.yaml"},
|
Resources: []string{"resources.yaml"},
|
||||||
Results: []testapi.TestResults{{
|
Results: []testapi.TestResult{{
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Policy: "images",
|
Policy: "images",
|
||||||
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
|
Rule: "only-allow-trusted-images",
|
||||||
|
},
|
||||||
Resources: []string{"test-pod-with-non-root-user-image"},
|
Resources: []string{"test-pod-with-non-root-user-image"},
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
|
||||||
Rule: "only-allow-trusted-images",
|
|
||||||
}, {
|
}, {
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Policy: "images",
|
Policy: "images",
|
||||||
Resources: []string{"test-pod-with-trusted-registry"},
|
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
Rule: "only-allow-trusted-images",
|
Rule: "only-allow-trusted-images",
|
||||||
|
},
|
||||||
|
Resources: []string{"test-pod-with-trusted-registry"},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -209,18 +229,22 @@ func TestLoadTest(t *testing.T) {
|
||||||
Name: "test-registry",
|
Name: "test-registry",
|
||||||
Policies: []string{"image-example.yaml"},
|
Policies: []string{"image-example.yaml"},
|
||||||
Resources: []string{"resources.yaml"},
|
Resources: []string{"resources.yaml"},
|
||||||
Results: []testapi.TestResults{{
|
Results: []testapi.TestResult{{
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Policy: "images",
|
Policy: "images",
|
||||||
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
|
Rule: "only-allow-trusted-images",
|
||||||
|
},
|
||||||
Resources: []string{"test-pod-with-non-root-user-image"},
|
Resources: []string{"test-pod-with-non-root-user-image"},
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
|
||||||
Rule: "only-allow-trusted-images",
|
|
||||||
}, {
|
}, {
|
||||||
|
TestResultBase: testapi.TestResultBase{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
Policy: "images",
|
Policy: "images",
|
||||||
Resources: []string{"test-pod-with-trusted-registry"},
|
|
||||||
Result: policyreportv1alpha2.StatusPass,
|
Result: policyreportv1alpha2.StatusPass,
|
||||||
Rule: "only-allow-trusted-images",
|
Rule: "only-allow-trusted-images",
|
||||||
|
},
|
||||||
|
Resources: []string{"test-pod-with-trusted-registry"},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,9 +6,8 @@ resources:
|
||||||
results:
|
results:
|
||||||
- generatedResource: generatedResource.yaml
|
- generatedResource: generatedResource.yaml
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
namespace: hello-world
|
|
||||||
policy: create-default-pdb
|
policy: create-default-pdb
|
||||||
resources:
|
resources:
|
||||||
- nginx-deployment
|
- hello-world/nginx-deployment
|
||||||
result: pass
|
result: pass
|
||||||
rule: create-default-pdb
|
rule: create-default-pdb
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
name: connection-draining
|
name: connection-draining
|
||||||
policies:
|
policies:
|
||||||
- policy.yaml
|
- policy.yaml
|
||||||
resources:
|
resources:
|
||||||
- resource.yaml
|
- resource.yaml
|
||||||
results:
|
results:
|
||||||
- policy: disable-connection-draining
|
- kind: Service
|
||||||
rule: clb
|
policy: disable-connection-draining
|
||||||
resource: nlb-aws-controller-no-attributes
|
resources:
|
||||||
kind: Service
|
- nlb-aws-controller-no-attributes
|
||||||
result: skip
|
result: skip
|
||||||
- policy: disable-connection-draining
|
rule: clb
|
||||||
rule: nlb-no-attributes
|
- kind: Service
|
||||||
patchedResource: patched.yaml
|
patchedResource: patched.yaml
|
||||||
resource: nlb-aws-controller-no-attributes
|
policy: disable-connection-draining
|
||||||
kind: Service
|
resources:
|
||||||
|
- nlb-aws-controller-no-attributes
|
||||||
result: pass
|
result: pass
|
||||||
|
rule: nlb-no-attributes
|
||||||
|
|
|
@ -5,27 +5,10 @@ resources:
|
||||||
- resource.yaml
|
- resource.yaml
|
||||||
results:
|
results:
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: practice
|
|
||||||
patchedResource: patchedResource1.yaml
|
|
||||||
policy: add-label
|
|
||||||
resources:
|
|
||||||
- resource-equal-to-patch-res-for-cp
|
|
||||||
result: skip
|
|
||||||
rule: add-label
|
|
||||||
- kind: Pod
|
|
||||||
namespace: testing
|
|
||||||
patchedResource: patchedResource2.yaml
|
|
||||||
policy: add-label
|
|
||||||
resources:
|
|
||||||
- same-name-but-diff-namespace
|
|
||||||
result: pass
|
|
||||||
rule: add-label
|
|
||||||
- kind: Pod
|
|
||||||
namespace: production
|
|
||||||
patchedResource: patchedResource3.yaml
|
patchedResource: patchedResource3.yaml
|
||||||
policy: add-label
|
policy: add-label
|
||||||
resources:
|
resources:
|
||||||
- same-name-but-diff-namespace
|
- production/same-name-but-diff-namespace
|
||||||
result: pass
|
result: pass
|
||||||
rule: add-label
|
rule: add-label
|
||||||
- kind: Deployment
|
- kind: Deployment
|
||||||
|
@ -35,13 +18,6 @@ results:
|
||||||
- mydeploy
|
- mydeploy
|
||||||
result: pass
|
result: pass
|
||||||
rule: add-label
|
rule: add-label
|
||||||
# - kind: Service
|
|
||||||
# patchedResource: patchedResource5.yaml
|
|
||||||
# policy: add-label
|
|
||||||
# resources:
|
|
||||||
# - same-name-but-diff-kind
|
|
||||||
# result: skip
|
|
||||||
# rule: add-label
|
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
patchedResource: patchedResource6.yaml
|
patchedResource: patchedResource6.yaml
|
||||||
policy: add-label
|
policy: add-label
|
||||||
|
@ -49,51 +25,13 @@ results:
|
||||||
- same-name-but-diff-kind
|
- same-name-but-diff-kind
|
||||||
result: pass
|
result: pass
|
||||||
rule: add-label
|
rule: add-label
|
||||||
# - kind: Pod
|
|
||||||
# namespace: practice
|
|
||||||
# patchedResource: patchedResource7.yaml
|
|
||||||
# policy: add-ndots
|
|
||||||
# resources:
|
|
||||||
# - resource-equal-to-patch-res-for-cp
|
|
||||||
# result: skip
|
|
||||||
# rule: add-ndots
|
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: testing
|
|
||||||
patchedResource: patchedResource8.yaml
|
patchedResource: patchedResource8.yaml
|
||||||
policy: add-ndots
|
policy: testing/add-ndots
|
||||||
resources:
|
resources:
|
||||||
- same-name-but-diff-namespace
|
- same-name-but-diff-namespace
|
||||||
result: pass
|
result: pass
|
||||||
rule: add-ndots
|
rule: add-ndots
|
||||||
# - kind: Pod
|
|
||||||
# namespace: production
|
|
||||||
# patchedResource: patchedResource9.yaml
|
|
||||||
# policy: add-ndots
|
|
||||||
# resources:
|
|
||||||
# - same-name-but-diff-namespace
|
|
||||||
# result: skip
|
|
||||||
# rule: add-ndots
|
|
||||||
# - kind: Deployment
|
|
||||||
# patchedResource: patchedResource10.yaml
|
|
||||||
# policy: add-ndots
|
|
||||||
# resources:
|
|
||||||
# - mydeploy
|
|
||||||
# result: skip
|
|
||||||
# rule: add-ndots
|
|
||||||
# - kind: Service
|
|
||||||
# patchedResource: patchedResource5.yaml
|
|
||||||
# policy: add-ndots
|
|
||||||
# resources:
|
|
||||||
# - same-name-but-diff-kind
|
|
||||||
# result: skip
|
|
||||||
# rule: add-ndots
|
|
||||||
# - kind: Pod
|
|
||||||
# patchedResource: patchedResource11.yaml
|
|
||||||
# policy: add-ndots
|
|
||||||
# resources:
|
|
||||||
# - same-name-but-diff-kind
|
|
||||||
# result: skip
|
|
||||||
# rule: add-ndots
|
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
patchedResource: patched-resource.yaml
|
patchedResource: patched-resource.yaml
|
||||||
policy: example
|
policy: example
|
||||||
|
@ -101,3 +39,17 @@ results:
|
||||||
- example
|
- example
|
||||||
result: pass
|
result: pass
|
||||||
rule: object_from_lists
|
rule: object_from_lists
|
||||||
|
- kind: Pod
|
||||||
|
patchedResource: patchedResource1.yaml
|
||||||
|
policy: add-label
|
||||||
|
resources:
|
||||||
|
- practice/resource-equal-to-patch-res-for-cp
|
||||||
|
result: skip
|
||||||
|
rule: add-label
|
||||||
|
- kind: Pod
|
||||||
|
patchedResource: patchedResource2.yaml
|
||||||
|
policy: add-label
|
||||||
|
resources:
|
||||||
|
- testing/same-name-but-diff-namespace
|
||||||
|
result: pass
|
||||||
|
rule: add-label
|
||||||
|
|
|
@ -5,24 +5,9 @@ resources:
|
||||||
- resource.yaml
|
- resource.yaml
|
||||||
results:
|
results:
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: namespace1
|
|
||||||
policy: disallow-protected-namespaces
|
policy: disallow-protected-namespaces
|
||||||
resources:
|
resources:
|
||||||
- test1
|
- namespace2/test2
|
||||||
|
- namespace1/test1
|
||||||
result: fail
|
result: fail
|
||||||
rule: disallow
|
rule: disallow
|
||||||
- kind: Pod
|
|
||||||
namespace: namespace2
|
|
||||||
policy: disallow-protected-namespaces
|
|
||||||
resources:
|
|
||||||
- test2
|
|
||||||
result: fail
|
|
||||||
rule: disallow
|
|
||||||
# TODO CEB FIX
|
|
||||||
# - kind: Pod
|
|
||||||
# namespace: namespace3
|
|
||||||
# policy: disallow-protected-namespaces
|
|
||||||
# resources:
|
|
||||||
# - test3
|
|
||||||
# result: skip
|
|
||||||
# rule: disallow
|
|
||||||
|
|
|
@ -5,10 +5,9 @@ resources:
|
||||||
- resource.yaml
|
- resource.yaml
|
||||||
results:
|
results:
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: test1
|
|
||||||
policy: enforce-pod-name
|
policy: enforce-pod-name
|
||||||
resources:
|
resources:
|
||||||
- test-nginx
|
- test1/test-nginx
|
||||||
result: pass
|
result: pass
|
||||||
rule: validate-name
|
rule: validate-name
|
||||||
variables: value.yaml
|
variables: value.yaml
|
||||||
|
|
|
@ -5,10 +5,9 @@ resources:
|
||||||
- resource.yaml
|
- resource.yaml
|
||||||
results:
|
results:
|
||||||
- kind: PodExecOptions
|
- kind: PodExecOptions
|
||||||
namespace: default
|
|
||||||
policy: deny-exec-by-pod-label
|
policy: deny-exec-by-pod-label
|
||||||
resources:
|
resources:
|
||||||
- execpod
|
- default/execpod
|
||||||
result: fail
|
result: fail
|
||||||
rule: deny-exec-by-label
|
rule: deny-exec-by-label
|
||||||
values:
|
values:
|
||||||
|
|
|
@ -5,16 +5,14 @@ resources:
|
||||||
- resources.yaml
|
- resources.yaml
|
||||||
results:
|
results:
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: test
|
|
||||||
policy: require-image-digest
|
policy: require-image-digest
|
||||||
resources:
|
resources:
|
||||||
- no-digest
|
- test/no-digest
|
||||||
result: fail
|
result: fail
|
||||||
rule: check-digest
|
rule: check-digest
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: test
|
|
||||||
policy: require-image-digest
|
policy: require-image-digest
|
||||||
resources:
|
resources:
|
||||||
- with-digest
|
- test/with-digest
|
||||||
result: pass
|
result: pass
|
||||||
rule: check-digest
|
rule: check-digest
|
||||||
|
|
|
@ -5,7 +5,7 @@ resources:
|
||||||
- resources.yaml
|
- resources.yaml
|
||||||
results:
|
results:
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
policy: test-jmespath
|
policy: default/test-jmespath
|
||||||
resources:
|
resources:
|
||||||
- test-valid1
|
- test-valid1
|
||||||
- test-valid2
|
- test-valid2
|
||||||
|
@ -13,7 +13,7 @@ results:
|
||||||
result: pass
|
result: pass
|
||||||
rule: test-jmespath
|
rule: test-jmespath
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
policy: test-jmespath
|
policy: default/test-jmespath
|
||||||
resources:
|
resources:
|
||||||
- test-invalid
|
- test-invalid
|
||||||
result: fail
|
result: fail
|
||||||
|
|
|
@ -2,6 +2,7 @@ apiVersion: kyverno.io/v1
|
||||||
kind: Policy
|
kind: Policy
|
||||||
metadata:
|
metadata:
|
||||||
name: test-jmespath
|
name: test-jmespath
|
||||||
|
namespace: default
|
||||||
annotations:
|
annotations:
|
||||||
pod-policies.kyverno.io/autogen-controllers: none
|
pod-policies.kyverno.io/autogen-controllers: none
|
||||||
spec:
|
spec:
|
||||||
|
|
|
@ -5,16 +5,15 @@ resources:
|
||||||
- resource.yaml
|
- resource.yaml
|
||||||
results:
|
results:
|
||||||
- kind: ConfigMap
|
- kind: ConfigMap
|
||||||
namespace: any-namespace
|
|
||||||
policy: limit-configmap-for-sa
|
policy: limit-configmap-for-sa
|
||||||
resources:
|
resources:
|
||||||
- any-configmap-name-good
|
- any-namespace/any-configmap-name-good
|
||||||
result: fail
|
result: fail
|
||||||
rule: limit-configmap-for-sa-developer
|
rule: limit-configmap-for-sa-developer
|
||||||
- kind: ConfigMap
|
- kind: ConfigMap
|
||||||
policy: limit-configmap-for-sa
|
policy: limit-configmap-for-sa
|
||||||
resources:
|
resources:
|
||||||
- any-configmap-name-bad
|
- any-namespace/any-configmap-name-bad
|
||||||
result: skip
|
result: skip
|
||||||
rule: limit-configmap-for-sa-developer
|
rule: limit-configmap-for-sa-developer
|
||||||
variables: variables.yaml
|
variables: variables.yaml
|
||||||
|
|
|
@ -5,33 +5,21 @@ resources:
|
||||||
- resource.yaml
|
- resource.yaml
|
||||||
results:
|
results:
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: user-space
|
policy: ondemand
|
||||||
|
resources:
|
||||||
|
- user-foo/nodeselector-without-labels-on-mutation
|
||||||
|
result: fail
|
||||||
|
rule: ondemand-managed_by
|
||||||
|
- kind: Pod
|
||||||
patchedResource: patched-resource.yaml
|
patchedResource: patched-resource.yaml
|
||||||
policy: ondemand
|
policy: ondemand
|
||||||
resources:
|
resources:
|
||||||
- nodeselector-with-labels-on-mutation
|
- user-space/nodeselector-with-labels-on-mutation
|
||||||
result: pass
|
result: pass
|
||||||
rule: ondemand-nodeselector
|
rule: ondemand-nodeselector
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: user-space
|
|
||||||
policy: ondemand
|
policy: ondemand
|
||||||
resources:
|
resources:
|
||||||
- nodeselector-with-labels-on-mutation
|
- user-space/nodeselector-with-labels-on-mutation
|
||||||
result: pass
|
result: pass
|
||||||
rule: ondemand-managed_by
|
rule: ondemand-managed_by
|
||||||
# TODO CEB FIX
|
|
||||||
# - kind: Pod
|
|
||||||
# namespace: user-foo
|
|
||||||
# patchedResource: patched-resource1.yaml
|
|
||||||
# policy: ondemand
|
|
||||||
# resources:
|
|
||||||
# - nodeselector-without-labels-on-mutation
|
|
||||||
# result: skip
|
|
||||||
# rule: ondemand-nodeselector
|
|
||||||
- kind: Pod
|
|
||||||
namespace: user-foo
|
|
||||||
policy: ondemand
|
|
||||||
resources:
|
|
||||||
- nodeselector-without-labels-on-mutation
|
|
||||||
result: fail
|
|
||||||
rule: ondemand-managed_by
|
|
||||||
|
|
|
@ -5,10 +5,9 @@ resources:
|
||||||
- resource.yaml
|
- resource.yaml
|
||||||
results:
|
results:
|
||||||
- kind: Scale
|
- kind: Scale
|
||||||
namespace: default
|
|
||||||
policy: enforce-replicas-for-scale-subresource
|
policy: enforce-replicas-for-scale-subresource
|
||||||
resources:
|
resources:
|
||||||
- nginx-test
|
- default/nginx-test
|
||||||
result: fail
|
result: fail
|
||||||
rule: validate-nginx-test
|
rule: validate-nginx-test
|
||||||
variables: values.yaml
|
variables: values.yaml
|
||||||
|
|
|
@ -5,76 +5,62 @@ resources:
|
||||||
- resources.yaml
|
- resources.yaml
|
||||||
results:
|
results:
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: test
|
policy: disallow-latest-tag
|
||||||
|
resources:
|
||||||
|
- test/test-validate-image-tag-fail
|
||||||
|
result: fail
|
||||||
|
rule: validate-image-tag
|
||||||
|
- kind: Pod
|
||||||
policy: duration-test
|
policy: duration-test
|
||||||
resources:
|
resources:
|
||||||
- test-lifetime-fail
|
- test/test-lifetime-fail
|
||||||
result: fail
|
result: fail
|
||||||
rule: greater-than
|
rule: greater-than
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: test
|
policy: disallow-latest-tag
|
||||||
|
resources:
|
||||||
|
- test/test-validate-image-tag-pass
|
||||||
|
result: pass
|
||||||
|
rule: validate-image-tag
|
||||||
|
- kind: Pod
|
||||||
policy: duration-test
|
policy: duration-test
|
||||||
resources:
|
resources:
|
||||||
- test-lifetime-fail
|
- test/test-lifetime-fail
|
||||||
|
result: pass
|
||||||
|
rule: less-equal-than
|
||||||
|
- kind: Pod
|
||||||
|
policy: disallow-latest-tag
|
||||||
|
resources:
|
||||||
|
- test/test-require-image-tag-pass
|
||||||
|
result: pass
|
||||||
|
rule: require-image-tag
|
||||||
|
- kind: Pod
|
||||||
|
policy: disallow-latest-tag
|
||||||
|
resources:
|
||||||
|
- test/test-require-image-tag-fail
|
||||||
|
result: fail
|
||||||
|
rule: require-image-tag
|
||||||
|
- kind: Pod
|
||||||
|
policy: duration-test
|
||||||
|
resources:
|
||||||
|
- test/test-lifetime-fail
|
||||||
result: pass
|
result: pass
|
||||||
rule: less-than
|
rule: less-than
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
namespace: test
|
|
||||||
policy: duration-test
|
policy: duration-test
|
||||||
resources:
|
resources:
|
||||||
- test-lifetime-fail
|
- test/test-lifetime-fail
|
||||||
result: fail
|
result: fail
|
||||||
rule: greater-equal-than
|
rule: greater-equal-than
|
||||||
- kind: Pod
|
|
||||||
namespace: test
|
|
||||||
policy: restrict-pod-counts
|
|
||||||
resources:
|
|
||||||
- test-require-image-tag-pass
|
|
||||||
- test-require-image-tag-fail
|
|
||||||
- test-validate-image-tag-fail
|
|
||||||
- test-validate-image-tag-pass
|
|
||||||
result: fail
|
|
||||||
rule: restrict-pod-count
|
|
||||||
- kind: Pod
|
|
||||||
namespace: test
|
|
||||||
policy: disallow-latest-tag
|
|
||||||
resources:
|
|
||||||
- test-require-image-tag-pass
|
|
||||||
result: pass
|
|
||||||
rule: require-image-tag
|
|
||||||
- kind: Pod
|
|
||||||
namespace: test
|
|
||||||
policy: disallow-latest-tag
|
|
||||||
resources:
|
|
||||||
- test-require-image-tag-fail
|
|
||||||
result: fail
|
|
||||||
rule: require-image-tag
|
|
||||||
- kind: Pod
|
|
||||||
namespace: test
|
|
||||||
policy: disallow-latest-tag
|
|
||||||
resources:
|
|
||||||
- test-validate-image-tag-pass
|
|
||||||
result: pass
|
|
||||||
rule: validate-image-tag
|
|
||||||
- kind: Pod
|
|
||||||
namespace: test
|
|
||||||
policy: disallow-latest-tag
|
|
||||||
resources:
|
|
||||||
- test-validate-image-tag-fail
|
|
||||||
result: fail
|
|
||||||
rule: validate-image-tag
|
|
||||||
- kind: Pod
|
|
||||||
namespace: test
|
|
||||||
policy: duration-test
|
|
||||||
resources:
|
|
||||||
- test-lifetime-fail
|
|
||||||
result: pass
|
|
||||||
rule: less-equal-than
|
|
||||||
- kind: Pod
|
- kind: Pod
|
||||||
policy: restrict-pod-counts
|
policy: restrict-pod-counts
|
||||||
resources:
|
resources:
|
||||||
- myapp-pod
|
- myapp-pod
|
||||||
- test-validate-image-tag-ignore
|
- test-validate-image-tag-ignore
|
||||||
|
- test/test-require-image-tag-pass
|
||||||
|
- test/test-require-image-tag-fail
|
||||||
|
- test/test-validate-image-tag-fail
|
||||||
|
- test/test-validate-image-tag-pass
|
||||||
result: fail
|
result: fail
|
||||||
rule: restrict-pod-count
|
rule: restrict-pod-count
|
||||||
variables: values.yaml
|
variables: values.yaml
|
||||||
|
|
Loading…
Add table
Reference in a new issue