mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
added validation - resource not found in cluster
This commit is contained in:
parent
2b979fec4d
commit
cd5609fd58
3 changed files with 9 additions and 20 deletions
|
@ -6,16 +6,4 @@ Apply Command - Valid Parameter Combinations and their interpretation!
|
|||
| 2. | policy.yaml | -r resourceName | true | | apply policy from file to the resource in cluster |
|
||||
| 3. | policy.yaml | | true | | apply policy from file to all the resources in cluster |
|
||||
| 4. | policy.yaml | -r resourceName | true | -n=namespace | apply policy from file to the resource in cluster in mentioned namespace |
|
||||
| 5. | policy.yaml | | true | -n=namespace | apply policy from file to all the resources in cluster in mentioned namespace |
|
||||
| 6. | policyName | -r resourceName | true | | apply policy from cluster to the resource in cluster |
|
||||
| 7. | policyName | | true | | apply polify from cluster to all the resouces in cluster |
|
||||
| 8. | policyName | -r resourceName | true | -n=namespace | apply policy from cluster to the resource in cluster in mentioned namespace |
|
||||
| 9. | policyName | | true | -n=namespace | apply polify from cluster to all the resouces in cluster in mentioned namespace |
|
||||
| 10. | | -r resourceName | true | | applying all policies from the cluster to resouce in cluster |
|
||||
| 11. | | -r resourceName | true | -n=namespace | applying all policies from the cluster to resouce in cluster in mentioned namespace |
|
||||
| 12. | | | true | | applying all policies from the cluster to all resouces in cluster |
|
||||
| 13. | | | true | | applying all policies from the cluster to all resouces in cluster in mentioned namespace |
|
||||
|
||||
|
||||
|
||||
|
||||
| 5. | policy.yaml | | true | -n=namespace | apply policy from file to all the resources in cluster in mentioned namespace |
|
|
@ -301,7 +301,7 @@ func printReportOrViolation(policyReport bool, engineResponses []response.Engine
|
|||
if policyReport {
|
||||
resps := buildPolicyReports(engineResponses)
|
||||
if len(resps) > 0 {
|
||||
fmt.Println("----------------------------------------------------------------------\nPOLICY REPORT:")
|
||||
fmt.Println("----------------------------------------------------------------------\nPOLICY REPORT:\n----------------------------------------------------------------------")
|
||||
report, _ := generateCLIraw(resps)
|
||||
yamlReport, _ := yaml1.Marshal(report)
|
||||
fmt.Println(string(yamlReport))
|
||||
|
|
|
@ -3,8 +3,11 @@ package common
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/kyverno/kyverno/pkg/kyverno/sanitizedError"
|
||||
|
||||
v1 "github.com/kyverno/kyverno/pkg/api/kyverno/v1"
|
||||
"github.com/kyverno/kyverno/pkg/client/clientset/versioned/scheme"
|
||||
client "github.com/kyverno/kyverno/pkg/dclient"
|
||||
|
@ -53,14 +56,9 @@ func GetResources(policies []*v1.ClusterPolicy, resourcePaths []string, dClient
|
|||
}
|
||||
|
||||
for _, resourcePath := range resourcePaths {
|
||||
lenOfResource := len(resources)
|
||||
resourceBytes, err := getFileBytes(resourcePath)
|
||||
if err != nil {
|
||||
// check in the cluster for the given resource name
|
||||
// what if two resources have same name ?
|
||||
//r, err := getResourceFromCluster(resourceTypes, resourcePath, dClient)
|
||||
//if err != nil {
|
||||
|
||||
//}
|
||||
if cluster {
|
||||
for _, rm := range resourceMap {
|
||||
for rn, rr := range rm {
|
||||
|
@ -73,6 +71,9 @@ func GetResources(policies []*v1.ClusterPolicy, resourcePaths []string, dClient
|
|||
} else {
|
||||
return nil, err
|
||||
}
|
||||
if len(resources) <= lenOfResource {
|
||||
return nil, sanitizedError.NewWithError(fmt.Sprintf("resource %s not found in cluster", resourcePath), errors.New("resource not found"))
|
||||
}
|
||||
}
|
||||
|
||||
getResources, err := GetResource(resourceBytes)
|
||||
|
|
Loading…
Add table
Reference in a new issue