move setters to be available as libraries

This commit is contained in:
Phillip Wittrock
2019-12-21 16:14:19 -08:00
parent 19928abb6f
commit ad4eb87e2e
9 changed files with 23 additions and 23 deletions

View File

@@ -21,9 +21,9 @@ import (
"github.com/olekukonko/tablewriter" "github.com/olekukonko/tablewriter"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands" "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/errors"
"sigs.k8s.io/kustomize/kyaml/kio" "sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/set"
) )
// NewSubRunner returns a command runner. // NewSubRunner returns a command runner.
@@ -55,8 +55,8 @@ func SubCommand(parent string) *cobra.Command {
type SubRunner struct { type SubRunner struct {
Command *cobra.Command Command *cobra.Command
Lookup sub.LookupSubstitutions Lookup set.LookupSubstitutions
Perform sub.PerformSubstitutions Perform set.PerformSubstitutions
} }
func (r *SubRunner) preRunE(c *cobra.Command, args []string) error { func (r *SubRunner) preRunE(c *cobra.Command, args []string) error {

View File

@@ -17,8 +17,8 @@ package commands
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands" "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/kio"
"sigs.k8s.io/kustomize/kyaml/set"
) )
// NewSubSetRunner returns a command runner. // NewSubSetRunner returns a command runner.
@@ -62,7 +62,7 @@ func SubSetCommand(parent string) *cobra.Command {
type SubSetRunner struct { type SubSetRunner struct {
Command *cobra.Command Command *cobra.Command
Set sub.SetSubstitutionMarker Set set.SetSubstitutionMarker
} }
func (r *SubSetRunner) runE(c *cobra.Command, args []string) error { func (r *SubSetRunner) runE(c *cobra.Command, args []string) error {

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package sub package set
import ( import (
"sigs.k8s.io/kustomize/kyaml/kio" "sigs.k8s.io/kustomize/kyaml/kio"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package sub package set
import ( import (
"strings" "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 // doesn't match the supplied value
if field.YNode().Value != as.Substitution.Value { if field.YNode().Value != m.Substitution.Value {
if !as.PartialMatch || !strings.Contains(field.YNode().Value, as.Substitution.Value) { if !m.PartialMatch || !strings.Contains(field.YNode().Value, m.Substitution.Value) {
return nil return nil
} }
} }
@@ -77,26 +77,26 @@ func (as *Marker) createSub(field *yaml.RNode) error {
if err := fm.Read(field); err != nil { if err := fm.Read(field); err != nil {
return errors.Wrap(err) return errors.Wrap(err)
} }
fm.OwnedBy = as.OwnedBy fm.OwnedBy = m.OwnedBy
fm.Description = as.Description fm.Description = m.Description
fm.Type = fieldmeta.FieldValueType(as.Type) fm.Type = fieldmeta.FieldValueType(m.Type)
if as.Substitution.Marker == "" { if m.Substitution.Marker == "" {
as.Substitution.Marker = "[MARKER]" m.Substitution.Marker = "[MARKER]"
} }
found := false found := false
for i := range fm.Substitutions { for i := range fm.Substitutions {
s := fm.Substitutions[i] s := fm.Substitutions[i]
if s.Name == as.Substitution.Name { if s.Name == m.Substitution.Name {
// update the substitution if we find it // update the substitution if we find it
found = true found = true
fm.Substitutions[i] = as.Substitution fm.Substitutions[i] = m.Substitution
break break
} }
} }
if !found { if !found {
// add the substitution if it wasn't 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 { if err := fm.Write(field); err != nil {
return errors.Wrap(err) return errors.Wrap(err)

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package sub package set
import ( import (
"sigs.k8s.io/kustomize/kyaml/kio" "sigs.k8s.io/kustomize/kyaml/kio"

View File

@@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
// Package sub substitutes strings in fields // Package sub substitutes strings in fields
package sub package set
import ( import (
"strings" "strings"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package sub package set
import ( import (
"sort" "sort"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package sub package set
import ( import (
"sigs.k8s.io/kustomize/kyaml/fieldmeta" "sigs.k8s.io/kustomize/kyaml/fieldmeta"

View File

@@ -1,7 +1,7 @@
// Copyright 2019 The Kubernetes Authors. // Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package sub package set
import ( import (
"sigs.k8s.io/kustomize/kyaml/fieldmeta" "sigs.k8s.io/kustomize/kyaml/fieldmeta"