1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/pkg/engine/mutate/generatePatches.go
shuting 39de46fe39
983 kustomize support (#1026)
* prototype - strategic merge patch

* add end to end test

* add engine strategic merge patch support

* set webhook reinvocationPolicy to IfNeeded

* refactor engine mutate code

* support JMESPath in strategic merge patch

* implement patchesJson6902

* update doc

* resolve pr comments
2020-08-05 09:11:23 -07:00

27 lines
565 B
Go

package mutate
import (
"fmt"
"github.com/mattbaird/jsonpatch"
)
func generatePatches(src, dst []byte) ([][]byte, error) {
var patchesBytes [][]byte
pp, err := jsonpatch.CreatePatch(src, dst)
for _, p := range pp {
// TODO: handle remove nil value, i.e.,
// {remove /spec/securityContext <nil>}
// {remove /status/conditions/0/lastProbeTime <nil>}
pbytes, err := p.MarshalJSON()
if err != nil {
return patchesBytes, err
}
patchesBytes = append(patchesBytes, pbytes)
fmt.Printf("generated patch %s\n", p)
}
return patchesBytes, err
}