2019-07-26 15:54:42 -07:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/golang/glog"
|
2019-08-14 10:01:47 -07:00
|
|
|
kyverno "github.com/nirmata/kyverno/pkg/api/kyverno/v1alpha1"
|
2019-07-26 15:54:42 -07:00
|
|
|
)
|
|
|
|
|
2019-08-14 10:01:47 -07:00
|
|
|
func patchOverlay(rule kyverno.Rule, rawResource []byte) ([][]byte, error) {
|
2019-07-26 15:54:42 -07:00
|
|
|
var resource interface{}
|
|
|
|
if err := json.Unmarshal(rawResource, &resource); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resourceInfo := ParseResourceInfoFromObject(rawResource)
|
2019-08-14 10:01:47 -07:00
|
|
|
patches, err := processOverlayPatches(resource, rule.Mutation.Overlay)
|
2019-07-26 15:54:42 -07:00
|
|
|
if err != nil && strings.Contains(err.Error(), "Conditions are not met") {
|
|
|
|
glog.Infof("Resource does not meet conditions in overlay pattern, resource=%s, rule=%s\n", resourceInfo, rule.Name)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return patches, err
|
|
|
|
}
|