From ad4eb87e2e5413826c4cbe1d1de5878eb32e4345 Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Sat, 21 Dec 2019 16:14:19 -0800 Subject: [PATCH] move setters to be available as libraries --- cmd/config/internal/commands/cmdsub.go | 6 ++--- cmd/config/internal/commands/cmdsubcreate.go | 4 ++-- .../internal/sub => kyaml/set}/addkio.go | 2 +- .../internal/sub => kyaml/set}/addyaml.go | 24 +++++++++---------- .../internal/sub => kyaml/set}/dokio.go | 2 +- .../internal/sub => kyaml/set}/doyaml.go | 2 +- .../internal/sub => kyaml/set}/lookupkio.go | 2 +- .../internal/sub => kyaml/set}/lookupyaml.go | 2 +- .../internal/sub => kyaml/set}/types.go | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) rename {cmd/config/internal/sub => kyaml/set}/addkio.go (98%) rename {cmd/config/internal/sub => kyaml/set}/addyaml.go (80%) rename {cmd/config/internal/sub => kyaml/set}/dokio.go (99%) rename {cmd/config/internal/sub => kyaml/set}/doyaml.go (99%) rename {cmd/config/internal/sub => kyaml/set}/lookupkio.go (99%) rename {cmd/config/internal/sub => kyaml/set}/lookupyaml.go (99%) rename {cmd/config/internal/sub => kyaml/set}/types.go (98%) diff --git a/cmd/config/internal/commands/cmdsub.go b/cmd/config/internal/commands/cmdsub.go index ebb8e6f19..8c4c3834d 100644 --- a/cmd/config/internal/commands/cmdsub.go +++ b/cmd/config/internal/commands/cmdsub.go @@ -21,9 +21,9 @@ import ( "github.com/olekukonko/tablewriter" "github.com/spf13/cobra" "sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands" - "sigs.k8s.io/kustomize/cmd/config/internal/sub" "sigs.k8s.io/kustomize/kyaml/errors" "sigs.k8s.io/kustomize/kyaml/kio" + "sigs.k8s.io/kustomize/kyaml/set" ) // NewSubRunner returns a command runner. @@ -55,8 +55,8 @@ func SubCommand(parent string) *cobra.Command { type SubRunner struct { Command *cobra.Command - Lookup sub.LookupSubstitutions - Perform sub.PerformSubstitutions + Lookup set.LookupSubstitutions + Perform set.PerformSubstitutions } func (r *SubRunner) preRunE(c *cobra.Command, args []string) error { diff --git a/cmd/config/internal/commands/cmdsubcreate.go b/cmd/config/internal/commands/cmdsubcreate.go index ee9378b64..680584a95 100644 --- a/cmd/config/internal/commands/cmdsubcreate.go +++ b/cmd/config/internal/commands/cmdsubcreate.go @@ -17,8 +17,8 @@ package commands import ( "github.com/spf13/cobra" "sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands" - "sigs.k8s.io/kustomize/cmd/config/internal/sub" "sigs.k8s.io/kustomize/kyaml/kio" + "sigs.k8s.io/kustomize/kyaml/set" ) // NewSubSetRunner returns a command runner. @@ -62,7 +62,7 @@ func SubSetCommand(parent string) *cobra.Command { type SubSetRunner struct { Command *cobra.Command - Set sub.SetSubstitutionMarker + Set set.SetSubstitutionMarker } func (r *SubSetRunner) runE(c *cobra.Command, args []string) error { diff --git a/cmd/config/internal/sub/addkio.go b/kyaml/set/addkio.go similarity index 98% rename from cmd/config/internal/sub/addkio.go rename to kyaml/set/addkio.go index dff71f983..2ec66213a 100644 --- a/cmd/config/internal/sub/addkio.go +++ b/kyaml/set/addkio.go @@ -1,7 +1,7 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -package sub +package set import ( "sigs.k8s.io/kustomize/kyaml/kio" diff --git a/cmd/config/internal/sub/addyaml.go b/kyaml/set/addyaml.go similarity index 80% rename from cmd/config/internal/sub/addyaml.go rename to kyaml/set/addyaml.go index 118d054da..3255c2560 100644 --- a/cmd/config/internal/sub/addyaml.go +++ b/kyaml/set/addyaml.go @@ -1,7 +1,7 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -package sub +package set import ( "strings" @@ -65,10 +65,10 @@ func (m *Marker) Filter(object *yaml.RNode) (*yaml.RNode, error) { } } -func (as *Marker) createSub(field *yaml.RNode) error { +func (m *Marker) createSub(field *yaml.RNode) error { // doesn't match the supplied value - if field.YNode().Value != as.Substitution.Value { - if !as.PartialMatch || !strings.Contains(field.YNode().Value, as.Substitution.Value) { + if field.YNode().Value != m.Substitution.Value { + if !m.PartialMatch || !strings.Contains(field.YNode().Value, m.Substitution.Value) { return nil } } @@ -77,26 +77,26 @@ func (as *Marker) createSub(field *yaml.RNode) error { if err := fm.Read(field); err != nil { return errors.Wrap(err) } - fm.OwnedBy = as.OwnedBy - fm.Description = as.Description - fm.Type = fieldmeta.FieldValueType(as.Type) - if as.Substitution.Marker == "" { - as.Substitution.Marker = "[MARKER]" + fm.OwnedBy = m.OwnedBy + fm.Description = m.Description + fm.Type = fieldmeta.FieldValueType(m.Type) + if m.Substitution.Marker == "" { + m.Substitution.Marker = "[MARKER]" } found := false for i := range fm.Substitutions { s := fm.Substitutions[i] - if s.Name == as.Substitution.Name { + if s.Name == m.Substitution.Name { // update the substitution if we find it found = true - fm.Substitutions[i] = as.Substitution + fm.Substitutions[i] = m.Substitution break } } if !found { // add the substitution if it wasn't found - fm.Substitutions = append(fm.Substitutions, as.Substitution) + fm.Substitutions = append(fm.Substitutions, m.Substitution) } if err := fm.Write(field); err != nil { return errors.Wrap(err) diff --git a/cmd/config/internal/sub/dokio.go b/kyaml/set/dokio.go similarity index 99% rename from cmd/config/internal/sub/dokio.go rename to kyaml/set/dokio.go index 794283a8b..cf982b619 100644 --- a/cmd/config/internal/sub/dokio.go +++ b/kyaml/set/dokio.go @@ -1,7 +1,7 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -package sub +package set import ( "sigs.k8s.io/kustomize/kyaml/kio" diff --git a/cmd/config/internal/sub/doyaml.go b/kyaml/set/doyaml.go similarity index 99% rename from cmd/config/internal/sub/doyaml.go rename to kyaml/set/doyaml.go index 19c2b5198..4b78edf18 100644 --- a/cmd/config/internal/sub/doyaml.go +++ b/kyaml/set/doyaml.go @@ -13,7 +13,7 @@ // limitations under the License. // Package sub substitutes strings in fields -package sub +package set import ( "strings" diff --git a/cmd/config/internal/sub/lookupkio.go b/kyaml/set/lookupkio.go similarity index 99% rename from cmd/config/internal/sub/lookupkio.go rename to kyaml/set/lookupkio.go index 76921c119..05ac4b65a 100644 --- a/cmd/config/internal/sub/lookupkio.go +++ b/kyaml/set/lookupkio.go @@ -1,7 +1,7 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -package sub +package set import ( "sort" diff --git a/cmd/config/internal/sub/lookupyaml.go b/kyaml/set/lookupyaml.go similarity index 99% rename from cmd/config/internal/sub/lookupyaml.go rename to kyaml/set/lookupyaml.go index dee2abf29..7c26acdbb 100644 --- a/cmd/config/internal/sub/lookupyaml.go +++ b/kyaml/set/lookupyaml.go @@ -1,7 +1,7 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -package sub +package set import ( "sigs.k8s.io/kustomize/kyaml/fieldmeta" diff --git a/cmd/config/internal/sub/types.go b/kyaml/set/types.go similarity index 98% rename from cmd/config/internal/sub/types.go rename to kyaml/set/types.go index f8b6a86b7..5b8557398 100644 --- a/cmd/config/internal/sub/types.go +++ b/kyaml/set/types.go @@ -1,7 +1,7 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -package sub +package set import ( "sigs.k8s.io/kustomize/kyaml/fieldmeta"