Skip to content

Commit 2e6171a

Browse files
authored
Merge pull request #5671 from emirot/refactor/string_inSlice
refactor: string in slice is now part of stdlib
2 parents 7f99ceb + bcb1a36 commit 2e6171a

16 files changed

+33
-28
lines changed

kustomize/commands/create/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"path/filepath"
10+
"slices"
1011
"strings"
1112

1213
"github.com/spf13/cobra"
@@ -113,7 +114,7 @@ func runCreate(opts createFlags, fSys filesys.FileSystem, rf *resource.Factory)
113114
return err
114115
}
115116
for _, resource := range detected {
116-
if kustfile.StringInSlice(resource, resources) {
117+
if slices.Contains(resources, resource) {
117118
continue
118119
}
119120
resources = append(resources, resource)

kustomize/commands/edit/add/addbase.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"fmt"
99
"strings"
1010

11+
"slices"
12+
1113
"github.com/spf13/cobra"
1214
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile"
1315
"sigs.k8s.io/kustomize/kyaml/filesys"
@@ -64,7 +66,7 @@ func (o *addBaseOptions) RunAddBase(fSys filesys.FileSystem) error {
6466
if !fSys.Exists(path) {
6567
return errors.New(path + " does not exist")
6668
}
67-
if kustfile.StringInSlice(path, m.Resources) {
69+
if slices.Contains(m.Resources, path) {
6870
return fmt.Errorf("base %s already in kustomization file", path)
6971
}
7072
m.Resources = append(m.Resources, path)

kustomize/commands/edit/add/addbase_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
package add
55

66
import (
7+
"slices"
78
"strings"
89
"testing"
910

1011
"github.com/stretchr/testify/assert"
1112
"github.com/stretchr/testify/require"
12-
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile"
1313
testutils_test "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/testutils"
1414
"sigs.k8s.io/kustomize/kyaml/filesys"
1515
)
@@ -57,7 +57,7 @@ func TestAddBaseAlreadyThere(t *testing.T) {
5757
for _, base := range bases {
5858
msg := "base " + base + " already in kustomization file"
5959
expectedErrors = append(expectedErrors, msg)
60-
assert.True(t, kustfile.StringInSlice(msg, expectedErrors))
60+
assert.True(t, slices.Contains(expectedErrors, msg))
6161
}
6262
}
6363

kustomize/commands/edit/add/addbuildmetadata.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package add
55

66
import (
77
"fmt"
8+
"slices"
89

910
"github.com/spf13/cobra"
1011
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile"
@@ -60,7 +61,7 @@ func (o *addBuildMetadataOptions) RunAddBuildMetadata(fSys filesys.FileSystem) e
6061
return err
6162
}
6263
for _, opt := range o.buildMetadataOptions {
63-
if kustfile.StringInSlice(opt, m.BuildMetadata) {
64+
if slices.Contains(m.BuildMetadata, opt) {
6465
return fmt.Errorf("buildMetadata option %s already in kustomization file", opt)
6566
}
6667
m.BuildMetadata = append(m.BuildMetadata, opt)

kustomize/commands/edit/add/addcomponent.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package add
66
import (
77
"errors"
88
"log"
9+
"slices"
910

1011
"github.com/spf13/cobra"
1112
"sigs.k8s.io/kustomize/api/pkg/loader"
@@ -69,7 +70,7 @@ func (o *addComponentOptions) RunAddComponent(fSys filesys.FileSystem) error {
6970

7071
for _, component := range components {
7172
if mf.GetPath() != component {
72-
if kustfile.StringInSlice(component, m.Components) {
73+
if slices.Contains(m.Components, component) {
7374
log.Printf("component %s already in kustomization file", component)
7475
continue
7576
}

kustomize/commands/edit/add/addgenerator.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package add
66
import (
77
"errors"
88
"log"
9+
"slices"
910

1011
"github.com/spf13/cobra"
1112
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile"
@@ -62,7 +63,7 @@ func (o *addGeneratorOptions) RunAddGenerator(fSys filesys.FileSystem) error {
6263
return err
6364
}
6465
for _, t := range o.generatorFilePaths {
65-
if kustfile.StringInSlice(t, m.Generators) {
66+
if slices.Contains(m.Generators, t) {
6667
log.Printf("generator %s already in kustomization file", t)
6768
continue
6869
}

kustomize/commands/edit/add/addresource.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package add
66
import (
77
"errors"
88
"log"
9+
"slices"
910

1011
"github.com/spf13/cobra"
1112
ldrhelper "sigs.k8s.io/kustomize/api/pkg/loader"
@@ -73,7 +74,7 @@ func (o *addResourceOptions) RunAddResource(fSys filesys.FileSystem) error {
7374

7475
for _, resource := range resources {
7576
if mf.GetPath() != resource {
76-
if kustfile.StringInSlice(resource, m.Resources) {
77+
if slices.Contains(m.Resources, resource) {
7778
log.Printf("resource %s already in kustomization file", resource)
7879
continue
7980
}

kustomize/commands/edit/add/addtransformer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package add
66
import (
77
"errors"
88
"log"
9+
"slices"
910

1011
"github.com/spf13/cobra"
1112
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile"
@@ -62,7 +63,7 @@ func (o *addTransformerOptions) RunAddTransformer(fSys filesys.FileSystem) error
6263
return err
6364
}
6465
for _, t := range o.transformerFilePaths {
65-
if kustfile.StringInSlice(t, m.Transformers) {
66+
if slices.Contains(m.Transformers, t) {
6667
log.Printf("transformer %s already in kustomization file", t)
6768
continue
6869
}

kustomize/commands/edit/fix/convert.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"bytes"
88
"fmt"
99
"path"
10+
"slices"
1011
"strconv"
1112
"strings"
1213

@@ -55,11 +56,11 @@ func filesTouchedByKustomize(k *types.Kustomization, filepath string, fSys files
5556
files, err := fSys.ReadDir(r)
5657
if err == nil && len(files) > 0 {
5758
for _, file := range files {
58-
if !stringInSlice(file, []string{
59+
if !slices.Contains([]string{
5960
"kustomization.yaml",
6061
"kustomization.yml",
6162
"Kustomization",
62-
}) {
63+
}, file) {
6364
continue
6465
}
6566

kustomize/commands/edit/remove/removebuildmetadata.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package remove
55

66
import (
7+
"slices"
8+
79
"github.com/spf13/cobra"
810
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile"
911
"sigs.k8s.io/kustomize/kustomize/v5/commands/internal/util"
@@ -59,7 +61,7 @@ func (o *removeBuildMetadataOptions) RunRemoveBuildMetadata(fSys filesys.FileSys
5961
}
6062
var newOptions []string
6163
for _, opt := range m.BuildMetadata {
62-
if !kustfile.StringInSlice(opt, o.buildMetadataOptions) {
64+
if !slices.Contains(o.buildMetadataOptions, opt) {
6365
newOptions = append(newOptions, opt)
6466
}
6567
}

0 commit comments

Comments
 (0)