mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 13:42:02 +00:00
Make a RESTMapper scope aware
This commit is contained in:
@@ -103,7 +103,62 @@ func init() {
|
||||
return interfaces, true
|
||||
},
|
||||
)
|
||||
mapper.Add(api.Scheme, true, "v1beta1", "v1beta2")
|
||||
mapper.Add(api.Scheme, false, "v1beta3")
|
||||
// scopes that are used to qualify resources in the API
|
||||
namespaceAsQueryParam := meta.RESTScope{
|
||||
Name: "namespace",
|
||||
ParamName: "namespace",
|
||||
ParamPath: false,
|
||||
ParamDescription: "object name and auth scope, such as for teams and projects",
|
||||
}
|
||||
namespaceAsPathParam := meta.RESTScope{
|
||||
Name: "namespace",
|
||||
ParamName: "ns",
|
||||
ParamPath: true,
|
||||
ParamDescription: "object name and auth scope, such as for teams and projects",
|
||||
}
|
||||
rootScope := meta.RESTScope{
|
||||
Name: "root",
|
||||
ParamName: "",
|
||||
ParamPath: true,
|
||||
}
|
||||
|
||||
// list of versions we support on the server
|
||||
versions := []string{"v1beta1", "v1beta2", "v1beta3"}
|
||||
|
||||
// versions that used mixed case URL formats
|
||||
versionMixedCase := map[string]bool{
|
||||
"v1beta1": true,
|
||||
"v1beta2": true,
|
||||
}
|
||||
|
||||
// backwards compatibility, prior to v1beta3, we identified the namespace as a query parameter
|
||||
versionToNamespaceScope := map[string]meta.RESTScope{
|
||||
"v1beta1": namespaceAsQueryParam,
|
||||
"v1beta2": namespaceAsQueryParam,
|
||||
"v1beta3": namespaceAsPathParam,
|
||||
}
|
||||
|
||||
// the list of kinds that are scoped at the root of the api hierarchy
|
||||
// if a kind is not enumerated here, it is assumed to have a namespace scope
|
||||
kindToRootScope := map[string]bool{
|
||||
"Node": true,
|
||||
"Minion": true,
|
||||
}
|
||||
|
||||
// enumerate all supported versions, get the kinds, and register with the mapper how to address our resources
|
||||
for _, version := range versions {
|
||||
for kind := range api.Scheme.KnownTypes(version) {
|
||||
mixedCase, found := versionMixedCase[version]
|
||||
if !found {
|
||||
mixedCase = false
|
||||
}
|
||||
scope := versionToNamespaceScope[version]
|
||||
_, found = kindToRootScope[kind]
|
||||
if found {
|
||||
scope = rootScope
|
||||
}
|
||||
mapper.Add(scope, kind, version, mixedCase)
|
||||
}
|
||||
}
|
||||
RESTMapper = mapper
|
||||
}
|
||||
|
Reference in New Issue
Block a user