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 JSON Merge Patch and Strategic Merge Patch in Resource Modifiers #6917

Merged
merged 13 commits into from
Nov 2, 2023

Conversation

27149chen
Copy link
Contributor

@27149chen 27149chen commented Oct 4, 2023

Please add a summary of your change

Support JSON Merge Patch and Strategic Merge Patch in Resource Modifiers, implement #6797

Does your change fix a particular issue?

Fixes #6728

Please indicate you've done the following:

  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Created a changelog file or added /kind changelog-not-required as a comment on this pull request.
  • Updated the corresponding documentation in site/content/docs/main.

Signed-off-by: lou <[email protected]>
@github-actions github-actions bot added Dependencies Pull requests that update a dependency file has-changelog labels Oct 4, 2023
@codecov
Copy link

codecov bot commented Oct 4, 2023

Codecov Report

Merging #6917 (e309375) into main (b316101) will increase coverage by 0.41%.
Report is 59 commits behind head on main.
The diff coverage is 63.03%.

@@            Coverage Diff             @@
##             main    #6917      +/-   ##
==========================================
+ Coverage   60.69%   61.11%   +0.41%     
==========================================
  Files         249      255       +6     
  Lines       26493    27072     +579     
==========================================
+ Hits        16081    16545     +464     
- Misses       9268     9348      +80     
- Partials     1144     1179      +35     
Files Coverage Δ
.../resourcemodifiers/resource_modifiers_validator.go 100.00% <100.00%> (ø)
pkg/restore/restore.go 65.77% <0.00%> (+1.38%) ⬆️
internal/resourcemodifiers/json_merge_patch.go 55.00% <55.00%> (ø)
internal/resourcemodifiers/json_patch.go 81.48% <81.48%> (ø)
internal/resourcemodifiers/resource_modifiers.go 71.92% <75.47%> (-3.73%) ⬇️
...nternal/resourcemodifiers/strategic_merge_patch.go 36.61% <36.61%> (ø)

... and 34 files with indirect coverage changes

Signed-off-by: lou <[email protected]>
@anshulahuja98 anshulahuja98 self-requested a review October 5, 2023 06:17
go.mod Outdated Show resolved Hide resolved
@danfengliu danfengliu requested a review from ywk253100 October 10, 2023 07:25
@anshulahuja98
Copy link
Collaborator

@27149chen can you also please get patch code coverage to 60%

@github-actions github-actions bot added the Area/Design Design Documents label Oct 10, 2023
Signed-off-by: lou <[email protected]>
@27149chen
Copy link
Contributor Author

@27149chen can you also please get patch code coverage to 60%

done

namespaceInclusion := collections.NewIncludesExcludes().Includes(r.Conditions.Namespaces...)
if !namespaceInclusion.ShouldInclude(obj.GetNamespace()) {
return nil
}

