diff --git a/pkg/action/hooks.go b/pkg/action/hooks.go index 8db0d51f8..591371e44 100644 --- a/pkg/action/hooks.go +++ b/pkg/action/hooks.go @@ -189,12 +189,7 @@ func (cfg *Configuration) deleteHooksByPolicy(hooks []*release.Hook, policy rele // hookHasDeletePolicy determines whether the defined hook deletion policy matches the hook deletion polices // supported by helm. If so, mark the hook as one should be deleted. func hookHasDeletePolicy(h *release.Hook, policy release.HookDeletePolicy) bool { - for _, v := range h.DeletePolicies { - if policy == v { - return true - } - } - return false + return slices.Contains(h.DeletePolicies, policy) } // outputLogsByPolicy outputs a pods logs if the hook policy instructs it to diff --git a/pkg/chart/v2/util/capabilities.go b/pkg/chart/v2/util/capabilities.go index d4b420b2f..23b6d46fa 100644 --- a/pkg/chart/v2/util/capabilities.go +++ b/pkg/chart/v2/util/capabilities.go @@ -17,6 +17,7 @@ package util import ( "fmt" + "slices" "strconv" "github.com/Masterminds/semver/v3" @@ -102,12 +103,7 @@ type VersionSet []string // // vs.Has("apps/v1") func (v VersionSet) Has(apiVersion string) bool { - for _, x := range v { - if x == apiVersion { - return true - } - } - return false + return slices.Contains(v, apiVersion) } func allKnownVersions() VersionSet { diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go index cbec33a80..3496a4bbd 100644 --- a/pkg/cmd/install.go +++ b/pkg/cmd/install.go @@ -25,6 +25,7 @@ import ( "log/slog" "os" "os/signal" + "slices" "syscall" "time" @@ -350,13 +351,7 @@ func compInstall(args []string, toComplete string, client *action.Install) ([]st func validateDryRunOptionFlag(dryRunOptionFlagValue string) error { // Validate dry-run flag value with a set of allowed value allowedDryRunValues := []string{"false", "true", "none", "client", "server"} - isAllowed := false - for _, v := range allowedDryRunValues { - if dryRunOptionFlagValue == v { - isAllowed = true - break - } - } + isAllowed := slices.Contains(allowedDryRunValues, dryRunOptionFlagValue) if !isAllowed { return errors.New("invalid dry-run flag. Flag must one of the following: false, true, none, client, server") } diff --git a/pkg/cmd/list.go b/pkg/cmd/list.go index 69a4ff36d..5af43adad 100644 --- a/pkg/cmd/list.go +++ b/pkg/cmd/list.go @@ -20,6 +20,7 @@ import ( "fmt" "io" "os" + "slices" "strconv" "github.com/gosuri/uitable" @@ -203,13 +204,7 @@ func filterReleases(releases []*release.Release, ignoredReleaseNames []string) [ var filteredReleases []*release.Release for _, rel := range releases { - found := false - for _, ignoredName := range ignoredReleaseNames { - if rel.Name == ignoredName { - found = true - break - } - } + found := slices.Contains(ignoredReleaseNames, rel.Name) if !found { filteredReleases = append(filteredReleases, rel) } diff --git a/pkg/cmd/load_plugins.go b/pkg/cmd/load_plugins.go index 2eef1fb3c..385990d82 100644 --- a/pkg/cmd/load_plugins.go +++ b/pkg/cmd/load_plugins.go @@ -23,6 +23,7 @@ import ( "os" "os/exec" "path/filepath" + "slices" "strconv" "strings" "syscall" @@ -163,10 +164,8 @@ func manuallyProcessArgs(args []string) ([]string, []string) { } isKnown := func(v string) string { - for _, i := range kvargs { - if i == v { - return v - } + if slices.Contains(kvargs, v) { + return v } return "" } diff --git a/pkg/cmd/plugin_list.go b/pkg/cmd/plugin_list.go index fdd66ec0a..5bb9ff68d 100644 --- a/pkg/cmd/plugin_list.go +++ b/pkg/cmd/plugin_list.go @@ -19,6 +19,7 @@ import ( "fmt" "io" "log/slog" + "slices" "github.com/gosuri/uitable" "github.com/spf13/cobra" @@ -60,13 +61,7 @@ func filterPlugins(plugins []*plugin.Plugin, ignoredPluginNames []string) []*plu var filteredPlugins []*plugin.Plugin for _, plugin := range plugins { - found := false - for _, ignoredName := range ignoredPluginNames { - if plugin.Metadata.Name == ignoredName { - found = true - break - } - } + found := slices.Contains(ignoredPluginNames, plugin.Metadata.Name) if !found { filteredPlugins = append(filteredPlugins, plugin) } diff --git a/pkg/getter/getter.go b/pkg/getter/getter.go index 743ac569b..1aa38cac1 100644 --- a/pkg/getter/getter.go +++ b/pkg/getter/getter.go @@ -20,6 +20,7 @@ import ( "bytes" "fmt" "net/http" + "slices" "time" "helm.sh/helm/v4/pkg/cli" @@ -163,12 +164,7 @@ type Provider struct { // Provides returns true if the given scheme is supported by this Provider. func (p Provider) Provides(scheme string) bool { - for _, i := range p.Schemes { - if i == scheme { - return true - } - } - return false + return slices.Contains(p.Schemes, scheme) } // Providers is a collection of Provider objects. diff --git a/pkg/lint/rules/template.go b/pkg/lint/rules/template.go index 135ebf90a..72b81f191 100644 --- a/pkg/lint/rules/template.go +++ b/pkg/lint/rules/template.go @@ -25,6 +25,7 @@ import ( "os" "path" "path/filepath" + "slices" "strings" "k8s.io/apimachinery/pkg/api/validation" @@ -206,10 +207,8 @@ func validateAllowedExtension(fileName string) error { ext := filepath.Ext(fileName) validExtensions := []string{".yaml", ".yml", ".tpl", ".txt"} - for _, b := range validExtensions { - if b == ext { - return nil - } + if slices.Contains(validExtensions, ext) { + return nil } return fmt.Errorf("file extension '%s' not valid. Valid extensions are .yaml, .yml, .tpl, or .txt", ext) diff --git a/pkg/plugin/installer/http_installer.go b/pkg/plugin/installer/http_installer.go index 7b6f28db1..3bcf71208 100644 --- a/pkg/plugin/installer/http_installer.go +++ b/pkg/plugin/installer/http_installer.go @@ -27,6 +27,7 @@ import ( "path" "path/filepath" "regexp" + "slices" "strings" securejoin "github.com/cyphar/filepath-securejoin" @@ -196,10 +197,8 @@ func cleanJoin(root, dest string) (string, error) { // We want to alert the user that something bad was attempted. Cleaning it // is not a good practice. - for _, part := range strings.Split(dest, "/") { - if part == ".." { - return "", errors.New("path contains '..', which is illegal") - } + if slices.Contains(strings.Split(dest, "/"), "..") { + return "", errors.New("path contains '..', which is illegal") } // If a path is absolute, the creator of the TAR is doing something shady. diff --git a/pkg/pusher/pusher.go b/pkg/pusher/pusher.go index c4c766748..e3c767be9 100644 --- a/pkg/pusher/pusher.go +++ b/pkg/pusher/pusher.go @@ -18,6 +18,7 @@ package pusher import ( "fmt" + "slices" "helm.sh/helm/v4/pkg/cli" "helm.sh/helm/v4/pkg/registry" @@ -86,12 +87,7 @@ type Provider struct { // Provides returns true if the given scheme is supported by this Provider. func (p Provider) Provides(scheme string) bool { - for _, i := range p.Schemes { - if i == scheme { - return true - } - } - return false + return slices.Contains(p.Schemes, scheme) } // Providers is a collection of Provider objects. diff --git a/pkg/registry/util.go b/pkg/registry/util.go index e63dda43a..b31ab63fe 100644 --- a/pkg/registry/util.go +++ b/pkg/registry/util.go @@ -21,6 +21,7 @@ import ( "fmt" "io" "net/http" + "slices" "strings" "time" @@ -45,12 +46,7 @@ func IsOCI(url string) bool { // ContainsTag determines whether a tag is found in a provided list of tags func ContainsTag(tags []string, tag string) bool { - for _, t := range tags { - if tag == t { - return true - } - } - return false + return slices.Contains(tags, tag) } func GetTagMatchingVersionOrConstraint(tags []string, versionString string) (string, error) { diff --git a/pkg/storage/driver/util.go b/pkg/storage/driver/util.go index 0abbe41b2..ca8e23cc2 100644 --- a/pkg/storage/driver/util.go +++ b/pkg/storage/driver/util.go @@ -22,6 +22,7 @@ import ( "encoding/base64" "encoding/json" "io" + "slices" rspb "helm.sh/helm/v4/pkg/release/v1" ) @@ -88,12 +89,7 @@ func decodeRelease(data string) (*rspb.Release, error) { // Checks if label is system func isSystemLabel(key string) bool { - for _, v := range GetSystemLabels() { - if key == v { - return true - } - } - return false + return slices.Contains(GetSystemLabels(), key) } // Removes system labels from labels map