mirror of
https://github.com/kyverno/kyverno.git
synced 2025-04-08 10:04:25 +00:00
removing error count
Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
This commit is contained in:
parent
36515ce127
commit
dce3663429
5 changed files with 9 additions and 42 deletions
|
@ -301,7 +301,7 @@ func applyCommandHelper(resourcePaths []string, cluster bool, policyReport bool,
|
|||
return validateEngineResponses, rc, resources, skippedPolicies, sanitizederror.NewWithError(fmt.Sprintf("policy %s have variables. pass the values for the variables using set/values_file flag", policy.Name), err)
|
||||
}
|
||||
|
||||
validateErs, responseError, rcErs, err := common.ApplyPolicyOnResource(policy, resource, mutateLogPath, mutateLogPathIsDir, thisPolicyResourceValues, policyReport, namespaceSelectorMap, stdin)
|
||||
validateErs, responseError, err := common.ApplyPolicyOnResource(policy, resource, mutateLogPath, mutateLogPathIsDir, thisPolicyResourceValues, policyReport, namespaceSelectorMap, stdin)
|
||||
if err != nil {
|
||||
return validateEngineResponses, rc, resources, skippedPolicies, sanitizederror.NewWithError(fmt.Errorf("failed to apply policy %v on resource %v", policy.Name, resource.GetName()).Error(), err)
|
||||
}
|
||||
|
@ -310,9 +310,7 @@ func applyCommandHelper(resourcePaths []string, cluster bool, policyReport bool,
|
|||
} else {
|
||||
rc.pass++
|
||||
}
|
||||
if rcErs == true {
|
||||
rc.error++
|
||||
}
|
||||
|
||||
validateEngineResponses = append(validateEngineResponses, validateErs)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,36 +25,6 @@ func buildPolicyReports(resps []*response.EngineResponse) (res []*unstructured.U
|
|||
var raw []byte
|
||||
var err error
|
||||
|
||||
// for _, sp := range skippedPolicies {
|
||||
// for _, r := range sp.Rules {
|
||||
// result := []*report.PolicyReportResult{
|
||||
// {
|
||||
// Message: fmt.Sprintln("skipped policy with variables -", sp.Variable),
|
||||
// Policy: sp.Name,
|
||||
// Rule: r.Name,
|
||||
// Result: "skip",
|
||||
// },
|
||||
// }
|
||||
// report := &report.PolicyReport{
|
||||
// TypeMeta: metav1.TypeMeta{
|
||||
// APIVersion: report.SchemeGroupVersion.String(),
|
||||
// Kind: "PolicyReport",
|
||||
// },
|
||||
// Results: result,
|
||||
// }
|
||||
// if raw, err = json.Marshal(report); err != nil {
|
||||
// log.Log.V(3).Info("failed to serialize policy report", "error", err)
|
||||
// continue
|
||||
// }
|
||||
// reportUnstructured, err := engineutils.ConvertToUnstructured(raw)
|
||||
// if err != nil {
|
||||
// log.Log.V(3).Info("failed to convert policy report", "error", err)
|
||||
// continue
|
||||
// }
|
||||
// res = append(res, reportUnstructured)
|
||||
// }
|
||||
// }
|
||||
|
||||
resultsMap := buildPolicyResults(resps)
|
||||
for scope, result := range resultsMap {
|
||||
if scope == clusterpolicyreport {
|
||||
|
|
|
@ -507,7 +507,7 @@ func MutatePolices(policies []*v1.ClusterPolicy) ([]*v1.ClusterPolicy, error) {
|
|||
|
||||
// ApplyPolicyOnResource - function to apply policy on resource
|
||||
func ApplyPolicyOnResource(policy *v1.ClusterPolicy, resource *unstructured.Unstructured,
|
||||
mutateLogPath string, mutateLogPathIsDir bool, variables map[string]string, policyReport bool, namespaceSelectorMap map[string]map[string]string, stdin bool) (*response.EngineResponse, bool, bool, error) {
|
||||
mutateLogPath string, mutateLogPathIsDir bool, variables map[string]string, policyReport bool, namespaceSelectorMap map[string]map[string]string, stdin bool) (*response.EngineResponse, bool, error) {
|
||||
|
||||
operationIsDelete := false
|
||||
|
||||
|
@ -516,7 +516,6 @@ func ApplyPolicyOnResource(policy *v1.ClusterPolicy, resource *unstructured.Unst
|
|||
}
|
||||
|
||||
responseError := false
|
||||
rcError := false
|
||||
engineResponses := make([]*response.EngineResponse, 0)
|
||||
namespaceLabels := make(map[string]string)
|
||||
|
||||
|
@ -533,7 +532,7 @@ func ApplyPolicyOnResource(policy *v1.ClusterPolicy, resource *unstructured.Unst
|
|||
resourceNamespace := resource.GetNamespace()
|
||||
namespaceLabels = namespaceSelectorMap[resource.GetNamespace()]
|
||||
if resourceNamespace != "default" && len(namespaceLabels) < 1 {
|
||||
return &response.EngineResponse{}, responseError, rcError, sanitizederror.NewWithError(fmt.Sprintf("failed to get namesapce labels for resource %s. use --values-file flag to pass the namespace labels", resource.GetName()), nil)
|
||||
return &response.EngineResponse{}, responseError, sanitizederror.NewWithError(fmt.Sprintf("failed to get namesapce labels for resource %s. use --values-file flag to pass the namespace labels", resource.GetName()), nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -573,7 +572,7 @@ func ApplyPolicyOnResource(policy *v1.ClusterPolicy, resource *unstructured.Unst
|
|||
if len(mutateResponse.PolicyResponse.Rules) > 0 {
|
||||
yamlEncodedResource, err := yamlv2.Marshal(mutateResponse.PatchedResource.Object)
|
||||
if err != nil {
|
||||
rcError = true
|
||||
return &response.EngineResponse{}, responseError, sanitizederror.NewWithError("failed to marshal", err)
|
||||
}
|
||||
|
||||
if mutateLogPath == "" {
|
||||
|
@ -588,7 +587,7 @@ func ApplyPolicyOnResource(policy *v1.ClusterPolicy, resource *unstructured.Unst
|
|||
} else {
|
||||
err := PrintMutatedOutput(mutateLogPath, mutateLogPathIsDir, string(yamlEncodedResource), resource.GetName()+"-mutated")
|
||||
if err != nil {
|
||||
return &response.EngineResponse{}, responseError, rcError, sanitizederror.NewWithError("failed to print mutated result", err)
|
||||
return &response.EngineResponse{}, responseError, sanitizederror.NewWithError("failed to print mutated result", err)
|
||||
}
|
||||
fmt.Printf("\n\nMutation:\nMutation has been applied successfully. Check the files.")
|
||||
}
|
||||
|
@ -651,7 +650,7 @@ func ApplyPolicyOnResource(policy *v1.ClusterPolicy, resource *unstructured.Unst
|
|||
}
|
||||
}
|
||||
|
||||
return validateResponse, responseError, rcError, nil
|
||||
return validateResponse, responseError, nil
|
||||
}
|
||||
|
||||
// PrintMutatedOutput - function to print output in provided file or directory
|
||||
|
|
|
@ -85,7 +85,7 @@ func Test_NamespaceSelector(t *testing.T) {
|
|||
for _, tc := range testcases {
|
||||
policyArray, _ := ut.GetPolicy(tc.policy)
|
||||
resourceArray, _ := GetResource(tc.resource)
|
||||
validateErs, _, _, _ := ApplyPolicyOnResource(policyArray[0], resourceArray[0], "", false, nil, false, tc.namespaceSelectorMap, false)
|
||||
validateErs, _, _ := ApplyPolicyOnResource(policyArray[0], resourceArray[0], "", false, nil, false, tc.namespaceSelectorMap, false)
|
||||
assert.Assert(t, tc.success == validateErs.IsSuccessful())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -394,7 +394,7 @@ func applyPoliciesFromPath(fs billy.Filesystem, policyBytes []byte, valuesFile s
|
|||
return sanitizederror.NewWithError(fmt.Sprintf("policy %s have variables. pass the values for the variables using set/values_file flag", policy.Name), err)
|
||||
}
|
||||
|
||||
validateErs, _, _, err := common.ApplyPolicyOnResource(policy, resource, "", false, thisPolicyResourceValues, true, namespaceSelectorMap, false)
|
||||
validateErs, _, err := common.ApplyPolicyOnResource(policy, resource, "", false, thisPolicyResourceValues, true, namespaceSelectorMap, false)
|
||||
if err != nil {
|
||||
return sanitizederror.NewWithError(fmt.Errorf("failed to apply policy %v on resource %v", policy.Name, resource.GetName()).Error(), err)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue