Skip to content

Commit

Permalink
🐛 Fix HasResource pkg method to properly stop when a match is found (k…
Browse files Browse the repository at this point in the history
…ubernetes-sigs#4190)

Fix HasResource method to properly stop when a match is found

- Updated the HasResource method to correctly stop the iteration when a matching GVK is found.
- Replaced the immediate return inside the loop with a boolean flag  and a break statement to ensure the function exits early when a resource is found.
- This resolves the issue where the method was not stopping as expected after finding a matching resource
  • Loading branch information
camilamacedo86 authored and TAM360 committed Sep 26, 2024
1 parent 9b82678 commit 4741891
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/config/v3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ func (c Cfg) ResourcesLength() int {

// HasResource implements config.Config
func (c Cfg) HasResource(gvk resource.GVK) bool {
found := false
for _, res := range c.Resources {
if gvk.IsEqualTo(res.GVK) {
return true
found = true
break
}
}

return false
return found
}

// GetResource implements config.Config
Expand Down

0 comments on commit 4741891

Please sign in to comment.