...

Source file src/sigs.k8s.io/kustomize/kyaml/yaml/schema/schema.go

Documentation: sigs.k8s.io/kustomize/kyaml/yaml/schema

     1  // Copyright 2019 The Kubernetes Authors.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  // Package schema contains libraries for working with the yaml and openapi packages.
     5  package schema
     6  
     7  import (
     8  	"strings"
     9  
    10  	"sigs.k8s.io/kustomize/kyaml/openapi"
    11  	"sigs.k8s.io/kustomize/kyaml/yaml"
    12  )
    13  
    14  // IsAssociative returns true if all elements in the list contain an
    15  // AssociativeSequenceKey as a field.
    16  func IsAssociative(schema *openapi.ResourceSchema, nodes []*yaml.RNode, infer bool) bool {
    17  	if schema != nil {
    18  		return schemaHasMergeStrategy(schema)
    19  	}
    20  	if !infer {
    21  		return false
    22  	}
    23  	for i := range nodes {
    24  		node := nodes[i]
    25  		if yaml.IsMissingOrNull(node) {
    26  			continue
    27  		}
    28  		if node.IsAssociative() {
    29  			return true
    30  		}
    31  	}
    32  	return false
    33  }
    34  
    35  func schemaHasMergeStrategy(schema *openapi.ResourceSchema) bool {
    36  	tmp, _ := schema.PatchStrategyAndKey()
    37  	strategies := strings.Split(tmp, ",")
    38  	for _, s := range strategies {
    39  		if s == "merge" {
    40  			return true
    41  		}
    42  	}
    43  	return false
    44  }
    45  

View as plain text