...
1
2
3
4 package types
5
6 import (
7 "fmt"
8 "strings"
9
10 "sigs.k8s.io/kustomize/kyaml/resid"
11 )
12
13 const DefaultReplacementFieldPath = "metadata.name"
14
15
16
17 type Replacement struct {
18
19 Source *SourceSelector `json:"source,omitempty" yaml:"source,omitempty"`
20
21
22 Targets []*TargetSelector `json:"targets,omitempty" yaml:"targets,omitempty"`
23 }
24
25
26 type SourceSelector struct {
27
28 resid.ResId `json:",inline,omitempty" yaml:",inline,omitempty"`
29
30
31 FieldPath string `json:"fieldPath,omitempty" yaml:"fieldPath,omitempty"`
32
33
34 Options *FieldOptions `json:"options,omitempty" yaml:"options,omitempty"`
35 }
36
37 func (s *SourceSelector) String() string {
38 if s == nil {
39 return ""
40 }
41 result := []string{s.ResId.String()}
42 if s.FieldPath != "" {
43 result = append(result, s.FieldPath)
44 }
45 if opts := s.Options.String(); opts != "" {
46 result = append(result, opts)
47 }
48 return strings.Join(result, ":")
49 }
50
51
52 type TargetSelector struct {
53
54 Select *Selector `json:"select" yaml:"select"`
55
56
57 Reject []*Selector `json:"reject,omitempty" yaml:"reject,omitempty"`
58
59
60 FieldPaths []string `json:"fieldPaths,omitempty" yaml:"fieldPaths,omitempty"`
61
62
63 Options *FieldOptions `json:"options,omitempty" yaml:"options,omitempty"`
64 }
65
66
67 type FieldOptions struct {
68
69 Delimiter string `json:"delimiter,omitempty" yaml:"delimiter,omitempty"`
70
71
72 Index int `json:"index,omitempty" yaml:"index,omitempty"`
73
74
75
76 Encoding string `json:"encoding,omitempty" yaml:"encoding,omitempty"`
77
78
79 Create bool `json:"create,omitempty" yaml:"create,omitempty"`
80 }
81
82 func (fo *FieldOptions) String() string {
83 if fo == nil || (fo.Delimiter == "" && !fo.Create) {
84 return ""
85 }
86 return fmt.Sprintf("%s(%d), create=%t", fo.Delimiter, fo.Index, fo.Create)
87 }
88
View as plain text