mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-06 16:06:56 +00:00
Merge pull request #373 from nirmata/365_annotation_bug
rename EngineResponseNew to EngineResponse accordingly
This commit is contained in:
commit
653fe19283
2 changed files with 10 additions and 10 deletions
|
@ -30,7 +30,7 @@ type response struct {
|
||||||
Value interface{} `json:"value"`
|
Value interface{} `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateAnnotationPatches(annotations map[string]string, engineResponses []engine.EngineResponseNew) []byte {
|
func generateAnnotationPatches(annotations map[string]string, engineResponses []engine.EngineResponse) []byte {
|
||||||
if annotations == nil {
|
if annotations == nil {
|
||||||
annotations = make(map[string]string)
|
annotations = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func generateAnnotationPatches(annotations map[string]string, engineResponses []
|
||||||
return patchByte
|
return patchByte
|
||||||
}
|
}
|
||||||
|
|
||||||
func annotationFromEngineResponses(engineResponses []engine.EngineResponseNew) []byte {
|
func annotationFromEngineResponses(engineResponses []engine.EngineResponse) []byte {
|
||||||
var policyPatches []policyPatch
|
var policyPatches []policyPatch
|
||||||
for _, engineResponse := range engineResponses {
|
for _, engineResponse := range engineResponses {
|
||||||
if !engineResponse.IsSuccesful() {
|
if !engineResponse.IsSuccesful() {
|
||||||
|
|
|
@ -24,8 +24,8 @@ func newPolicyResponse(policy, rule string, patchesStr []string, success bool) e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEngineResponse(policy, rule string, patchesStr []string, success bool) engine.EngineResponseNew {
|
func newEngineResponse(policy, rule string, patchesStr []string, success bool) engine.EngineResponse {
|
||||||
return engine.EngineResponseNew{
|
return engine.EngineResponse{
|
||||||
PolicyResponse: newPolicyResponse(policy, rule, patchesStr, success),
|
PolicyResponse: newPolicyResponse(policy, rule, patchesStr, success),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func Test_empty_annotation(t *testing.T) {
|
||||||
patchStr := `{ "op": "replace", "path": "/spec/containers/0/imagePullPolicy", "value": "IfNotPresent" }`
|
patchStr := `{ "op": "replace", "path": "/spec/containers/0/imagePullPolicy", "value": "IfNotPresent" }`
|
||||||
engineResponse := newEngineResponse("mutate-container", "default-imagepullpolicy", []string{patchStr}, true)
|
engineResponse := newEngineResponse("mutate-container", "default-imagepullpolicy", []string{patchStr}, true)
|
||||||
|
|
||||||
annPatches := generateAnnotationPatches(nil, []engine.EngineResponseNew{engineResponse})
|
annPatches := generateAnnotationPatches(nil, []engine.EngineResponse{engineResponse})
|
||||||
expectedPatches := `{"op":"add","path":"/metadata/annotations","value":{"policies.kyverno.io":"[{\"policyname\":\"mutate-container\",\"patches\":[{\"rulename\":\"default-imagepullpolicy\",\"op\":\"replace\",\"path\":\"/spec/containers/0/imagePullPolicy\"}]}]"}}`
|
expectedPatches := `{"op":"add","path":"/metadata/annotations","value":{"policies.kyverno.io":"[{\"policyname\":\"mutate-container\",\"patches\":[{\"rulename\":\"default-imagepullpolicy\",\"op\":\"replace\",\"path\":\"/spec/containers/0/imagePullPolicy\"}]}]"}}`
|
||||||
assert.Assert(t, string(annPatches) == expectedPatches)
|
assert.Assert(t, string(annPatches) == expectedPatches)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func Test_exist_annotation(t *testing.T) {
|
||||||
|
|
||||||
patchStr := `{ "op": "replace", "path": "/spec/containers/0/imagePullPolicy", "value": "IfNotPresent" }`
|
patchStr := `{ "op": "replace", "path": "/spec/containers/0/imagePullPolicy", "value": "IfNotPresent" }`
|
||||||
engineResponse := newEngineResponse("mutate-container", "default-imagepullpolicy", []string{patchStr}, true)
|
engineResponse := newEngineResponse("mutate-container", "default-imagepullpolicy", []string{patchStr}, true)
|
||||||
annPatches := generateAnnotationPatches(annotation, []engine.EngineResponseNew{engineResponse})
|
annPatches := generateAnnotationPatches(annotation, []engine.EngineResponse{engineResponse})
|
||||||
|
|
||||||
expectedPatches := `{"op":"add","path":"/metadata/annotations","value":{"policies.kyverno.io":"[{\"policyname\":\"mutate-container\",\"patches\":[{\"rulename\":\"default-imagepullpolicy\",\"op\":\"replace\",\"path\":\"/spec/containers/0/imagePullPolicy\"}]}]","test":"annotation"}}`
|
expectedPatches := `{"op":"add","path":"/metadata/annotations","value":{"policies.kyverno.io":"[{\"policyname\":\"mutate-container\",\"patches\":[{\"rulename\":\"default-imagepullpolicy\",\"op\":\"replace\",\"path\":\"/spec/containers/0/imagePullPolicy\"}]}]","test":"annotation"}}`
|
||||||
assert.Assert(t, string(annPatches) == expectedPatches)
|
assert.Assert(t, string(annPatches) == expectedPatches)
|
||||||
|
@ -59,7 +59,7 @@ func Test_exist_kyverno_annotation(t *testing.T) {
|
||||||
|
|
||||||
patchStr := `{ "op": "replace", "path": "/spec/containers/0/imagePullPolicy", "value": "IfNotPresent" }`
|
patchStr := `{ "op": "replace", "path": "/spec/containers/0/imagePullPolicy", "value": "IfNotPresent" }`
|
||||||
engineResponse := newEngineResponse("mutate-container", "default-imagepullpolicy", []string{patchStr}, true)
|
engineResponse := newEngineResponse("mutate-container", "default-imagepullpolicy", []string{patchStr}, true)
|
||||||
annPatches := generateAnnotationPatches(annotation, []engine.EngineResponseNew{engineResponse})
|
annPatches := generateAnnotationPatches(annotation, []engine.EngineResponse{engineResponse})
|
||||||
|
|
||||||
expectedPatches := `{"op":"replace","path":"/metadata/annotations/policies.kyverno.io","value":"[{\"policyname\":\"mutate-container\",\"patches\":[{\"rulename\":\"default-imagepullpolicy\",\"op\":\"replace\",\"path\":\"/spec/containers/0/imagePullPolicy\"}]}]"}`
|
expectedPatches := `{"op":"replace","path":"/metadata/annotations/policies.kyverno.io","value":"[{\"policyname\":\"mutate-container\",\"patches\":[{\"rulename\":\"default-imagepullpolicy\",\"op\":\"replace\",\"path\":\"/spec/containers/0/imagePullPolicy\"}]}]"}`
|
||||||
assert.Assert(t, string(annPatches) == expectedPatches)
|
assert.Assert(t, string(annPatches) == expectedPatches)
|
||||||
|
@ -71,12 +71,12 @@ func Test_annotation_nil_patch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
engineResponse := newEngineResponse("mutate-container", "default-imagepullpolicy", nil, true)
|
engineResponse := newEngineResponse("mutate-container", "default-imagepullpolicy", nil, true)
|
||||||
annPatches := generateAnnotationPatches(annotation, []engine.EngineResponseNew{engineResponse})
|
annPatches := generateAnnotationPatches(annotation, []engine.EngineResponse{engineResponse})
|
||||||
|
|
||||||
assert.Assert(t, annPatches == nil)
|
assert.Assert(t, annPatches == nil)
|
||||||
|
|
||||||
engineResponseNew := newEngineResponse("mutate-container", "default-imagepullpolicy", []string{""}, true)
|
engineResponseNew := newEngineResponse("mutate-container", "default-imagepullpolicy", []string{""}, true)
|
||||||
annPatchesNew := generateAnnotationPatches(annotation, []engine.EngineResponseNew{engineResponseNew})
|
annPatchesNew := generateAnnotationPatches(annotation, []engine.EngineResponse{engineResponseNew})
|
||||||
assert.Assert(t, annPatchesNew == nil)
|
assert.Assert(t, annPatchesNew == nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ func Test_annotation_failed_Patch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
engineResponse := newEngineResponse("mutate-container", "default-imagepullpolicy", nil, false)
|
engineResponse := newEngineResponse("mutate-container", "default-imagepullpolicy", nil, false)
|
||||||
annPatches := generateAnnotationPatches(annotation, []engine.EngineResponseNew{engineResponse})
|
annPatches := generateAnnotationPatches(annotation, []engine.EngineResponse{engineResponse})
|
||||||
|
|
||||||
assert.Assert(t, annPatches == nil)
|
assert.Assert(t, annPatches == nil)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue