kubectl apply parse libraries copy extensions to references and list elements

when getting field / type metadata from openapi, copy the openapi extensions from

- references to the underlying type
- lists to the subtype
This commit is contained in:
Phillip Wittrock
2017-10-31 14:34:50 -07:00
parent 1fef312102
commit 1b7118d965
2 changed files with 64 additions and 4 deletions

View File

@@ -101,13 +101,20 @@ func getFieldMeta(s proto.Schema, name string) (apply.FieldMetaImpl, error) {
m := apply.FieldMetaImpl{}
if s != nil {
ext := s.GetExtensions()
if s, found := ext["x-kubernetes-patch-strategy"]; found {
strategy, ok := s.(string)
if e, found := ext["x-kubernetes-patch-strategy"]; found {
strategy, ok := e.(string)
if !ok {
return apply.FieldMetaImpl{}, fmt.Errorf("Expected string for x-kubernetes-patch-strategy by got %T", s)
}
// TODO: Support multi-strategy
m.MergeType = strategy
// Take the first strategy if there are substrategies.
// Sub strategies are copied to sub types in openapi.go
strategies := strings.Split(strategy, ",")
if len(strategies) > 2 {
return apply.FieldMetaImpl{}, fmt.Errorf("Expected between 0 and 2 elements for x-kubernetes-patch-merge-strategy by got %v", strategies)
}
// For lists, choose the strategy for this type, not the subtype
m.MergeType = strategies[0]
}
if k, found := ext["x-kubernetes-patch-merge-key"]; found {
key, ok := k.(string)