Allow multiple patch strategies.

This commit is contained in:
jregan
2020-06-26 14:42:09 -07:00
parent cebb1b31ab
commit 781e396122
3 changed files with 65 additions and 6 deletions

View File

@@ -5,22 +5,21 @@
package schema
import (
"strings"
"sigs.k8s.io/kustomize/kyaml/openapi"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
// IsAssociative returns true if all elements in the list contain an AssociativeSequenceKey
// as a field.
// IsAssociative returns true if all elements in the list contain an
// AssociativeSequenceKey as a field.
func IsAssociative(schema *openapi.ResourceSchema, nodes []*yaml.RNode, infer bool) bool {
if schema != nil {
// use the schema to identify if the list is associative
s, _ := schema.PatchStrategyAndKey()
return s == "merge"
return schemaHasMergeStrategy(schema)
}
if !infer {
return false
}
for i := range nodes {
node := nodes[i]
if yaml.IsEmpty(node) {
@@ -32,3 +31,14 @@ func IsAssociative(schema *openapi.ResourceSchema, nodes []*yaml.RNode, infer bo
}
return false
}
func schemaHasMergeStrategy(schema *openapi.ResourceSchema) bool {
tmp, _ := schema.PatchStrategyAndKey()
strategies := strings.Split(tmp, ",")
for _, s := range strategies {
if s == "merge" {
return true
}
}
return false
}