mirror of
https://github.com/kyverno/kyverno.git
synced 2025-04-16 09:16:24 +00:00
- remove resource info per rule; - add resource info in each failed admission request
This commit is contained in:
parent
42150f95da
commit
8496a483dc
3 changed files with 8 additions and 5 deletions
|
@ -36,7 +36,7 @@ func processOverlay(rule kyverno.Rule, resource unstructured.Unstructured) (resp
|
||||||
case conditionNotPresent:
|
case conditionNotPresent:
|
||||||
glog.Infof("Resource %s/%s/%s: %s", resource.GetKind(), resource.GetNamespace(), resource.GetName(), overlayerr.ErrorMsg())
|
glog.Infof("Resource %s/%s/%s: %s", resource.GetKind(), resource.GetNamespace(), resource.GetName(), overlayerr.ErrorMsg())
|
||||||
response.Success = true
|
response.Success = true
|
||||||
response.Message = fmt.Sprintf("Resource %s/%s/%s: %s.", resource.GetKind(), resource.GetNamespace(), resource.GetName(), overlayerr.ErrorMsg())
|
response.Message = overlayerr.ErrorMsg()
|
||||||
return response, resource
|
return response, resource
|
||||||
// conditions are not met, don't apply this rule
|
// conditions are not met, don't apply this rule
|
||||||
// consider as failure
|
// consider as failure
|
||||||
|
@ -44,7 +44,7 @@ func processOverlay(rule kyverno.Rule, resource unstructured.Unstructured) (resp
|
||||||
glog.Errorf("Resource %s/%s/%s does not meet the conditions in the rule %s with overlay pattern %s", resource.GetKind(), resource.GetNamespace(), resource.GetName(), rule.Name, rule.Mutation.Overlay)
|
glog.Errorf("Resource %s/%s/%s does not meet the conditions in the rule %s with overlay pattern %s", resource.GetKind(), resource.GetNamespace(), resource.GetName(), rule.Name, rule.Mutation.Overlay)
|
||||||
//TODO: send zero response and not consider this as applied?
|
//TODO: send zero response and not consider this as applied?
|
||||||
response.Success = false
|
response.Success = false
|
||||||
response.Message = fmt.Sprintf("Resource %s/%s/%s: %v.", resource.GetKind(), resource.GetNamespace(), resource.GetName(), overlayerr.ErrorMsg())
|
response.Message = overlayerr.ErrorMsg()
|
||||||
return response, resource
|
return response, resource
|
||||||
// rule application failed
|
// rule application failed
|
||||||
case overlayFailure:
|
case overlayFailure:
|
||||||
|
|
|
@ -3,10 +3,9 @@ package webhooks
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/nirmata/kyverno/pkg/engine"
|
|
||||||
|
|
||||||
jsonpatch "github.com/evanphx/json-patch"
|
jsonpatch "github.com/evanphx/json-patch"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
"github.com/nirmata/kyverno/pkg/engine"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -33,8 +33,12 @@ func toBlockResource(engineReponses []engine.EngineResponse) bool {
|
||||||
|
|
||||||
func getErrorMsg(engineReponses []engine.EngineResponse) string {
|
func getErrorMsg(engineReponses []engine.EngineResponse) string {
|
||||||
var str []string
|
var str []string
|
||||||
|
var resourceInfo string
|
||||||
|
|
||||||
for _, er := range engineReponses {
|
for _, er := range engineReponses {
|
||||||
if !er.IsSuccesful() {
|
if !er.IsSuccesful() {
|
||||||
|
// resource in engineReponses is identical as this was called per admission request
|
||||||
|
resourceInfo = fmt.Sprintf("%s/%s/%s", er.PolicyResponse.Resource.Kind, er.PolicyResponse.Resource.Namespace, er.PolicyResponse.Resource.Name)
|
||||||
str = append(str, fmt.Sprintf("failed policy %s", er.PolicyResponse.Policy))
|
str = append(str, fmt.Sprintf("failed policy %s", er.PolicyResponse.Policy))
|
||||||
for _, rule := range er.PolicyResponse.Rules {
|
for _, rule := range er.PolicyResponse.Rules {
|
||||||
if !rule.Success {
|
if !rule.Success {
|
||||||
|
@ -43,7 +47,7 @@ func getErrorMsg(engineReponses []engine.EngineResponse) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return strings.Join(str, "\n")
|
return fmt.Sprintf("Resource %s: %s", resourceInfo, strings.Join(str, "\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
//ArrayFlags to store filterkinds
|
//ArrayFlags to store filterkinds
|
||||||
|
|
Loading…
Add table
Reference in a new issue