Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements to replacements value in the structured data #5679

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 39 additions & 1 deletion api/filters/replacement/replacement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,44 @@ spec:
name: sidecar
imagePullPolicy: OnFailure
`,
},
"replacement contain jsonfield": {
input: `apiVersion: v1
kind: ConfigMap
metadata:
name: target-configmap
data:
config.json: |-
{
"config": {
"id": "42",
"hostname": "REPLACE_TARGET_HOSTNAME"
}
}
`,
replacements: `replacements:
- source:
kind: ConfigMap
name: target-configmap
fieldPath: metadata.name
targets:
- select:
kind: ConfigMap
fieldPaths:
- data.config\.json.config.hostname
`,
expected: `apiVersion: v1
kind: ConfigMap
metadata:
name: target-configmap
data:
config.json: |-
{
"config": {
"id": "42",
"hostname": "target-configmap"
}
}`,
},
"multiple field paths in target": {
input: `apiVersion: v1
Expand Down Expand Up @@ -2779,7 +2817,7 @@ spec:
name: myingress
fieldPaths:
- spec.tls.0.hosts.0
- spec.tls.0.secretName
- spec.tls.0.secretName
options:
create: true
`,
Expand Down
4 changes: 4 additions & 0 deletions kyaml/yaml/fns.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,10 @@ func (e *InvalidNodeKindError) Error() string {
return msg
}

func (e *InvalidNodeKindError) Unwrap() error {
return errors.Errorf("InvalidNodeKindError")
}

func (e *InvalidNodeKindError) ActualNodeKind() Kind {
return e.node.YNode().Kind
}
Expand Down
9 changes: 8 additions & 1 deletion kyaml/yaml/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,17 @@ func (p *PathMatcher) visitEveryElem(elem *RNode) error {
func (p *PathMatcher) doField(rn *RNode) (*RNode, error) {
// lookup the field
field, err := rn.Pipe(Get(p.Path[0]))
if err != nil || (!IsCreate(p.Create) && field == nil) {
if err != nil {
if errors.Is(err, &InvalidNodeKindError{}) {
fmt.Println(err)
}
return nil, err
}

if !IsCreate(p.Create) && field == nil {
return nil, nil
}

if IsCreate(p.Create) && field == nil {
var nextPart string
if len(p.Path) > 1 {
Expand Down