Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support variables in patchesJson6902 #1774

Closed
wants to merge 1 commit into from

Conversation

kacejot
Copy link
Contributor

@kacejot kacejot commented Apr 7, 2021

Signed-off-by: Max Goncharenko kacejot@fex.net

Related issue

Fixes #1521

What type of PR is this

/kind bug

Proposed changes

Added variables resolution logic in mutation patchesJson6902 handler

Checklist

Signed-off-by: Max Goncharenko <kacejot@fex.net>
@kacejot kacejot requested a review from realshuting April 7, 2021 08:34
Copy link
Member

@realshuting realshuting left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to handle auto-gen for mutate.patchesJson6902 :
https://github.com/kyverno/kyverno/blob/main/pkg/policymutation/policymutation.go#L384

return ruleResponse, h.patchedResource
}

patchedPatch, err := variables.SubstituteAll(h.logger, h.evalCtx, patch)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Jim mentioned here, do we want to allow variables to be specified in path? What if it resolves to a list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this situation is OK, because in this case path won't apply. The more places we can use to substitute vars, the more flexible we are. Invalid path with an list inside must be validated further when patch is applied.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree we want to make it as flexible as possible, but supporting variable substitution in path could potentially bring unexpected results for different types, thus lead to confusing situations. Do you see any use case there?

Copy link
Contributor Author

@kacejot kacejot Apr 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no use case for more complex types than string in path, but I also think that this is not the actual place where this check should be applied. We could check here that we have unmarshall error and this will bring user the understanding of what he did wrong with path.

@realshuting realshuting self-assigned this Apr 8, 2021
@kacejot kacejot closed this Apr 8, 2021
@kacejot kacejot deleted the json-patch-variables branch April 8, 2021 11:53
@kacejot kacejot restored the json-patch-variables branch April 8, 2021 11:56
@kacejot kacejot reopened this Apr 8, 2021
@kacejot
Copy link
Contributor Author

kacejot commented Apr 27, 2021

We also need to handle auto-gen for mutate.patchesJson6902 :
https://github.com/kyverno/kyverno/blob/main/pkg/policymutation/policymutation.go#L384

It is not clear for me. I see that we have no resource context here, so variables cannot be substituted.

@kacejot
Copy link
Contributor Author

kacejot commented Apr 27, 2021

This PR is not actual anymore, because we substitute variables substitution for entire rule.
This variable substitution occurs here:

if rule, err = variables.SubstituteAllInRule(logger, policyContext.JSONContext, rule); err != nil {

@kacejot
Copy link
Contributor Author

kacejot commented Apr 27, 2021

Closed due to already implemented logic in #1785

@kacejot kacejot closed this Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support variables / JMESPath in patchesJson6902
2 participants