mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
return subst name inerror message
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user