diff --git a/tools/go.mod b/tools/go.mod index 1b06883ad..b408f62f7 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -8,7 +8,7 @@ require ( google.golang.org/protobuf v1.34.1 sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20240102165319-7f316f1309b1 sigs.k8s.io/controller-tools v0.15.0 - sigs.k8s.io/kustomize/kustomize/v5 v5.4.1 + sigs.k8s.io/kustomize/kustomize/v5 v5.4.2 ) require ( @@ -231,9 +231,9 @@ require ( sigs.k8s.io/controller-runtime v0.16.3 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/kubebuilder/v3 v3.13.1-0.20240119130530-7fba82c768f8 // indirect - sigs.k8s.io/kustomize/api v0.17.1 // indirect - sigs.k8s.io/kustomize/cmd/config v0.14.0 // indirect - sigs.k8s.io/kustomize/kyaml v0.17.0 // indirect + sigs.k8s.io/kustomize/api v0.17.2 // indirect + sigs.k8s.io/kustomize/cmd/config v0.14.1 // indirect + sigs.k8s.io/kustomize/kyaml v0.17.1 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect ) diff --git a/tools/go.sum b/tools/go.sum index cc6b19917..50e1022e3 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -822,14 +822,14 @@ sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMm sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/kubebuilder/v3 v3.13.1-0.20240119130530-7fba82c768f8 h1:6dc/YGQd4QVjjVHOQEz9M9w5C3Mv+q327eyJ0l8wixY= sigs.k8s.io/kubebuilder/v3 v3.13.1-0.20240119130530-7fba82c768f8/go.mod h1:ZhWtqslcUPr6eN/4Ww2Qn0OwxLuTt+HYLJRq/UTtJpw= -sigs.k8s.io/kustomize/api v0.17.1 h1:MYJBOP/yQ3/5tp4/sf6HiiMfNNyO97LmtnirH9SLNr4= -sigs.k8s.io/kustomize/api v0.17.1/go.mod h1:ffn5491s2EiNrJSmgqcWGzQUVhc/pB0OKNI0HsT/0tA= -sigs.k8s.io/kustomize/cmd/config v0.14.0 h1:TMKWBtk0Ox1EUwafT9hncg7EFrvrBlqDDHXmBHm51U8= -sigs.k8s.io/kustomize/cmd/config v0.14.0/go.mod h1:J+ukok4u7k8esCzEhRTygTW7dzDKYbC0kCDkpBK3VfI= -sigs.k8s.io/kustomize/kustomize/v5 v5.4.1 h1:97qXYnSngAvY+gUAzMfjJ73ClKZAD+JrKE+7OIMWYhw= -sigs.k8s.io/kustomize/kustomize/v5 v5.4.1/go.mod h1:nKouayWQbaro85jrNbcA+tZ6x63wYYxGPgniA/fEmgQ= -sigs.k8s.io/kustomize/kyaml v0.17.0 h1:G2bWs03V9Ur2PinHLzTUJ8Ded+30SzXZKiO92SRDs3c= -sigs.k8s.io/kustomize/kyaml v0.17.0/go.mod h1:6lxkYF1Cv9Ic8g/N7I86cvxNc5iinUo/P2vKsHNmpyE= +sigs.k8s.io/kustomize/api v0.17.2 h1:E7/Fjk7V5fboiuijoZHgs4aHuexi5Y2loXlVOAVAG5g= +sigs.k8s.io/kustomize/api v0.17.2/go.mod h1:UWTz9Ct+MvoeQsHcJ5e+vziRRkwimm3HytpZgIYqye0= +sigs.k8s.io/kustomize/cmd/config v0.14.1 h1:r1gRhgfPmnt7VYf4uxO8M27GX406n9kOOeScOH9IQds= +sigs.k8s.io/kustomize/cmd/config v0.14.1/go.mod h1:Sw1cPsFqh4uYczCWKlidPgMrsffLPCAB+7ytYLlauY4= +sigs.k8s.io/kustomize/kustomize/v5 v5.4.2 h1:9Zl5Gqg3XMdBEvkR54pVLCBj7FVO7W+VPNDDEzD6AyE= +sigs.k8s.io/kustomize/kustomize/v5 v5.4.2/go.mod h1:5ypfJVYlPb2MKKeoGknVLxvHemDlQT+szI4+KOhnD6k= +sigs.k8s.io/kustomize/kyaml v0.17.1 h1:TnxYQxFXzbmNG6gOINgGWQt09GghzgTP6mIurOgrLCQ= +sigs.k8s.io/kustomize/kyaml v0.17.1/go.mod h1:9V0mCjIEYjlXuCdYsSXvyoy2BTsLESH7TlGV81S282U= sigs.k8s.io/structured-merge-diff/v4 v4.4.1 h1:150L+0vs/8DA78h1u02ooW1/fFq/Lwr+sGiqlzvrtq4= sigs.k8s.io/structured-merge-diff/v4 v4.4.1/go.mod h1:N8hJocpFajUSSeSJ9bOZ77VzejKZaXsTtZo4/u7Io08= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= diff --git a/tools/vendor/modules.txt b/tools/vendor/modules.txt index ee8e1c850..5c1753d3e 100644 --- a/tools/vendor/modules.txt +++ b/tools/vendor/modules.txt @@ -1847,7 +1847,7 @@ sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/v1alpha sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/v1alpha/scaffolds sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/v1alpha/scaffolds/internal/templates sigs.k8s.io/kubebuilder/v3/pkg/rescaffold -# sigs.k8s.io/kustomize/api v0.17.1 +# sigs.k8s.io/kustomize/api v0.17.2 ## explicit; go 1.21 sigs.k8s.io/kustomize/api/filters/annotations sigs.k8s.io/kustomize/api/filters/fieldspec @@ -1897,7 +1897,7 @@ sigs.k8s.io/kustomize/api/provider sigs.k8s.io/kustomize/api/resmap sigs.k8s.io/kustomize/api/resource sigs.k8s.io/kustomize/api/types -# sigs.k8s.io/kustomize/cmd/config v0.14.0 +# sigs.k8s.io/kustomize/cmd/config v0.14.1 ## explicit; go 1.21 sigs.k8s.io/kustomize/cmd/config/completion sigs.k8s.io/kustomize/cmd/config/configcobra @@ -1908,7 +1908,7 @@ sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/api sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/tutorials sigs.k8s.io/kustomize/cmd/config/runner -# sigs.k8s.io/kustomize/kustomize/v5 v5.4.1 +# sigs.k8s.io/kustomize/kustomize/v5 v5.4.2 ## explicit; go 1.21 sigs.k8s.io/kustomize/kustomize/v5 sigs.k8s.io/kustomize/kustomize/v5/commands @@ -1927,7 +1927,7 @@ sigs.k8s.io/kustomize/kustomize/v5/commands/openapi sigs.k8s.io/kustomize/kustomize/v5/commands/openapi/fetch sigs.k8s.io/kustomize/kustomize/v5/commands/openapi/info sigs.k8s.io/kustomize/kustomize/v5/commands/version -# sigs.k8s.io/kustomize/kyaml v0.17.0 +# sigs.k8s.io/kustomize/kyaml v0.17.1 ## explicit; go 1.21 sigs.k8s.io/kustomize/kyaml/comments sigs.k8s.io/kustomize/kyaml/errors diff --git a/tools/vendor/sigs.k8s.io/kustomize/api/internal/accumulator/loadconfigfromcrds.go b/tools/vendor/sigs.k8s.io/kustomize/api/internal/accumulator/loadconfigfromcrds.go index afe6da2e7..f60c517b7 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/api/internal/accumulator/loadconfigfromcrds.go +++ b/tools/vendor/sigs.k8s.io/kustomize/api/internal/accumulator/loadconfigfromcrds.go @@ -144,7 +144,7 @@ func loadCrdIntoConfig( } _, label := property.Extensions.GetString(xLabelSelector) if label { - err = theConfig.AddLabelFieldSpec( + err = theConfig.AddCommonLabelsFieldSpec( makeFs(theGvk, append(path, propName))) if err != nil { return diff --git a/tools/vendor/sigs.k8s.io/kustomize/api/internal/builtins/SortOrderTransformer.go b/tools/vendor/sigs.k8s.io/kustomize/api/internal/builtins/SortOrderTransformer.go index 687f21a60..c50f627fe 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/api/internal/builtins/SortOrderTransformer.go +++ b/tools/vendor/sigs.k8s.io/kustomize/api/internal/builtins/SortOrderTransformer.go @@ -74,34 +74,16 @@ func (p *SortOrderTransformerPlugin) Transform(m resmap.ResMap) (err error) { // Sort if p.SortOptions.Order == types.LegacySortOrder { - s := newLegacyIDSorter(m.AllIds(), p.SortOptions.LegacySortOptions) + s := newLegacyIDSorter(m.Resources(), p.SortOptions.LegacySortOptions) sort.Sort(s) - err = applyOrdering(m, s.resids) - if err != nil { - return err - } - } - return nil -} -// applyOrdering takes resources (given in ResMap) and a desired ordering given -// as a sequence of ResIds, and updates the ResMap's resources to match the -// ordering. -func applyOrdering(m resmap.ResMap, ordering []resid.ResId) error { - var err error - resources := make([]*resource.Resource, m.Size()) - // Clear and refill with the correct order - for i, id := range ordering { - resources[i], err = m.GetByCurrentId(id) - if err != nil { - return errors.WrapPrefixf(err, "expected match for sorting") - } - } - m.Clear() - for _, r := range resources { - err = m.Append(r) - if err != nil { - return errors.WrapPrefixf(err, "SortOrderTransformer: Failed to append to resources") + // Clear the map and re-add the resources in the sorted order. + m.Clear() + for _, r := range s.resources { + err := m.Append(r) + if err != nil { + return errors.WrapPrefixf(err, "SortOrderTransformer: Failed to append to resources") + } } } return nil @@ -117,12 +99,17 @@ func applyOrdering(m resmap.ResMap, ordering []resid.ResId) error { type legacyIDSorter struct { // resids only stores the metadata of the object. This is an optimization as // it's expensive to compute these again and again during ordering. - resids []resid.ResId + resids []resid.ResId + // Initially, we sorted the metadata (ResId) of each object and then called GetByCurrentId on each to construct the final list. + // The problem is that GetByCurrentId is inefficient and does a linear scan in a list every time we do that. + // So instead, we sort resources alongside the ResIds. + resources []*resource.Resource + typeOrders map[string]int } func newLegacyIDSorter( - resids []resid.ResId, + resources []*resource.Resource, options *types.LegacySortOptions) *legacyIDSorter { // Precalculate a resource ranking based on the priority lists. var typeOrders = func() map[string]int { @@ -135,10 +122,13 @@ func newLegacyIDSorter( } return m }() - return &legacyIDSorter{ - resids: resids, - typeOrders: typeOrders, + + ret := &legacyIDSorter{typeOrders: typeOrders} + for _, res := range resources { + ret.resids = append(ret.resids, res.CurId()) + ret.resources = append(ret.resources, res) } + return ret } var _ sort.Interface = legacyIDSorter{} @@ -146,6 +136,7 @@ var _ sort.Interface = legacyIDSorter{} func (a legacyIDSorter) Len() int { return len(a.resids) } func (a legacyIDSorter) Swap(i, j int) { a.resids[i], a.resids[j] = a.resids[j], a.resids[i] + a.resources[i], a.resources[j] = a.resources[j], a.resources[i] } func (a legacyIDSorter) Less(i, j int) bool { if !a.resids[i].Gvk.Equals(a.resids[j].Gvk) { diff --git a/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/localizer.go b/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/localizer.go index 71de9dd6f..c5c7783c4 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/localizer.go +++ b/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/localizer.go @@ -381,7 +381,7 @@ func (lc *localizer) localizeFileWithContent(path string, content []byte) (strin // 2. avoid paths that temporarily traverse outside the current root, // i.e. ../../../scope/target/current-root. The localized file will be surrounded by // different directories than its source, and so an uncleaned path may no longer be valid. - locPath = cleanFilePath(lc.fSys, lc.root, path) + locPath = cleanedRelativePath(lc.fSys, lc.root, path) } absPath := filepath.Join(lc.dst, locPath) if err := lc.fSys.MkdirAll(filepath.Dir(absPath)); err != nil { diff --git a/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/locloader.go b/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/locloader.go index 1d1072bd1..33a03b4fc 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/locloader.go +++ b/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/locloader.go @@ -89,11 +89,8 @@ func (ll *Loader) Load(path string) ([]byte, error) { if err != nil { return nil, errors.WrapPrefixf(err, "invalid file reference") } - if filepath.IsAbs(path) { - return nil, errors.Errorf("absolute paths not yet supported in alpha: file path %q is absolute", path) - } if !loader.IsRemoteFile(path) && ll.local { - cleanPath := cleanFilePath(ll.fSys, filesys.ConfirmedDir(ll.Root()), path) + cleanPath := cleanedRelativePath(ll.fSys, filesys.ConfirmedDir(ll.Root()), path) cleanAbs := filepath.Join(ll.Root(), cleanPath) dir := filesys.ConfirmedDir(filepath.Dir(cleanAbs)) // target cannot reference newDir, as this load would've failed prior to localize; diff --git a/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/util.go b/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/util.go index 1a5151118..1ec077875 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/util.go +++ b/tools/vendor/sigs.k8s.io/kustomize/api/internal/localizer/util.go @@ -112,9 +112,13 @@ func hasRef(repoURL string) bool { return repoSpec.Ref != "" } -// cleanFilePath returns file cleaned, where file is a relative path to root on fSys -func cleanFilePath(fSys filesys.FileSystem, root filesys.ConfirmedDir, file string) string { - abs := root.Join(file) +// cleanedRelativePath returns a cleaned relative path of file to root on fSys +func cleanedRelativePath(fSys filesys.FileSystem, root filesys.ConfirmedDir, file string) string { + abs := file + if !filepath.IsAbs(file) { + abs = root.Join(file) + } + dir, f, err := fSys.CleanedAbs(abs) if err != nil { log.Fatalf("cannot clean validated file path %q: %s", abs, err) diff --git a/tools/vendor/sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig/transformerconfig.go b/tools/vendor/sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig/transformerconfig.go index ab847eb6e..c539c290d 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig/transformerconfig.go +++ b/tools/vendor/sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig/transformerconfig.go @@ -21,6 +21,7 @@ type TransformerConfig struct { NameSuffix types.FsSlice `json:"nameSuffix,omitempty" yaml:"nameSuffix,omitempty"` NameSpace types.FsSlice `json:"namespace,omitempty" yaml:"namespace,omitempty"` CommonLabels types.FsSlice `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"` + Labels types.FsSlice `json:"labels,omitempty" yaml:"labels,omitempty"` TemplateLabels types.FsSlice `json:"templateLabels,omitempty" yaml:"templateLabels,omitempty"` CommonAnnotations types.FsSlice `json:"commonAnnotations,omitempty" yaml:"commonAnnotations,omitempty"` NameReference nbrSlice `json:"nameReference,omitempty" yaml:"nameReference,omitempty"` @@ -41,6 +42,7 @@ func (t *TransformerConfig) DeepCopy() *TransformerConfig { NameSuffix: t.NameSuffix.DeepCopy(), NameSpace: t.NameSpace.DeepCopy(), CommonLabels: t.CommonLabels.DeepCopy(), + Labels: t.Labels.DeepCopy(), TemplateLabels: t.TemplateLabels.DeepCopy(), CommonAnnotations: t.CommonAnnotations.DeepCopy(), NameReference: t.NameReference.DeepCopy(), @@ -94,6 +96,7 @@ func (t *TransformerConfig) sortFields() { sort.Sort(t.NameSuffix) sort.Sort(t.NameSpace) sort.Sort(t.CommonLabels) + sort.Sort(t.Labels) sort.Sort(t.TemplateLabels) sort.Sort(t.CommonAnnotations) sort.Sort(t.NameReference) @@ -114,12 +117,18 @@ func (t *TransformerConfig) AddSuffixFieldSpec(fs types.FieldSpec) (err error) { return err } -// AddLabelFieldSpec adds a FieldSpec to CommonLabels -func (t *TransformerConfig) AddLabelFieldSpec(fs types.FieldSpec) (err error) { +// AddCommonLabelsFieldSpec adds a FieldSpec to CommonLabels +func (t *TransformerConfig) AddCommonLabelsFieldSpec(fs types.FieldSpec) (err error) { t.CommonLabels, err = t.CommonLabels.MergeOne(fs) return err } +// AddLabelsFieldSpec adds a FieldSpec to Labels +func (t *TransformerConfig) AddLabelsFieldSpec(fs types.FieldSpec) (err error) { + t.Labels, err = t.Labels.MergeOne(fs) + return err //nolint:wrapcheck +} + // AddAnnotationFieldSpec adds a FieldSpec to CommonAnnotations func (t *TransformerConfig) AddAnnotationFieldSpec(fs types.FieldSpec) (err error) { t.CommonAnnotations, err = t.CommonAnnotations.MergeOne(fs) @@ -162,6 +171,10 @@ func (t *TransformerConfig) Merge(input *TransformerConfig) ( if err != nil { return nil, errors.WrapPrefixf(err, "failed to merge CommonLabels fieldSpec") } + merged.Labels, err = t.Labels.MergeAll(input.Labels) + if err != nil { + return nil, errors.WrapPrefixf(err, "failed to merge Labels fieldSpec") + } merged.TemplateLabels, err = t.TemplateLabels.MergeAll(input.TemplateLabels) if err != nil { return nil, errors.WrapPrefixf(err, "failed to merge TemplateLabels fieldSpec") diff --git a/tools/vendor/sigs.k8s.io/kustomize/api/internal/plugins/loader/load_go_plugin_disabled.go b/tools/vendor/sigs.k8s.io/kustomize/api/internal/plugins/loader/load_go_plugin_disabled.go index 654e22da3..5531b7967 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/api/internal/plugins/loader/load_go_plugin_disabled.go +++ b/tools/vendor/sigs.k8s.io/kustomize/api/internal/plugins/loader/load_go_plugin_disabled.go @@ -14,11 +14,12 @@ package loader import ( + "fmt" + "sigs.k8s.io/kustomize/api/resmap" - "sigs.k8s.io/kustomize/kyaml/errors" "sigs.k8s.io/kustomize/kyaml/resid" ) func (l *Loader) loadGoPlugin(_ resid.ResId, _ string) (resmap.Configurable, error) { - return nil, errors.New("plugin load is disabled") + return nil, fmt.Errorf("plugin load is disabled") } diff --git a/tools/vendor/sigs.k8s.io/kustomize/api/internal/target/kusttarget_configplugin.go b/tools/vendor/sigs.k8s.io/kustomize/api/internal/target/kusttarget_configplugin.go index b589961e5..1ba028a36 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/api/internal/target/kusttarget_configplugin.go +++ b/tools/vendor/sigs.k8s.io/kustomize/api/internal/target/kusttarget_configplugin.go @@ -275,13 +275,25 @@ var transformerConfigurators = map[builtinhelpers.BuiltinPluginType]func( if len(kt.kustomization.Labels) == 0 && len(kt.kustomization.CommonLabels) == 0 { return } + + type labelStruct struct { + Labels map[string]string + FieldSpecs []types.FieldSpec + } + for _, label := range kt.kustomization.Labels { - var c struct { - Labels map[string]string - FieldSpecs []types.FieldSpec - } + var c labelStruct + c.Labels = label.Pairs fss := types.FsSlice(label.FieldSpecs) + + // merge labels specified in the label section of transformer configs + // these apply to selectors and templates + fss, err := fss.MergeAll(tc.Labels) + if err != nil { + return nil, fmt.Errorf("failed to merge labels: %w", err) + } + // merge the custom fieldSpecs with the default if label.IncludeSelectors { fss, err = fss.MergeAll(tc.CommonLabels) @@ -297,7 +309,7 @@ var transformerConfigurators = map[builtinhelpers.BuiltinPluginType]func( fss, err = fss.MergeOne(types.FieldSpec{Path: "metadata/labels", CreateIfNotPresent: true}) } if err != nil { - return nil, err + return nil, fmt.Errorf("failed to merge labels: %w", err) } c.FieldSpecs = fss p := f() @@ -307,10 +319,9 @@ var transformerConfigurators = map[builtinhelpers.BuiltinPluginType]func( } result = append(result, p) } - var c struct { - Labels map[string]string - FieldSpecs []types.FieldSpec - } + + var c labelStruct + c.Labels = kt.kustomization.CommonLabels c.FieldSpecs = tc.CommonLabels p := f() diff --git a/tools/vendor/sigs.k8s.io/kustomize/api/resource/factory.go b/tools/vendor/sigs.k8s.io/kustomize/api/resource/factory.go index f67fbf360..fef2f6e49 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/api/resource/factory.go +++ b/tools/vendor/sigs.k8s.io/kustomize/api/resource/factory.go @@ -41,28 +41,26 @@ func (rf *Factory) Hasher() ifc.KustHasher { } // FromMap returns a new instance of Resource. -func (rf *Factory) FromMap(m map[string]interface{}) *Resource { +func (rf *Factory) FromMap(m map[string]interface{}) (*Resource, error) { res, err := rf.FromMapAndOption(m, nil) if err != nil { - // TODO: return err instead of log. - log.Fatalf("failed to create resource from map: %v", err) + return nil, fmt.Errorf("failed to create resource from map: %w", err) } - return res + return res, nil } // FromMapWithName returns a new instance with the given "original" name. -func (rf *Factory) FromMapWithName(n string, m map[string]interface{}) *Resource { +func (rf *Factory) FromMapWithName(n string, m map[string]interface{}) (*Resource, error) { return rf.FromMapWithNamespaceAndName(resid.DefaultNamespace, n, m) } // FromMapWithNamespaceAndName returns a new instance with the given "original" namespace. -func (rf *Factory) FromMapWithNamespaceAndName(ns string, n string, m map[string]interface{}) *Resource { +func (rf *Factory) FromMapWithNamespaceAndName(ns string, n string, m map[string]interface{}) (*Resource, error) { r, err := rf.FromMapAndOption(m, nil) if err != nil { - // TODO: return err instead of log. - log.Fatalf("failed to create resource from map: %v", err) + return nil, fmt.Errorf("failed to create resource from map: %w", err) } - return r.setPreviousId(ns, n, r.GetKind()) + return r.setPreviousId(ns, n, r.GetKind()), nil } // FromMapAndOption returns a new instance of Resource with given options. diff --git a/tools/vendor/sigs.k8s.io/kustomize/api/types/labels.go b/tools/vendor/sigs.k8s.io/kustomize/api/types/labels.go index 05ba890f9..35f7fb2a5 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/api/types/labels.go +++ b/tools/vendor/sigs.k8s.io/kustomize/api/types/labels.go @@ -6,12 +6,12 @@ package types type Label struct { // Pairs contains the key-value pairs for labels to add Pairs map[string]string `json:"pairs,omitempty" yaml:"pairs,omitempty"` - // IncludeSelectors inidicates should transformer include the + // IncludeSelectors indicates whether the transformer should include the // fieldSpecs for selectors. Custom fieldSpecs specified by // FieldSpecs will be merged with builtin fieldSpecs if this // is true. IncludeSelectors bool `json:"includeSelectors,omitempty" yaml:"includeSelectors,omitempty"` - // IncludeTemplates inidicates should transformer include the + // IncludeTemplates indicates whether the transformer should include the // spec/template/metadata fieldSpec. Custom fieldSpecs specified by // FieldSpecs will be merged with spec/template/metadata fieldSpec if this // is true. If IncludeSelectors is true, IncludeTemplates is not needed. diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/create/create.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/create/create.go index 81a05dbab..6b867c908 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/create/create.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/create/create.go @@ -7,6 +7,7 @@ import ( "fmt" "os" "path/filepath" + "slices" "strings" "github.com/spf13/cobra" @@ -113,7 +114,7 @@ func runCreate(opts createFlags, fSys filesys.FileSystem, rf *resource.Factory) return err } for _, resource := range detected { - if kustfile.StringInSlice(resource, resources) { + if slices.Contains(resources, resource) { continue } resources = append(resources, resource) diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addbase.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addbase.go index 01a422e5a..b33f128df 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addbase.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addbase.go @@ -8,6 +8,8 @@ import ( "fmt" "strings" + "slices" + "github.com/spf13/cobra" "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile" "sigs.k8s.io/kustomize/kyaml/filesys" @@ -64,7 +66,7 @@ func (o *addBaseOptions) RunAddBase(fSys filesys.FileSystem) error { if !fSys.Exists(path) { return errors.New(path + " does not exist") } - if kustfile.StringInSlice(path, m.Resources) { + if slices.Contains(m.Resources, path) { return fmt.Errorf("base %s already in kustomization file", path) } m.Resources = append(m.Resources, path) diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addbuildmetadata.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addbuildmetadata.go index e4aa86ca3..d8af37842 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addbuildmetadata.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addbuildmetadata.go @@ -5,6 +5,7 @@ package add import ( "fmt" + "slices" "github.com/spf13/cobra" "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile" @@ -60,7 +61,7 @@ func (o *addBuildMetadataOptions) RunAddBuildMetadata(fSys filesys.FileSystem) e return err } for _, opt := range o.buildMetadataOptions { - if kustfile.StringInSlice(opt, m.BuildMetadata) { + if slices.Contains(m.BuildMetadata, opt) { return fmt.Errorf("buildMetadata option %s already in kustomization file", opt) } m.BuildMetadata = append(m.BuildMetadata, opt) diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addcomponent.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addcomponent.go index c0f728f71..a5078ae73 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addcomponent.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addcomponent.go @@ -6,6 +6,7 @@ package add import ( "errors" "log" + "slices" "github.com/spf13/cobra" "sigs.k8s.io/kustomize/api/pkg/loader" @@ -69,7 +70,7 @@ func (o *addComponentOptions) RunAddComponent(fSys filesys.FileSystem) error { for _, component := range components { if mf.GetPath() != component { - if kustfile.StringInSlice(component, m.Components) { + if slices.Contains(m.Components, component) { log.Printf("component %s already in kustomization file", component) continue } diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addgenerator.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addgenerator.go index ee475d1b4..ab1d17230 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addgenerator.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addgenerator.go @@ -6,6 +6,7 @@ package add import ( "errors" "log" + "slices" "github.com/spf13/cobra" "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile" @@ -62,7 +63,7 @@ func (o *addGeneratorOptions) RunAddGenerator(fSys filesys.FileSystem) error { return err } for _, t := range o.generatorFilePaths { - if kustfile.StringInSlice(t, m.Generators) { + if slices.Contains(m.Generators, t) { log.Printf("generator %s already in kustomization file", t) continue } diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addresource.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addresource.go index 529f2b119..3c63b4b13 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addresource.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addresource.go @@ -6,6 +6,7 @@ package add import ( "errors" "log" + "slices" "github.com/spf13/cobra" ldrhelper "sigs.k8s.io/kustomize/api/pkg/loader" @@ -73,7 +74,7 @@ func (o *addResourceOptions) RunAddResource(fSys filesys.FileSystem) error { for _, resource := range resources { if mf.GetPath() != resource { - if kustfile.StringInSlice(resource, m.Resources) { + if slices.Contains(m.Resources, resource) { log.Printf("resource %s already in kustomization file", resource) continue } diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addtransformer.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addtransformer.go index 288ee3f3e..ffc4aa77e 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addtransformer.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/add/addtransformer.go @@ -6,6 +6,7 @@ package add import ( "errors" "log" + "slices" "github.com/spf13/cobra" "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile" @@ -62,7 +63,7 @@ func (o *addTransformerOptions) RunAddTransformer(fSys filesys.FileSystem) error return err } for _, t := range o.transformerFilePaths { - if kustfile.StringInSlice(t, m.Transformers) { + if slices.Contains(m.Transformers, t) { log.Printf("transformer %s already in kustomization file", t) continue } diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/fix/convert.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/fix/convert.go index f6c450803..04162d7c1 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/fix/convert.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/fix/convert.go @@ -7,6 +7,7 @@ import ( "bytes" "fmt" "path" + "slices" "strconv" "strings" @@ -55,11 +56,11 @@ func filesTouchedByKustomize(k *types.Kustomization, filepath string, fSys files files, err := fSys.ReadDir(r) if err == nil && len(files) > 0 { for _, file := range files { - if !stringInSlice(file, []string{ + if !slices.Contains([]string{ "kustomization.yaml", "kustomization.yml", "Kustomization", - }) { + }, file) { continue } @@ -223,7 +224,7 @@ func constructFieldOptions(value string, varString string) ([]*types.FieldOption return nil, fmt.Errorf("cannot convert all vars to replacements; %s is not delimited", varString) } delimiter = pre - index = indexOf(varString, strings.Split(value, delimiter)) + index = slices.Index(strings.Split(value, delimiter), varString) if index == -1 { // this should never happen return nil, fmt.Errorf("internal error: could not get index of var %s", varString) @@ -327,21 +328,3 @@ func setPlaceholderValue(varName string, files []string, fSys filesys.FileSystem } return nil } - -func stringInSlice(elem string, slice []string) bool { - for i := range slice { - if slice[i] == elem { - return true - } - } - return false -} - -func indexOf(varName string, slice []string) int { - for i := range slice { - if slice[i] == varName { - return i - } - } - return -1 -} diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removebuildmetadata.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removebuildmetadata.go index de27de0a1..58e30488c 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removebuildmetadata.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removebuildmetadata.go @@ -4,6 +4,8 @@ package remove import ( + "slices" + "github.com/spf13/cobra" "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile" "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/util" @@ -59,7 +61,7 @@ func (o *removeBuildMetadataOptions) RunRemoveBuildMetadata(fSys filesys.FileSys } var newOptions []string for _, opt := range m.BuildMetadata { - if !kustfile.StringInSlice(opt, o.buildMetadataOptions) { + if !slices.Contains(o.buildMetadataOptions, opt) { newOptions = append(newOptions, opt) } } diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removeconfigmap.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removeconfigmap.go index 7eeedb7d0..056db08e9 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removeconfigmap.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removeconfigmap.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "slices" "strings" "github.com/spf13/cobra" @@ -88,7 +89,7 @@ func (o *removeConfigMapOptions) RunRemoveConfigMap(fSys filesys.FileSystem) err remainingConfigMaps := make([]types.ConfigMapArgs, 0, len(m.ConfigMapGenerator)) for _, currentConfigMap := range m.ConfigMapGenerator { - if kustfile.StringInSlice(currentConfigMap.Name, o.configMapNamesToRemove) && + if slices.Contains(o.configMapNamesToRemove, currentConfigMap.Name) && util.NamespaceEqual(currentConfigMap.Namespace, o.namespace) { foundConfigMaps[currentConfigMap.Name] = struct{}{} continue diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removeresource.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removeresource.go index fc76943d0..1fdbf79be 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removeresource.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removeresource.go @@ -6,6 +6,7 @@ package remove import ( "errors" "path/filepath" + "slices" "github.com/spf13/cobra" "sigs.k8s.io/kustomize/api/konfig" @@ -73,7 +74,7 @@ func (o *removeResourceOptions) RunRemoveResource(fSys filesys.FileSystem) error newResources := make([]string, 0, len(m.Resources)) for _, resource := range m.Resources { - if kustfile.StringInSlice(resource, resources) { + if slices.Contains(resources, resource) { continue } newResources = append(newResources, resource) diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removesecret.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removesecret.go index 89a8af230..d648051ed 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removesecret.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removesecret.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "slices" "strings" "github.com/spf13/cobra" @@ -89,7 +90,7 @@ func (o *removeSecretOptions) RunRemoveSecret(fSys filesys.FileSystem) error { remainingSecrets := make([]types.SecretArgs, 0, len(m.SecretGenerator)) for _, currentSecret := range m.SecretGenerator { - if kustfile.StringInSlice(currentSecret.Name, o.secretNamesToRemove) && + if slices.Contains(o.secretNamesToRemove, currentSecret.Name) && util.NamespaceEqual(currentSecret.Namespace, o.namespace) { foundSecrets[currentSecret.Name] = struct{}{} continue diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removetransformer.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removetransformer.go index c8e188cec..7de87256f 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removetransformer.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/edit/remove/removetransformer.go @@ -5,6 +5,7 @@ package remove import ( "errors" + "slices" "github.com/spf13/cobra" "sigs.k8s.io/kustomize/api/konfig" @@ -72,7 +73,7 @@ func (o *removeTransformerOptions) RunRemoveTransformer(fSys filesys.FileSystem) newTransformers := make([]string, 0, len(m.Transformers)) for _, transformer := range m.Transformers { - if kustfile.StringInSlice(transformer, transformers) { + if slices.Contains(transformers, transformer) { continue } newTransformers = append(newTransformers, transformer) diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile/kustomizationfile.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile/kustomizationfile.go index 4804b5691..1f9e5f22b 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile/kustomizationfile.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile/kustomizationfile.go @@ -189,16 +189,6 @@ func (mf *kustomizationFile) Write(kustomization *types.Kustomization) error { return mf.fSys.WriteFile(mf.path, data) } -// StringInSlice returns true if the string is in the slice. -func StringInSlice(str string, list []string) bool { - for _, v := range list { - if v == str { - return true - } - } - return false -} - func (mf *kustomizationFile) parseCommentedFields(content []byte) error { buffer := bytes.NewBuffer(content) var comments [][]byte diff --git a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/internal/util/validate.go b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/internal/util/validate.go index bf041b50f..0fde88f78 100644 --- a/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/internal/util/validate.go +++ b/tools/vendor/sigs.k8s.io/kustomize/kustomize/v5/commands/internal/util/validate.go @@ -6,10 +6,10 @@ package util import ( "errors" "fmt" + "slices" "strings" "sigs.k8s.io/kustomize/api/types" - "sigs.k8s.io/kustomize/kustomize/v5/commands/internal/kustfile" ) type BuildMetadataValidator struct{} @@ -23,7 +23,7 @@ func (b *BuildMetadataValidator) Validate(args []string) ([]string, error) { } opts := strings.Split(args[0], ",") for _, opt := range opts { - if !kustfile.StringInSlice(opt, types.BuildMetadataOptions) { + if !slices.Contains(types.BuildMetadataOptions, opt) { return nil, fmt.Errorf("invalid buildMetadata option: %s", opt) } }