Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5c4fb5bc
Commit
5c4fb5bc
authored
Nov 16, 2015
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make RESTMapper.KindFor
parent
581a1ad1
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
41 additions
and
69 deletions
+41
-69
interfaces.go
pkg/api/meta/interfaces.go
+3
-4
restmapper.go
pkg/api/meta/restmapper.go
+8
-27
fixture.go
pkg/client/unversioned/testclient/fixture.go
+1
-6
explain.go
pkg/kubectl/cmd/explain.go
+2
-2
factory.go
pkg/kubectl/cmd/util/factory.go
+6
-6
kubectl.go
pkg/kubectl/kubectl.go
+6
-4
builder.go
pkg/kubectl/resource/builder.go
+4
-4
codec.go
pkg/registry/thirdpartyresourcedata/codec.go
+5
-10
admission.go
plugin/pkg/admission/namespace/autoprovision/admission.go
+2
-2
admission.go
plugin/pkg/admission/namespace/exists/admission.go
+2
-2
admission.go
plugin/pkg/admission/namespace/lifecycle/admission.go
+2
-2
No files found.
pkg/api/meta/interfaces.go
View file @
5c4fb5bc
...
@@ -147,10 +147,9 @@ type RESTMapping struct {
...
@@ -147,10 +147,9 @@ type RESTMapping struct {
// TODO(caesarxuchao): Add proper multi-group support so that kinds & resources are
// TODO(caesarxuchao): Add proper multi-group support so that kinds & resources are
// scoped to groups. See http://issues.k8s.io/12413 and http://issues.k8s.io/10009.
// scoped to groups. See http://issues.k8s.io/12413 and http://issues.k8s.io/10009.
type
RESTMapper
interface
{
type
RESTMapper
interface
{
VersionAndKindForResource
(
resource
string
)
(
defaultVersion
,
kind
string
,
err
error
)
// KindFor takes a resource and returns back the unambiguous Kind (GroupVersionKind)
// TODO(caesarxuchao): Remove GroupForResource when multi-group support is in (since
KindFor
(
resource
string
)
(
unversioned
.
GroupVersionKind
,
error
)
// group will be part of the version).
GroupForResource
(
resource
string
)
(
string
,
error
)
RESTMapping
(
kind
string
,
versions
...
string
)
(
*
RESTMapping
,
error
)
RESTMapping
(
kind
string
,
versions
...
string
)
(
*
RESTMapping
,
error
)
AliasesForResource
(
resource
string
)
([]
string
,
bool
)
AliasesForResource
(
resource
string
)
([]
string
,
bool
)
ResourceSingularizer
(
resource
string
)
(
singular
string
,
err
error
)
ResourceSingularizer
(
resource
string
)
(
singular
string
,
err
error
)
...
...
pkg/api/meta/restmapper.go
View file @
5c4fb5bc
...
@@ -80,6 +80,8 @@ type DefaultRESTMapper struct {
...
@@ -80,6 +80,8 @@ type DefaultRESTMapper struct {
interfacesFunc
VersionInterfacesFunc
interfacesFunc
VersionInterfacesFunc
}
}
var
_
RESTMapper
=
&
DefaultRESTMapper
{}
// VersionInterfacesFunc returns the appropriate codec, typer, and metadata accessor for a
// VersionInterfacesFunc returns the appropriate codec, typer, and metadata accessor for a
// given api version, or an error if no such api version exists.
// given api version, or an error if no such api version exists.
type
VersionInterfacesFunc
func
(
apiVersion
string
)
(
*
VersionInterfaces
,
error
)
type
VersionInterfacesFunc
func
(
apiVersion
string
)
(
*
VersionInterfaces
,
error
)
...
@@ -163,21 +165,12 @@ func (m *DefaultRESTMapper) ResourceSingularizer(resource string) (singular stri
...
@@ -163,21 +165,12 @@ func (m *DefaultRESTMapper) ResourceSingularizer(resource string) (singular stri
}
}
// VersionAndKindForResource implements RESTMapper
// VersionAndKindForResource implements RESTMapper
func
(
m
*
DefaultRESTMapper
)
VersionAndKindForResource
(
resource
string
)
(
gvString
,
kind
string
,
err
error
)
{
func
(
m
*
DefaultRESTMapper
)
KindFor
(
resource
string
)
(
unversioned
.
GroupVersionKind
,
error
)
{
gvk
,
ok
:=
m
.
resourceToKind
[
strings
.
ToLower
(
resource
)]
gvk
,
ok
:=
m
.
resourceToKind
[
strings
.
ToLower
(
resource
)]
if
!
ok
{
if
!
ok
{
return
""
,
""
,
fmt
.
Errorf
(
"in version and kind for resource, no resource %q has been defined"
,
resource
)
return
gvk
,
fmt
.
Errorf
(
"in version and kind for resource, no resource %q has been defined"
,
resource
)
}
}
return
gvk
.
GroupVersion
()
.
String
(),
gvk
.
Kind
,
nil
return
gvk
,
nil
}
func
(
m
*
DefaultRESTMapper
)
GroupForResource
(
resource
string
)
(
string
,
error
)
{
gvk
,
exists
:=
m
.
resourceToKind
[
strings
.
ToLower
(
resource
)]
if
!
exists
{
return
""
,
fmt
.
Errorf
(
"in group for resource, no resource %q has been defined"
,
resource
)
}
return
gvk
.
Group
,
nil
}
}
// RESTMapping returns a struct representing the resource path and conversion interfaces a
// RESTMapping returns a struct representing the resource path and conversion interfaces a
...
@@ -295,7 +288,7 @@ func (m *DefaultRESTMapper) AliasesForResource(alias string) ([]string, bool) {
...
@@ -295,7 +288,7 @@ func (m *DefaultRESTMapper) AliasesForResource(alias string) ([]string, bool) {
// ResourceIsValid takes a string (kind) and checks if it's a valid resource
// ResourceIsValid takes a string (kind) and checks if it's a valid resource
func
(
m
*
DefaultRESTMapper
)
ResourceIsValid
(
resource
string
)
bool
{
func
(
m
*
DefaultRESTMapper
)
ResourceIsValid
(
resource
string
)
bool
{
_
,
_
,
err
:=
m
.
VersionAndKindForResource
(
resource
)
_
,
err
:=
m
.
KindFor
(
resource
)
return
err
==
nil
return
err
==
nil
}
}
...
@@ -317,21 +310,9 @@ func (m MultiRESTMapper) ResourceSingularizer(resource string) (singular string,
...
@@ -317,21 +310,9 @@ func (m MultiRESTMapper) ResourceSingularizer(resource string) (singular string,
// VersionAndKindForResource provides the Version and Kind mappings for the
// VersionAndKindForResource provides the Version and Kind mappings for the
// REST resources. This implementation supports multiple REST schemas and return
// REST resources. This implementation supports multiple REST schemas and return
// the first match.
// the first match.
func
(
m
MultiRESTMapper
)
VersionAndKindForResource
(
resource
string
)
(
defaultVersion
,
kind
string
,
err
error
)
{
func
(
m
MultiRESTMapper
)
KindFor
(
resource
string
)
(
gvk
unversioned
.
GroupVersionKind
,
err
error
)
{
for
_
,
t
:=
range
m
{
defaultVersion
,
kind
,
err
=
t
.
VersionAndKindForResource
(
resource
)
if
err
==
nil
{
return
}
}
return
}
// GroupForResource provides the Group mappings for the REST resources. This
// implementation supports multiple REST schemas and returns the first match.
func
(
m
MultiRESTMapper
)
GroupForResource
(
resource
string
)
(
group
string
,
err
error
)
{
for
_
,
t
:=
range
m
{
for
_
,
t
:=
range
m
{
g
roup
,
err
=
t
.
GroupForResource
(
resource
)
g
vk
,
err
=
t
.
KindFor
(
resource
)
if
err
==
nil
{
if
err
==
nil
{
return
return
}
}
...
...
pkg/client/unversioned/testclient/fixture.go
View file @
5c4fb5bc
...
@@ -59,15 +59,10 @@ type ObjectScheme interface {
...
@@ -59,15 +59,10 @@ type ObjectScheme interface {
func
ObjectReaction
(
o
ObjectRetriever
,
mapper
meta
.
RESTMapper
)
ReactionFunc
{
func
ObjectReaction
(
o
ObjectRetriever
,
mapper
meta
.
RESTMapper
)
ReactionFunc
{
return
func
(
action
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
return
func
(
action
Action
)
(
bool
,
runtime
.
Object
,
error
)
{
gv
String
,
kind
,
err
:=
mapper
.
VersionAndKindForResource
(
action
.
GetResource
())
gv
k
,
err
:=
mapper
.
KindFor
(
action
.
GetResource
())
if
err
!=
nil
{
if
err
!=
nil
{
return
false
,
nil
,
fmt
.
Errorf
(
"unrecognized action %s: %v"
,
action
.
GetResource
(),
err
)
return
false
,
nil
,
fmt
.
Errorf
(
"unrecognized action %s: %v"
,
action
.
GetResource
(),
err
)
}
}
gv
,
err
:=
unversioned
.
ParseGroupVersion
(
gvString
)
if
err
!=
nil
{
return
false
,
nil
,
err
}
gvk
:=
gv
.
WithKind
(
kind
)
// TODO: have mapper return a Kind for a subresource?
// TODO: have mapper return a Kind for a subresource?
switch
castAction
:=
action
.
(
type
)
{
switch
castAction
:=
action
.
(
type
)
{
...
...
pkg/kubectl/cmd/explain.go
View file @
5c4fb5bc
...
@@ -82,13 +82,13 @@ func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
...
@@ -82,13 +82,13 @@ func RunExplain(f *cmdutil.Factory, out io.Writer, cmd *cobra.Command, args []st
}
}
// TODO: We should deduce the group for a resource by discovering the supported resources at server.
// TODO: We should deduce the group for a resource by discovering the supported resources at server.
g
roup
,
err
:=
mapper
.
GroupForResource
(
inModel
)
g
vk
,
err
:=
mapper
.
KindFor
(
inModel
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
if
len
(
apiV
)
==
0
{
if
len
(
apiV
)
==
0
{
groupMeta
,
err
:=
latest
.
Group
(
group
)
groupMeta
,
err
:=
latest
.
Group
(
g
vk
.
G
roup
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/kubectl/cmd/util/factory.go
View file @
5c4fb5bc
...
@@ -151,7 +151,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -151,7 +151,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
clients
.
ClientConfigForVersion
(
""
)
return
clients
.
ClientConfigForVersion
(
""
)
},
},
RESTClient
:
func
(
mapping
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
{
RESTClient
:
func
(
mapping
*
meta
.
RESTMapping
)
(
resource
.
RESTClient
,
error
)
{
g
roup
,
err
:=
api
.
RESTMapper
.
GroupForResource
(
mapping
.
Resource
)
g
vk
,
err
:=
api
.
RESTMapper
.
KindFor
(
mapping
.
Resource
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -159,7 +159,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -159,7 +159,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
switch
group
{
switch
g
vk
.
G
roup
{
case
""
:
case
""
:
return
client
.
RESTClient
,
nil
return
client
.
RESTClient
,
nil
case
"extensions"
:
case
"extensions"
:
...
@@ -168,7 +168,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -168,7 +168,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
return
nil
,
fmt
.
Errorf
(
"unable to get RESTClient for resource '%s'"
,
mapping
.
Resource
)
return
nil
,
fmt
.
Errorf
(
"unable to get RESTClient for resource '%s'"
,
mapping
.
Resource
)
},
},
Describer
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Describer
,
error
)
{
Describer
:
func
(
mapping
*
meta
.
RESTMapping
)
(
kubectl
.
Describer
,
error
)
{
g
roup
,
err
:=
api
.
RESTMapper
.
GroupForResource
(
mapping
.
Resource
)
g
vk
,
err
:=
api
.
RESTMapper
.
KindFor
(
mapping
.
Resource
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -176,7 +176,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
...
@@ -176,7 +176,7 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
describer
,
ok
:=
kubectl
.
DescriberFor
(
group
,
mapping
.
GroupVersionKind
.
Kind
,
client
);
ok
{
if
describer
,
ok
:=
kubectl
.
DescriberFor
(
g
vk
.
G
roup
,
mapping
.
GroupVersionKind
.
Kind
,
client
);
ok
{
return
describer
,
nil
return
describer
,
nil
}
}
return
nil
,
fmt
.
Errorf
(
"no description has been implemented for %q"
,
mapping
.
Kind
)
return
nil
,
fmt
.
Errorf
(
"no description has been implemented for %q"
,
mapping
.
Kind
)
...
@@ -497,11 +497,11 @@ func (c *clientSwaggerSchema) ValidateBytes(data []byte) error {
...
@@ -497,11 +497,11 @@ func (c *clientSwaggerSchema) ValidateBytes(data []byte) error {
return
fmt
.
Errorf
(
"API version %q isn't supported, only supports API versions %q"
,
version
,
registered
.
RegisteredGroupVersions
)
return
fmt
.
Errorf
(
"API version %q isn't supported, only supports API versions %q"
,
version
,
registered
.
RegisteredGroupVersions
)
}
}
resource
,
_
:=
meta
.
KindToResource
(
kind
,
false
)
resource
,
_
:=
meta
.
KindToResource
(
kind
,
false
)
g
roup
,
err
:=
c
.
mapper
.
GroupForResource
(
resource
)
g
vk
,
err
:=
c
.
mapper
.
KindFor
(
resource
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"could not find api group for %s: %v"
,
kind
,
err
)
return
fmt
.
Errorf
(
"could not find api group for %s: %v"
,
kind
,
err
)
}
}
if
group
==
"extensions"
{
if
g
vk
.
G
roup
==
"extensions"
{
if
c
.
c
.
ExtensionsClient
==
nil
{
if
c
.
c
.
ExtensionsClient
==
nil
{
return
errors
.
New
(
"unable to validate: no experimental client"
)
return
errors
.
New
(
"unable to validate: no experimental client"
)
}
}
...
...
pkg/kubectl/kubectl.go
View file @
5c4fb5bc
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/unversioned"
)
)
const
kubectlAnnotationPrefix
=
"kubectl.kubernetes.io/"
const
kubectlAnnotationPrefix
=
"kubectl.kubernetes.io/"
...
@@ -65,12 +66,13 @@ type ShortcutExpander struct {
...
@@ -65,12 +66,13 @@ type ShortcutExpander struct {
meta
.
RESTMapper
meta
.
RESTMapper
}
}
// VersionAndKindForResource implements meta.RESTMapper. It expands the resource first, then invokes the wrapped
var
_
meta
.
RESTMapper
=
&
ShortcutExpander
{}
// KindFor implements meta.RESTMapper. It expands the resource first, then invokes the wrapped
// mapper.
// mapper.
func
(
e
ShortcutExpander
)
VersionAndKindForResource
(
resource
string
)
(
defaultVersion
,
kind
string
,
err
error
)
{
func
(
e
ShortcutExpander
)
KindFor
(
resource
string
)
(
unversioned
.
GroupVersionKind
,
error
)
{
resource
=
expandResourceShortcut
(
resource
)
resource
=
expandResourceShortcut
(
resource
)
defaultVersion
,
kind
,
err
=
e
.
RESTMapper
.
VersionAndKindForResource
(
resource
)
return
e
.
RESTMapper
.
KindFor
(
resource
)
return
defaultVersion
,
kind
,
err
}
}
// ResourceIsValid takes a string (kind) and checks if it's a valid resource.
// ResourceIsValid takes a string (kind) and checks if it's a valid resource.
...
...
pkg/kubectl/resource/builder.go
View file @
5c4fb5bc
...
@@ -426,11 +426,11 @@ func (b *Builder) resourceMappings() ([]*meta.RESTMapping, error) {
...
@@ -426,11 +426,11 @@ func (b *Builder) resourceMappings() ([]*meta.RESTMapping, error) {
}
}
mappings
:=
[]
*
meta
.
RESTMapping
{}
mappings
:=
[]
*
meta
.
RESTMapping
{}
for
_
,
r
:=
range
b
.
resources
{
for
_
,
r
:=
range
b
.
resources
{
version
,
kind
,
err
:=
b
.
mapper
.
VersionAndKindForResource
(
r
)
gvk
,
err
:=
b
.
mapper
.
KindFor
(
r
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
mapping
,
err
:=
b
.
mapper
.
RESTMapping
(
kind
,
version
)
mapping
,
err
:=
b
.
mapper
.
RESTMapping
(
gvk
.
Kind
,
gvk
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -446,11 +446,11 @@ func (b *Builder) resourceTupleMappings() (map[string]*meta.RESTMapping, error)
...
@@ -446,11 +446,11 @@ func (b *Builder) resourceTupleMappings() (map[string]*meta.RESTMapping, error)
if
_
,
ok
:=
mappings
[
r
.
Resource
];
ok
{
if
_
,
ok
:=
mappings
[
r
.
Resource
];
ok
{
continue
continue
}
}
version
,
kind
,
err
:=
b
.
mapper
.
VersionAndKindForResource
(
r
.
Resource
)
gvk
,
err
:=
b
.
mapper
.
KindFor
(
r
.
Resource
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
mapping
,
err
:=
b
.
mapper
.
RESTMapping
(
kind
,
version
)
mapping
,
err
:=
b
.
mapper
.
RESTMapping
(
gvk
.
Kind
,
gvk
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/registry/thirdpartyresourcedata/codec.go
View file @
5c4fb5bc
...
@@ -39,15 +39,17 @@ type thirdPartyResourceDataMapper struct {
...
@@ -39,15 +39,17 @@ type thirdPartyResourceDataMapper struct {
group
string
group
string
}
}
var
_
meta
.
RESTMapper
=
&
thirdPartyResourceDataMapper
{}
func
(
t
*
thirdPartyResourceDataMapper
)
isThirdPartyResource
(
resource
string
)
bool
{
func
(
t
*
thirdPartyResourceDataMapper
)
isThirdPartyResource
(
resource
string
)
bool
{
return
resource
==
strings
.
ToLower
(
t
.
kind
)
+
"s"
return
resource
==
strings
.
ToLower
(
t
.
kind
)
+
"s"
}
}
func
(
t
*
thirdPartyResourceDataMapper
)
GroupForResource
(
resource
string
)
(
string
,
error
)
{
func
(
t
*
thirdPartyResourceDataMapper
)
KindFor
(
resource
string
)
(
unversioned
.
GroupVersionKind
,
error
)
{
if
t
.
isThirdPartyResource
(
resource
)
{
if
t
.
isThirdPartyResource
(
resource
)
{
return
t
.
group
,
nil
return
unversioned
.
GroupVersionKind
{
Group
:
t
.
group
,
Version
:
t
.
version
,
Kind
:
t
.
kind
}
,
nil
}
}
return
t
.
mapper
.
GroupForResource
(
resource
)
return
t
.
mapper
.
KindFor
(
resource
)
}
}
func
(
t
*
thirdPartyResourceDataMapper
)
RESTMapping
(
kind
string
,
groupVersions
...
string
)
(
*
meta
.
RESTMapping
,
error
)
{
func
(
t
*
thirdPartyResourceDataMapper
)
RESTMapping
(
kind
string
,
groupVersions
...
string
)
(
*
meta
.
RESTMapping
,
error
)
{
...
@@ -76,13 +78,6 @@ func (t *thirdPartyResourceDataMapper) ResourceSingularizer(resource string) (si
...
@@ -76,13 +78,6 @@ func (t *thirdPartyResourceDataMapper) ResourceSingularizer(resource string) (si
return
t
.
mapper
.
ResourceSingularizer
(
resource
)
return
t
.
mapper
.
ResourceSingularizer
(
resource
)
}
}
func
(
t
*
thirdPartyResourceDataMapper
)
VersionAndKindForResource
(
resource
string
)
(
defaultVersion
,
kind
string
,
err
error
)
{
if
t
.
isThirdPartyResource
(
resource
)
{
return
t
.
version
,
t
.
kind
,
nil
}
return
t
.
mapper
.
VersionAndKindForResource
(
resource
)
}
// ResourceIsValid takes a string (kind) and checks if it's a valid resource
// ResourceIsValid takes a string (kind) and checks if it's a valid resource
func
(
t
*
thirdPartyResourceDataMapper
)
ResourceIsValid
(
resource
string
)
bool
{
func
(
t
*
thirdPartyResourceDataMapper
)
ResourceIsValid
(
resource
string
)
bool
{
return
t
.
isThirdPartyResource
(
resource
)
||
t
.
mapper
.
ResourceIsValid
(
resource
)
return
t
.
isThirdPartyResource
(
resource
)
||
t
.
mapper
.
ResourceIsValid
(
resource
)
...
...
plugin/pkg/admission/namespace/autoprovision/admission.go
View file @
5c4fb5bc
...
@@ -48,11 +48,11 @@ type provision struct {
...
@@ -48,11 +48,11 @@ type provision struct {
}
}
func
(
p
*
provision
)
Admit
(
a
admission
.
Attributes
)
(
err
error
)
{
func
(
p
*
provision
)
Admit
(
a
admission
.
Attributes
)
(
err
error
)
{
defaultVersion
,
kind
,
err
:=
api
.
RESTMapper
.
VersionAndKindForResource
(
a
.
GetResource
())
gvk
,
err
:=
api
.
RESTMapper
.
KindFor
(
a
.
GetResource
())
if
err
!=
nil
{
if
err
!=
nil
{
return
admission
.
NewForbidden
(
a
,
err
)
return
admission
.
NewForbidden
(
a
,
err
)
}
}
mapping
,
err
:=
api
.
RESTMapper
.
RESTMapping
(
kind
,
defaultVersion
)
mapping
,
err
:=
api
.
RESTMapper
.
RESTMapping
(
gvk
.
Kind
,
gvk
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
admission
.
NewForbidden
(
a
,
err
)
return
admission
.
NewForbidden
(
a
,
err
)
}
}
...
...
plugin/pkg/admission/namespace/exists/admission.go
View file @
5c4fb5bc
...
@@ -49,11 +49,11 @@ type exists struct {
...
@@ -49,11 +49,11 @@ type exists struct {
}
}
func
(
e
*
exists
)
Admit
(
a
admission
.
Attributes
)
(
err
error
)
{
func
(
e
*
exists
)
Admit
(
a
admission
.
Attributes
)
(
err
error
)
{
defaultVersion
,
kind
,
err
:=
api
.
RESTMapper
.
VersionAndKindForResource
(
a
.
GetResource
())
gvk
,
err
:=
api
.
RESTMapper
.
KindFor
(
a
.
GetResource
())
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
NewInternalError
(
err
)
return
errors
.
NewInternalError
(
err
)
}
}
mapping
,
err
:=
api
.
RESTMapper
.
RESTMapping
(
kind
,
defaultVersion
)
mapping
,
err
:=
api
.
RESTMapper
.
RESTMapping
(
gvk
.
Kind
,
gvk
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
NewInternalError
(
err
)
return
errors
.
NewInternalError
(
err
)
}
}
...
...
plugin/pkg/admission/namespace/lifecycle/admission.go
View file @
5c4fb5bc
...
@@ -57,11 +57,11 @@ func (l *lifecycle) Admit(a admission.Attributes) (err error) {
...
@@ -57,11 +57,11 @@ func (l *lifecycle) Admit(a admission.Attributes) (err error) {
return
errors
.
NewForbidden
(
a
.
GetKind
(),
a
.
GetName
(),
fmt
.
Errorf
(
"this namespace may not be deleted"
))
return
errors
.
NewForbidden
(
a
.
GetKind
(),
a
.
GetName
(),
fmt
.
Errorf
(
"this namespace may not be deleted"
))
}
}
defaultVersion
,
kind
,
err
:=
api
.
RESTMapper
.
VersionAndKindForResource
(
a
.
GetResource
())
gvk
,
err
:=
api
.
RESTMapper
.
KindFor
(
a
.
GetResource
())
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
NewInternalError
(
err
)
return
errors
.
NewInternalError
(
err
)
}
}
mapping
,
err
:=
api
.
RESTMapper
.
RESTMapping
(
kind
,
defaultVersion
)
mapping
,
err
:=
api
.
RESTMapper
.
RESTMapping
(
gvk
.
Kind
,
gvk
.
GroupVersion
()
.
String
()
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
NewInternalError
(
err
)
return
errors
.
NewInternalError
(
err
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment