Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

fix: Only consider resources which supports appropriate verb for any given operation#423

Merged
jannfis merged 3 commits intoargoproj:masterfrom
jannfis:fix/resolve-gvk-check-supported-verbs
Jul 6, 2022
Merged

fix: Only consider resources which supports appropriate verb for any given operation#423
jannfis merged 3 commits intoargoproj:masterfrom
jannfis:fix/resolve-gvk-check-supported-verbs

Conversation

@jannfis
Copy link
Copy Markdown
Member

@jannfis jannfis commented Jun 24, 2022

This will consider the verbs supported by the API any GVK resolves to.

Fixes #422

Signed-off-by: jannfis jann@mistrust.net

jannfis added 2 commits June 24, 2022 11:41
…given operation

Signed-off-by: jannfis <jann@mistrust.net>
Signed-off-by: jannfis <jann@mistrust.net>
@codecov
Copy link
Copy Markdown

codecov bot commented Jun 24, 2022

Codecov Report

Merging #423 (b87a216) into master (f9456de) will increase coverage by 0.24%.
The diff coverage is 62.50%.

@@            Coverage Diff             @@
##           master     #423      +/-   ##
==========================================
+ Coverage   54.12%   54.37%   +0.24%     
==========================================
  Files          41       41              
  Lines        3104     3110       +6     
==========================================
+ Hits         1680     1691      +11     
+ Misses       1259     1252       -7     
- Partials      165      167       +2     
Impacted Files Coverage Δ
pkg/utils/kube/resource_ops.go 0.00% <0.00%> (ø)
pkg/utils/kube/ctl.go 6.70% <16.66%> (+1.76%) ⬆️
pkg/sync/sync_context.go 71.10% <100.00%> (ø)
pkg/utils/kube/kube.go 39.32% <100.00%> (+3.69%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9456de...b87a216. Read the comment docs.

@jannfis jannfis requested a review from alexmt June 24, 2022 15:09
}
for _, r := range resources.APIResources {
if r.Kind == gvk.Kind {
if r.Kind == gvk.Kind && isSupportedVerb(&r, verb) {
Copy link
Copy Markdown
Member

@jessesuen jessesuen Jun 27, 2022

Choose a reason for hiding this comment

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

I'm not sure if users will ever run into a misleading message where we report NotFound error in logs, not because the GVK doesn't exist, but rather the verb isn't supported and we did not distinguish between the two. Since it's a pretty rare corner case, I don't think it's necessary but wanted to point it out.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I actually agree with this comment, @jessesuen. Edge case or not, I'm going to fix this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Changed the logic to return MethodNotSupported if the GVK resolves to a resource which does not support the given verb.

Also, added some unit tests around all that.

Copy link
Copy Markdown
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

Was puzzled about one thing, but lgtm.

// isSupportedVerb returns whether or not a APIResource supports a specific verb.
// The verb will be matched case-insensitive.
func isSupportedVerb(apiResource *metav1.APIResource, verb string) bool {
if verb == "" || verb == "*" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this something that can happen? As far as I can tell, all instances of the argument are hard-coded as values others than these two.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good question. This is intended to allow the caller to just say "I don't care about the support verbs, just resolve it". It might be a valid use-case for some.

Signed-off-by: jannfis <jann@mistrust.net>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Jul 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

No Coverage information No Coverage information
4.3% 4.3% Duplication

@jannfis jannfis merged commit ed31317 into argoproj:master Jul 6, 2022
jannfis added a commit that referenced this pull request Jul 6, 2022
…given operation (#423)

* fix: Only consider resources which supports appropriate verb for any given operation

Signed-off-by: jannfis <jann@mistrust.net>

* Fix unit tests

Signed-off-by: jannfis <jann@mistrust.net>

* Return MethodNotSupported and add some tests

Signed-off-by: jannfis <jann@mistrust.net>
@jannfis
Copy link
Copy Markdown
Member Author

jannfis commented Jul 6, 2022

I have cherry-picked this change into release-0.7

I want to pull this change into an Argo CD v2.4.z release after the current code freeze period.

leoluz pushed a commit that referenced this pull request Aug 2, 2022
)

* Update cluster.go

Fixes #423

Signed-off-by: Daniel Urgell <urgell.d@gmail.com>

* Use c.log.Info instead of c.log.Warning

Signed-off-by: Daniel Urgell <urgell.d@gmail.com>

* Changed c.log.Info format to fix type string in argument

Signed-off-by: Daniel Urgell <urgell.d@gmail.com>

Co-authored-by: Daniel Urgell <daniel@bluelabs.eu>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gitops-engine should consider supported verbs when resolving GVK to resources

3 participants