chore(pkg): Fix modernize linter (#26314)

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Co-authored-by: Blake Pettersson <blake.pettersson@gmail.com>
This commit is contained in:
Matthieu MOREL
2026-02-07 18:35:29 +01:00
committed by GitHub
parent 342aea457f
commit 2bea8c0deb
5 changed files with 13 additions and 28 deletions

View File

@@ -178,17 +178,15 @@ func TestExecuteRequest_ConcurrentErrorRequests_NoConnectionLeak(t *testing.T) {
iterations := 5
var wg sync.WaitGroup
for iter := 0; iter < iterations; iter++ {
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for range iterations {
for range concurrency {
wg.Go(func() {
ctx := context.Background()
md := metadata.New(map[string]string{})
_, err := c.executeRequest(ctx, "/application.ApplicationService/ManagedResources", []byte("test"), md)
// We expect errors
assert.Error(t, err)
}()
})
}
wg.Wait()
}

View File

@@ -87,7 +87,7 @@ func processApplicationListField(v any, fields map[string]any, exclude bool) (an
}
parts := strings.Split(field, ".")
item := converted
for i := 0; i < len(parts); i++ {
for i := range parts {
subField := parts[i]
if i == len(parts)-1 {
item[subField] = value

View File

@@ -2,6 +2,7 @@ package v1alpha1
import (
"fmt"
"slices"
"sort"
"strconv"
"strings"
@@ -332,10 +333,8 @@ func (proj *AppProject) AddGroupToRole(roleName, group string) (bool, error) {
if err != nil {
return false, err
}
for _, roleGroup := range role.Groups {
if group == roleGroup {
return false, nil
}
if slices.Contains(role.Groups, group) {
return false, nil
}
role.Groups = append(role.Groups, group)
proj.Spec.Roles[roleIndex] = *role

View File

@@ -15,6 +15,7 @@ import (
"path/filepath"
"reflect"
"regexp"
"slices"
"sort"
"strconv"
"strings"
@@ -1437,10 +1438,8 @@ type SyncOptions []string
// AddOption adds a sync option to the list of sync options and returns the modified list.
// If option was already set, returns the unmodified list of sync options.
func (o SyncOptions) AddOption(option string) SyncOptions {
for _, j := range o {
if j == option {
return o
}
if slices.Contains(o, option) {
return o
}
return append(o, option)
}
@@ -1458,12 +1457,7 @@ func (o SyncOptions) RemoveOption(option string) SyncOptions {
// HasOption returns true if the list of sync options contains given option
func (o SyncOptions) HasOption(option string) bool {
for _, i := range o {
if option == i {
return true
}
}
return false
return slices.Contains(o, option)
}
type ManagedNamespaceMetadata struct {
@@ -3321,12 +3315,7 @@ type ApplicationDestinationServiceAccount struct {
// CascadedDeletion indicates if the deletion finalizer is set and controller should delete the application and it's cascaded resources
func (app *Application) CascadedDeletion() bool {
for _, finalizer := range app.Finalizers {
if isPropagationPolicyFinalizer(finalizer) {
return true
}
}
return false
return slices.ContainsFunc(app.Finalizers, isPropagationPolicyFinalizer)
}
// IsRefreshRequested returns whether a refresh has been requested for an application, and if yes, the type of refresh that should be executed.

View File

@@ -226,7 +226,6 @@ func TestAppProject_IsDestinationPermitted(t *testing.T) {
}
for _, data := range testData {
data := data
t.Run(data.name, func(t *testing.T) {
t.Parallel()