1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-29 10:55:05 +00:00

522 added service account name in context

This commit is contained in:
shravan 2020-03-04 19:38:33 +05:30
parent 044d55600a
commit b27a62b6bf

View file

@ -79,10 +79,17 @@ func ValidatePolicyMutation(policy v1.ClusterPolicy) error {
resource, _ := generateEmptyResource(openApiGlobalState.definitions[openApiGlobalState.kindToDefinitionName[kind]]).(map[string]interface{})
newResource := unstructured.Unstructured{Object: resource}
newResource.SetKind(kind)
ctx := context.NewContext()
err := ctx.AddSA("kyvernoDummyUsername")
if err != nil {
glog.Infof("Failed to load service account in context:%v", err)
}
policyContext := engine.PolicyContext{
Policy: newPolicy,
NewResource: newResource,
Context: context.NewContext(),
Context: ctx,
}
resp := engine.Mutate(policyContext)
if len(resp.GetSuccessRules()) != len(rules) {
@ -94,7 +101,7 @@ func ValidatePolicyMutation(policy v1.ClusterPolicy) error {
}
return fmt.Errorf(strings.Join(errMessages, "\n"))
}
err := ValidateResource(resp.PatchedResource.UnstructuredContent(), kind)
err = ValidateResource(resp.PatchedResource.UnstructuredContent(), kind)
if err != nil {
return err
}