if r.Conditions.GroupResource != groupResource {
g, err := glob.Compile(r.Conditions.GroupResource)
Copy link
Collaborator

Choose a reason for hiding this comment

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

one thing came in my mind
if we support globbing with namespace filter.

Scenario -> user provided NS filter, with path glob as blah*
Now blah* can contain both cluster scope and namespaced scope CRs.
We need to make it clear in docs that if user wants to do cluster scope they have to put NS filter as empty otherwise it won't work
and using it in conjunction with GroupResource glob path will have these further nuances.

Copy link
Contributor Author

@27149chen 27149chen Oct 16, 2023

Choose a reason for hiding this comment

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

  1. we do support namespace glob
  2. if user enters namespaces: ["blah*"], only namespaced resources in namespace started with blah will be matched

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah
again the limitation is cluster scope won't be taken care of

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, not quite understand, can you give an example?

Copy link
Collaborator

Choose a reason for hiding this comment

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

user provided NS filter (default), with GroupResource glob as blah*
Now blah* can contain both cluster scope and namespaced scope CRs.
We need to make it clear in docs that if user wants to do cluster scope they have to put NS filter as empty otherwise it won't work
and using it in conjunction with GroupResource glob path will have these further nuances.

Reworded my initial comment to make it more clear

Copy link
Collaborator

Choose a reason for hiding this comment

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

" I think including the cluster resources by default is reasonable"
I feel this would lead to changes which are not intended.
I am worried about this.

In terms of REAL filters here - similar to what we have in backup /restore - includeClusterSCopeResources
We can add a bool for that.
that would make it consistent and give control to user.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is only useful for globbed patterns
but would lead to confusion if explicit GroupResource is mentioned.

Copy link
Collaborator

Choose a reason for hiding this comment

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

On further thought, I think it's fine.
But PLEASE just add this behaviour of cluster scope by default to docuemtnation.

Copy link
Collaborator

@anshulahuja98 anshulahuja98 Nov 1, 2023

Choose a reason for hiding this comment

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

Just to reiterate, I am fine with current changes you have. Just that I request you to document the behaviour of cluster scope by default in case of globbed GroupResourcce.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, updated

@anshulahuja98
Copy link
Collaborator

@ywk253100 I am done with my review
Some minor comments are pending fix - you can review from your end.

@ywk253100
Copy link
Contributor

I'm good for the changes.
@27149chen Could you also update the user guide about the update?

@27149chen
Copy link
Contributor Author

I'm good for the changes. @27149chen Could you also update the user guide about the update?

done

site/content/docs/main/restore-resource-modifiers.md Outdated Show resolved Hide resolved
namespaceInclusion := collections.NewIncludesExcludes().Includes(r.Conditions.Namespaces...)
if !namespaceInclusion.ShouldInclude(obj.GetNamespace()) {
return nil
}

if r.Conditions.GroupResource != groupResource {
g, err := glob.Compile(r.Conditions.GroupResource)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey I am not sure if ignoring ns filter is the right way
I am wondering if we should add another flag which says includeClusterSCope similar to what we have in backup/restore APIs.

- The above configmap will apply the Merge Patch to all the pods in namespace ns1 and remove the annotation `foo` from the pods.
- Both json and yaml format are supported for the patchData.

#### Strategic Merge Patch
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should perhaps move these 2 sections above

this is currently below jsonpatch examples and adbacned scenarios.

We should probably refactor this whole doc to make things more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can refactor it later, I don't want to do it in this pr

}
}
```
- The above configmap will apply the Merge Patch to all the pods in namespace ns1 and remove the annotation `foo` from the pods.
Copy link
Collaborator

Choose a reason for hiding this comment

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

add links to kubectl merge patch docs / other docs for reference. YOU can even provide sample kubectl command for use to test out in local setup before creating CM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added doc link

site/content/docs/main/restore-resource-modifiers.md Outdated Show resolved Hide resolved
site/content/docs/main/restore-resource-modifiers.md Outdated Show resolved Hide resolved
site/content/docs/main/restore-resource-modifiers.md Outdated Show resolved Hide resolved
Signed-off-by: lou <[email protected]>
@anshulahuja98
Copy link
Collaborator

#6917 (comment)

Hey I am not sure if ignoring ns filter is the right way
I am wondering if we should add another flag which says includeClusterSCope similar to what we have in backup/restore APIs.

@27149chen

@ywk253100 ywk253100 merged commit 73c948d into vmware-tanzu:main Nov 2, 2023
24 checks passed
27149chen pushed a commit to 27149chen/velero that referenced this pull request Nov 2, 2023
support JSON Merge Patch and Strategic Merge Patch in Resource Modifiers
27149chen pushed a commit to 27149chen/velero that referenced this pull request Nov 15, 2023
support JSON Merge Patch and Strategic Merge Patch in Resource Modifiers

Signed-off-by: lou <[email protected]>
Lyndon-Li added a commit that referenced this pull request Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Design Design Documents Dependencies Pull requests that update a dependency file Documentation has-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource Modifier should support json merge patch and strategic merge patch
4 participants