Unverified Commit 42b63c8b authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #63627 from roycaihw/release-1.10

Automatic merge from submit-queue. Manual cherrypick of kube-openapi changes for release-1.10 **What this PR does / why we need it**: Cherry-picks kubernetes/kube-openapi#64 and kubernetes/kube-openapi#67 Fixes bugs that make apiserver panic when aggregating valid but not well formed OpenAPI spec (with empty `Paths`/`Definitions`) **Release note**: ```release-note Fixes bugs that make apiserver panic when aggregating valid but not well formed OpenAPI spec ``` /cc @MaciekPytel /sig api-machinery
parents 5e65ac1d 56d903a4
......@@ -3288,35 +3288,35 @@
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/aggregator",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/builder",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/common",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/generators",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/handler",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto/validation",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/utils/clock",
......
......@@ -2000,23 +2000,23 @@
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/builder",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/common",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/handler",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/equality",
......
......@@ -172,7 +172,7 @@
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
}
]
}
......@@ -1732,23 +1732,23 @@
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/builder",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/common",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/handler",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/client-go/discovery",
......
......@@ -576,7 +576,7 @@
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
}
]
}
......@@ -260,11 +260,11 @@
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/common",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/generators",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
}
]
}
......@@ -1644,27 +1644,27 @@
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/aggregator",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/builder",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/common",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/handler",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
}
]
}
......@@ -1608,23 +1608,23 @@
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/builder",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/common",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/handler",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
}
]
}
......@@ -912,7 +912,7 @@
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto",
"Rev": "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf"
"Rev": "39cb288412c48cb533ba4be5d6c28620b9a0c1b4"
}
]
}
......@@ -61,6 +61,10 @@ func (s *referenceWalker) walkRef(ref spec.Ref) spec.Ref {
k := refStr[len(definitionPrefix):]
def := s.root.Definitions[k]
s.walkSchema(&def)
// Make sure we don't assign to nil map
if s.root.Definitions == nil {
s.root.Definitions = spec.Definitions{}
}
s.root.Definitions[k] = def
}
return s.walkRefCallback(ref)
......@@ -147,6 +151,9 @@ func (s *referenceWalker) walkOperation(op *spec.Operation) {
}
func (s *referenceWalker) Start() {
if s.root.Paths == nil {
return
}
for _, pathItem := range s.root.Paths.Paths {
s.walkParams(pathItem.Parameters)
s.walkOperation(pathItem.Delete)
......@@ -220,6 +227,10 @@ func renameDefinition(s *spec.Swagger, old, new string) {
}
return ref
}, s)
// Make sure we don't assign to nil map
if s.Definitions == nil {
s.Definitions = spec.Definitions{}
}
s.Definitions[new] = s.Definitions[old]
delete(s.Definitions, old)
}
......@@ -244,6 +255,13 @@ func MergeSpecs(dest, source *spec.Swagger) error {
func mergeSpecs(dest, source *spec.Swagger, renameModelConflicts, ignorePathConflicts bool) (err error) {
specCloned := false
// Paths may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering).
if source.Paths == nil {
source.Paths = &spec.Paths{}
}
if dest.Paths == nil {
dest.Paths = &spec.Paths{}
}
if ignorePathConflicts {
keepPaths := []string{}
hasConflictingPath := false
......@@ -335,6 +353,9 @@ func mergeSpecs(dest, source *spec.Swagger, renameModelConflicts, ignorePathConf
}
for k, v := range source.Definitions {
if _, found := dest.Definitions[k]; !found {
if dest.Definitions == nil {
dest.Definitions = spec.Definitions{}
}
dest.Definitions[k] = v
}
}
......@@ -343,6 +364,10 @@ func mergeSpecs(dest, source *spec.Swagger, renameModelConflicts, ignorePathConf
if _, found := dest.Paths.Paths[k]; found {
return fmt.Errorf("unable to merge: duplicated path %s", k)
}
// PathItem may be empty, due to [ACL constraints](http://goo.gl/8us55a#securityFiltering).
if dest.Paths.Paths == nil {
dest.Paths.Paths = map[string]spec.PathItem{}
}
dest.Paths.Paths[k] = v
}
return nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment