Merge pull request #113749 from jpbetz/fix-params-null

Fix params to be null instead of an empty map if paramRef is null
This commit is contained in:
Kubernetes Prow Robot 2022-11-08 13:51:42 -08:00 committed by GitHub
commit c61c3fc492
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -146,7 +146,7 @@ func convertObjectToUnstructured(obj interface{}) (*unstructured.Unstructured, e
}
func objectToResolveVal(r runtime.Object) (interface{}, error) {
if r == nil {
if r == nil || reflect.ValueOf(r).IsNil() {
return nil, nil
}
v, err := convertObjectToUnstructured(r)

View File

@ -263,6 +263,8 @@ func TestValidate(t *testing.T) {
},
}
var nilUnstructured *unstructured.Unstructured
cases := []struct {
name string
policy *v1alpha1.ValidatingAdmissionPolicy
@ -502,6 +504,39 @@ func TestValidate(t *testing.T) {
generatedDecision(admit, "", ""),
},
},
{
name: "test deny paramKind without paramRef",
policy: getValidPolicy([]v1alpha1.Validation{
{
Expression: "params != null",
Reason: forbiddenReason,
Message: "params as required",
},
}, hasParamKind, nil),
attributes: newValidAttribute(nil, true),
// Simulate a interface holding a nil pointer, since this is how param is passed to Validate
// if paramRef is unset on a binding
params: runtime.Object(nilUnstructured),
policyDecisions: []policyDecision{
generatedDecision(deny, "params as required", metav1.StatusReasonForbidden),
},
},
{
name: "test allow paramKind without paramRef",
policy: getValidPolicy([]v1alpha1.Validation{
{
Expression: "params == null",
Reason: forbiddenReason,
},
}, hasParamKind, nil),
attributes: newValidAttribute(nil, true),
// Simulate a interface holding a nil pointer, since this is how param is passed to Validate
// if paramRef is unset on a binding
params: runtime.Object(nilUnstructured),
policyDecisions: []policyDecision{
generatedDecision(admit, "", ""),
},
},
}
for _, tc := range cases {