return subst name inerror message

This commit is contained in:
Jijie Wei
2020-06-18 12:47:20 -07:00
parent 22a6017870
commit e4ba898e20
2 changed files with 10 additions and 8 deletions

View File

@@ -222,7 +222,7 @@ openAPI:
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
`, `,
err: `setter is used in substitution, please delete the substitution first`, err: `setter is used in substitution image, please delete the substitution first`,
}, },
} }
for i := range tests { for i := range tests {

View File

@@ -73,11 +73,11 @@ func (dd DeleterDefinition) DeleteFromFile(path string) error {
return yaml.UpdateFile(dd, path) return yaml.UpdateFile(dd, path)
} }
// ContainedInSubstituion check if the setter used in substituition // ContainedInSubstituion check if the setter used in substituition and return the substitution name if true
func ContainedInSubstituion(definitions *yaml.RNode, key string) bool { func ContainedInSubstituion(definitions *yaml.RNode, key string) string {
fieldNames, err := definitions.Fields() fieldNames, err := definitions.Fields()
if err != nil { if err != nil {
return false return ""
} }
for _, fieldname := range fieldNames { for _, fieldname := range fieldNames {
// the definition key -- contains the substitution name // the definition key -- contains the substitution name
@@ -100,13 +100,13 @@ func ContainedInSubstituion(definitions *yaml.RNode, key string) bool {
// Check the ref in value to see if it contains the setter key // Check the ref in value to see if it contains the setter key
for _, v := range subst.Values { for _, v := range subst.Values {
if strings.HasSuffix(v.Ref, key) { if strings.HasSuffix(v.Ref, key) {
return true return subst.Name
} }
} }
} }
} }
return false return ""
} }
func (dd DeleterDefinition) Filter(object *yaml.RNode) (*yaml.RNode, error) { func (dd DeleterDefinition) Filter(object *yaml.RNode) (*yaml.RNode, error) {
@@ -121,8 +121,10 @@ func (dd DeleterDefinition) Filter(object *yaml.RNode) (*yaml.RNode, error) {
return nil, errors.Errorf("setter does not exist") return nil, errors.Errorf("setter does not exist")
} }
if ContainedInSubstituion(definitions, key) { subst := ContainedInSubstituion(definitions, key)
return nil, errors.Errorf("setter is used in substitution, please delete the substitution first")
if subst != "" {
return nil, errors.Errorf("setter is used in substitution %s, please delete the substitution first", subst)
} }
for i := 0; i < len(definitions.Content()); i += 2 { for i := 0; i < len(definitions.Content()); i += 2 {