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
62272a22
Commit
62272a22
authored
Jul 26, 2017
by
deads2k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make admission tolerate object without objectmeta for errors
parent
001ded68
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
2 deletions
+72
-2
BUILD
staging/src/k8s.io/apiserver/pkg/admission/BUILD
+2
-0
errors.go
staging/src/k8s.io/apiserver/pkg/admission/errors.go
+8
-2
errors_test.go
staging/src/k8s.io/apiserver/pkg/admission/errors_test.go
+62
-0
No files found.
staging/src/k8s.io/apiserver/pkg/admission/BUILD
View file @
62272a22
...
@@ -13,10 +13,12 @@ go_test(
...
@@ -13,10 +13,12 @@ go_test(
srcs = [
srcs = [
"chain_test.go",
"chain_test.go",
"config_test.go",
"config_test.go",
"errors_test.go",
],
],
library = ":go_default_library",
library = ":go_default_library",
tags = ["automanaged"],
tags = ["automanaged"],
deps = [
deps = [
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apiserver/pkg/apis/apiserver:go_default_library",
"//vendor/k8s.io/apiserver/pkg/apis/apiserver:go_default_library",
],
],
...
...
staging/src/k8s.io/apiserver/pkg/admission/errors.go
View file @
62272a22
...
@@ -24,13 +24,19 @@ import (
...
@@ -24,13 +24,19 @@ import (
)
)
func
extractResourceName
(
a
Attributes
)
(
name
string
,
resource
schema
.
GroupResource
,
err
error
)
{
func
extractResourceName
(
a
Attributes
)
(
name
string
,
resource
schema
.
GroupResource
,
err
error
)
{
name
=
"Unknown"
resource
=
a
.
GetResource
()
.
GroupResource
()
resource
=
a
.
GetResource
()
.
GroupResource
()
if
len
(
a
.
GetName
())
>
0
{
return
a
.
GetName
(),
resource
,
nil
}
name
=
"Unknown"
obj
:=
a
.
GetObject
()
obj
:=
a
.
GetObject
()
if
obj
!=
nil
{
if
obj
!=
nil
{
accessor
,
err
:=
meta
.
Accessor
(
obj
)
accessor
,
err
:=
meta
.
Accessor
(
obj
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
schema
.
GroupResource
{},
err
// not all object have ObjectMeta. If we don't, return a name with a slash (always illegal)
return
"Unknown/errorGettingName"
,
resource
,
nil
}
}
// this is necessary because name object name generation has not occurred yet
// this is necessary because name object name generation has not occurred yet
...
...
staging/src/k8s.io/apiserver/pkg/admission/errors_test.go
0 → 100644
View file @
62272a22
/*
Copyright 2015 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
admission
import
(
"errors"
"testing"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// makes sure that we never get:
// Internal error occurred: [some error, object does not implement the Object interfaces]
func
TestNewForbidden
(
t
*
testing
.
T
)
{
attributes
:=
NewAttributesRecord
(
&
fakeObj
{},
nil
,
schema
.
GroupVersionKind
{
Group
:
"foo"
,
Version
:
"bar"
,
Kind
:
"Baz"
},
""
,
""
,
schema
.
GroupVersionResource
{
Group
:
"foo"
,
Version
:
"bar"
,
Resource
:
"baz"
},
""
,
Create
,
nil
)
err
:=
errors
.
New
(
"some error"
)
expectedErr
:=
`baz.foo "Unknown/errorGettingName" is forbidden: some error`
actualErr
:=
NewForbidden
(
attributes
,
err
)
if
actualErr
.
Error
()
!=
expectedErr
{
t
.
Errorf
(
"expected %v, got %v"
,
expectedErr
,
actualErr
)
}
}
type
fakeObj
struct
{}
type
fakeObjKind
struct
{}
func
(
f
*
fakeObj
)
GetObjectKind
()
schema
.
ObjectKind
{
return
&
fakeObjKind
{}
}
func
(
f
*
fakeObj
)
DeepCopyObject
()
runtime
.
Object
{
return
f
}
func
(
f
*
fakeObjKind
)
SetGroupVersionKind
(
kind
schema
.
GroupVersionKind
)
{}
func
(
f
*
fakeObjKind
)
GroupVersionKind
()
schema
.
GroupVersionKind
{
return
schema
.
GroupVersionKind
{
Group
:
"foo"
,
Version
:
"bar"
,
Kind
:
"Baz"
}
}
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