1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-04-08 10:04:25 +00:00

fix filtered and sort patches index ()

added missing start index value for the
patches slice

Signed-off-by: prateekpandey14 <prateekpandey14@gmail.com>
This commit is contained in:
Prateek Pandey 2022-02-02 02:46:08 +05:30 committed by GitHub
parent 25641abeb9
commit 286b0427d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 1 deletions

View file

@ -48,7 +48,7 @@ func filterAndSortPatches(originalPatches []jsonpatch.JsonPatchOperation) []json
start := 0
for _, idx := range index {
end := idx[0]
copy(result[start:end], patches[:end])
copy(result[start:end], patches[start:end])
reversedPatches := reverse(patches, idx)
copy(result[end:], reversedPatches)
start = idx[1] + 1

View file

@ -249,6 +249,60 @@ func Test_sortRemovalPatches(t *testing.T) {
patches: []jsonpatch.JsonPatchOperation{{Operation: "remove", Path: "/a/0"}, {Operation: "remove", Path: "/b/0"}, {Operation: "add", Path: "/b/c/0"}, {Operation: "remove", Path: "/b/1"}, {Operation: "remove", Path: "/c/0"}},
expected: []jsonpatch.JsonPatchOperation{{Operation: "remove", Path: "/a/0"}, {Operation: "remove", Path: "/b/0"}, {Operation: "add", Path: "/b/c/0"}, {Operation: "remove", Path: "/b/1"}, {Operation: "remove", Path: "/c/0"}},
},
{
patches: []jsonpatch.JsonPatchOperation{
{Operation: "remove", Path: "/spec/containers/0/args/7"},
{Operation: "remove", Path: "/spec/containers/0/args/6"},
{Operation: "remove", Path: "/spec/containers/0/args/5"},
{Operation: "remove", Path: "/spec/containers/0/args/4"},
{Operation: "remove", Path: "/spec/containers/0/args/3"},
{Operation: "remove", Path: "/spec/containers/0/args/2"},
{Operation: "remove", Path: "/spec/containers/0/args/1"},
{Operation: "remove", Path: "/spec/containers/0/args/0"},
{Operation: "add", Path: "/spec/containers/0/args/0", Value: "--logtostderr"},
{Operation: "add", Path: "/spec/containers/0/args/1", Value: "--secure-listen-address=[$(IP)]:9100"},
{Operation: "add", Path: "/spec/containers/0/args/2", Value: "--tls-cipher-suites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"},
{Operation: "add", Path: "/spec/containers/0/args/3", Value: "--upstream=http://127.0.0.1:9100/"},
{Operation: "remove", Path: "/spec/containers/1/args/3"},
{Operation: "remove", Path: "/spec/containers/1/args/2"},
{Operation: "remove", Path: "/spec/containers/1/args/1"},
{Operation: "remove", Path: "/spec/containers/1/args/0"},
{Operation: "add", Path: "/spec/containers/1/args/0", Value: "--web.listen-address=127.0.0.1:9100"},
{Operation: "add", Path: "/spec/containers/1/args/1", Value: "--Path.procfs=/host/proc"},
{Operation: "add", Path: "/spec/containers/1/args/2", Value: "--Path.sysfs=/host/sys"},
{Operation: "add", Path: "/spec/containers/1/args/3", Value: "--Path.rootfs=/host/root"},
{Operation: "add", Path: "/spec/containers/1/args/4", Value: "--no-collector.wifi"},
{Operation: "add", Path: "/spec/containers/1/args/5", Value: "--no-collector.hwmon"},
{Operation: "add", Path: "/spec/containers/1/args/6", Value: "--collector.filesystem.ignored-mount-points=^/(dev|proc|sys|var/lib/docker/.+)($|/)"},
{Operation: "add", Path: "/spec/containers/1/args/7", Value: "--collector.filesystem.ignored-fs-types=^(autofs|binfmt_misc|cgroup|tracefs)$"},
},
expected: []jsonpatch.JsonPatchOperation{
{Operation: "remove", Path: "/spec/containers/0/args/0"},
{Operation: "remove", Path: "/spec/containers/0/args/1"},
{Operation: "remove", Path: "/spec/containers/0/args/2"},
{Operation: "remove", Path: "/spec/containers/0/args/3"},
{Operation: "remove", Path: "/spec/containers/0/args/4"},
{Operation: "remove", Path: "/spec/containers/0/args/5"},
{Operation: "remove", Path: "/spec/containers/0/args/6"},
{Operation: "remove", Path: "/spec/containers/0/args/7"},
{Operation: "add", Path: "/spec/containers/0/args/0", Value: "--logtostderr"},
{Operation: "add", Path: "/spec/containers/0/args/1", Value: "--secure-listen-address=[$(IP)]:9100"},
{Operation: "add", Path: "/spec/containers/0/args/2", Value: "--tls-cipher-suites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256"},
{Operation: "add", Path: "/spec/containers/0/args/3", Value: "--upstream=http://127.0.0.1:9100/"},
{Operation: "remove", Path: "/spec/containers/1/args/0"},
{Operation: "remove", Path: "/spec/containers/1/args/1"},
{Operation: "remove", Path: "/spec/containers/1/args/2"},
{Operation: "remove", Path: "/spec/containers/1/args/3"},
{Operation: "add", Path: "/spec/containers/1/args/0", Value: "--web.listen-address=127.0.0.1:9100"},
{Operation: "add", Path: "/spec/containers/1/args/1", Value: "--Path.procfs=/host/proc"},
{Operation: "add", Path: "/spec/containers/1/args/2", Value: "--Path.sysfs=/host/sys"},
{Operation: "add", Path: "/spec/containers/1/args/3", Value: "--Path.rootfs=/host/root"},
{Operation: "add", Path: "/spec/containers/1/args/4", Value: "--no-collector.wifi"},
{Operation: "add", Path: "/spec/containers/1/args/5", Value: "--no-collector.hwmon"},
{Operation: "add", Path: "/spec/containers/1/args/6", Value: "--collector.filesystem.ignored-mount-points=^/(dev|proc|sys|var/lib/docker/.+)($|/)"},
{Operation: "add", Path: "/spec/containers/1/args/7", Value: "--collector.filesystem.ignored-fs-types=^(autofs|binfmt_misc|cgroup|tracefs)$"},
},
},
}
for i, test := range tests {