Skip to content

Commit

Permalink
throw error instead of panic when replacements source.fieldPath doesn…
Browse files Browse the repository at this point in the history
…'t exist
  • Loading branch information
natasha41575 committed Sep 2, 2021
1 parent da05822 commit 1145f2d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 4 additions & 3 deletions api/filters/replacement/replacement.go
Expand Up @@ -131,10 +131,11 @@ func getReplacement(nodes []*yaml.RNode, r *types.Replacement) (*yaml.RNode, err
if err != nil {
return nil, err
}
if !rn.IsNilOrEmpty() {
return getRefinedValue(r.Source.Options, rn)
if rn.IsNilOrEmpty() {
return nil, fmt.Errorf("fieldPath `%s` is missing for replacement source %s", r.Source.FieldPath, r.Source)
}
return rn, nil

return getRefinedValue(r.Source.Options, rn)
}

func getRefinedValue(options *types.FieldOptions, rn *yaml.RNode) (*yaml.RNode, error) {
Expand Down
4 changes: 1 addition & 3 deletions api/filters/replacement/replacement_test.go
Expand Up @@ -1573,7 +1573,6 @@ data:
grpcPort: 8081
`,
replacements: `replacements:
# failing case
- source:
kind: ConfigMap
name: ports-from
Expand All @@ -1587,8 +1586,7 @@ data:
options:
create: true
`,
// this test currently panics instead of throwing an error
expectedErr: "fieldPath data.httpPort is missing for source ~G_~V_ConfigMap|~X|ports-from:data.httpPort",
expectedErr: "fieldPath `data.httpPort` is missing for replacement source ~G_~V_ConfigMap|~X|ports-from:data.httpPort",
},
}

Expand Down

0 comments on commit 1145f2d

Please sign in to comment.