Merge pull request #2006 from pwittrock/set

Move setters to be available as libraries
This commit is contained in:
Kubernetes Prow Robot
2019-12-21 16:53:33 -08:00
committed by GitHub
9 changed files with 23 additions and 23 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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"

View File

@@ -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)

View File

@@ -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"

View File

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

View File

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

View File

@@ -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"

View File

@@ -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"