Use resid.ResId in replacements.

This commit is contained in:
monopole
2021-04-22 20:41:18 -07:00
parent d5d44ce3fe
commit c828b1e49a
10 changed files with 195 additions and 84 deletions

View File

@@ -3,6 +3,13 @@
package types
import (
"fmt"
"strings"
"sigs.k8s.io/kustomize/api/resid"
)
const DefaultReplacementFieldPath = "metadata.name"
// Replacement defines how to perform a substitution
@@ -18,7 +25,7 @@ type Replacement struct {
// SourceSelector is the source of the replacement transformer.
type SourceSelector struct {
// A specific object to read it from.
KrmId `json:",inline,omitempty" yaml:",inline,omitempty"`
resid.ResId `json:",inline,omitempty" yaml:",inline,omitempty"`
// Structured field path expected in the allowed object.
FieldPath string `json:"fieldPath" yaml:"fieldPath"`
@@ -27,6 +34,20 @@ type SourceSelector struct {
Options *FieldOptions `json:"options" yaml:"options"`
}
func (s *SourceSelector) String() string {
if s == nil {
return ""
}
result := []string{s.ResId.String()}
if s.FieldPath != "" {
result = append(result, s.FieldPath)
}
if opts := s.Options.String(); opts != "" {
result = append(result, opts)
}
return strings.Join(result, ":")
}
// TargetSelector specifies fields in one or more objects.
type TargetSelector struct {
// Include objects that match this.
@@ -57,3 +78,10 @@ type FieldOptions struct {
// If field missing, add it.
Create bool `json:"create" yaml:"create"`
}
func (fo *FieldOptions) String() string {
if fo == nil || fo.Delimiter == "" {
return ""
}
return fmt.Sprintf("%s(%d)", fo.Delimiter, fo.Index)
}