- Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathreplacement.go
90 lines (70 loc) · 2.68 KB
/
replacement.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package types
import (
"fmt"
"strings"
"sigs.k8s.io/kustomize/kyaml/resid"
)
constDefaultReplacementFieldPath="metadata.name"
// Replacement defines how to perform a substitution
// where it is from and where it is to.
typeReplacementstruct {
// The source of the value.
Source*SourceSelector`json:"source,omitempty" yaml:"source,omitempty"`
// The N fields to write the value to.
Targets []*TargetSelector`json:"targets,omitempty" yaml:"targets,omitempty"`
// Used to define an static value
SourceValue*string`json:"sourceValue,omitempty" yaml:"sourceValue,omitempty"`
}
// SourceSelector is the source of the replacement transformer.
typeSourceSelectorstruct {
// A specific object to read it from.
resid.ResId`json:",inline,omitempty" yaml:",inline,omitempty"`
// Structured field path expected in the allowed object.
FieldPathstring`json:"fieldPath,omitempty" yaml:"fieldPath,omitempty"`
// Used to refine the interpretation of the field.
Options*FieldOptions`json:"options,omitempty" yaml:"options,omitempty"`
}
func (s*SourceSelector) String() string {
ifs==nil {
return""
}
result:= []string{s.ResId.String()}
ifs.FieldPath!="" {
result=append(result, s.FieldPath)
}
ifopts:=s.Options.String(); opts!="" {
result=append(result, opts)
}
returnstrings.Join(result, ":")
}
// TargetSelector specifies fields in one or more objects.
typeTargetSelectorstruct {
// Include objects that match this.
Select*Selector`json:"select" yaml:"select"`
// From the allowed set, remove objects that match this.
Reject []*Selector`json:"reject,omitempty" yaml:"reject,omitempty"`
// Structured field paths expected in each allowed object.
FieldPaths []string`json:"fieldPaths,omitempty" yaml:"fieldPaths,omitempty"`
// Used to refine the interpretation of the field.
Options*FieldOptions`json:"options,omitempty" yaml:"options,omitempty"`
}
// FieldOptions refine the interpretation of FieldPaths.
typeFieldOptionsstruct {
// Used to split/join the field.
Delimiterstring`json:"delimiter,omitempty" yaml:"delimiter,omitempty"`
// Which position in the split to consider.
Indexint`json:"index,omitempty" yaml:"index,omitempty"`
// TODO (#3492): Implement use of this option
// None, Base64, URL, Hex, etc
Encodingstring`json:"encoding,omitempty" yaml:"encoding,omitempty"`
// If field missing, add it.
Createbool`json:"create,omitempty" yaml:"create,omitempty"`
}
func (fo*FieldOptions) String() string {
iffo==nil|| (fo.Delimiter==""&&!fo.Create) {
return""
}
returnfmt.Sprintf("%s(%d), create=%t", fo.Delimiter, fo.Index, fo.Create)
}