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
267ef26b
Commit
267ef26b
authored
Mar 26, 2015
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not block admission if namespace already exists
parent
3b0db996
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
2 deletions
+28
-2
fake_namespaces.go
pkg/client/fake_namespaces.go
+1
-1
admission.go
plugin/pkg/admission/namespace/autoprovision/admission.go
+2
-1
admission_test.go
...n/pkg/admission/namespace/autoprovision/admission_test.go
+25
-0
No files found.
pkg/client/fake_namespaces.go
View file @
267ef26b
...
@@ -46,7 +46,7 @@ func (c *FakeNamespaces) Delete(name string) error {
...
@@ -46,7 +46,7 @@ func (c *FakeNamespaces) Delete(name string) error {
func
(
c
*
FakeNamespaces
)
Create
(
namespace
*
api
.
Namespace
)
(
*
api
.
Namespace
,
error
)
{
func
(
c
*
FakeNamespaces
)
Create
(
namespace
*
api
.
Namespace
)
(
*
api
.
Namespace
,
error
)
{
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"create-namespace"
})
c
.
Fake
.
Actions
=
append
(
c
.
Fake
.
Actions
,
FakeAction
{
Action
:
"create-namespace"
})
return
&
api
.
Namespace
{},
nil
return
&
api
.
Namespace
{},
c
.
Fake
.
Err
}
}
func
(
c
*
FakeNamespaces
)
Update
(
namespace
*
api
.
Namespace
)
(
*
api
.
Namespace
,
error
)
{
func
(
c
*
FakeNamespaces
)
Update
(
namespace
*
api
.
Namespace
)
(
*
api
.
Namespace
,
error
)
{
...
...
plugin/pkg/admission/namespace/autoprovision/admission.go
View file @
267ef26b
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/meta"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
...
@@ -76,7 +77,7 @@ func (p *provision) Admit(a admission.Attributes) (err error) {
...
@@ -76,7 +77,7 @@ func (p *provision) Admit(a admission.Attributes) (err error) {
return
nil
return
nil
}
}
_
,
err
=
p
.
client
.
Namespaces
()
.
Create
(
namespace
)
_
,
err
=
p
.
client
.
Namespaces
()
.
Create
(
namespace
)
if
err
!=
nil
{
if
err
!=
nil
&&
!
errors
.
IsAlreadyExists
(
err
)
{
return
err
return
err
}
}
return
nil
return
nil
...
...
plugin/pkg/admission/namespace/autoprovision/admission_test.go
View file @
267ef26b
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
"github.com/GoogleCloudPlatform/kubernetes/pkg/admission"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
)
)
...
@@ -103,3 +104,27 @@ func TestIgnoreAdmission(t *testing.T) {
...
@@ -103,3 +104,27 @@ func TestIgnoreAdmission(t *testing.T) {
t
.
Errorf
(
"No client request should have been made"
)
t
.
Errorf
(
"No client request should have been made"
)
}
}
}
}
// TestAdmissionNamespaceExistsUnknownToHandler
func
TestAdmissionNamespaceExistsUnknownToHandler
(
t
*
testing
.
T
)
{
namespace
:=
"test"
mockClient
:=
&
client
.
Fake
{
Err
:
errors
.
NewAlreadyExists
(
"namespaces"
,
namespace
),
}
store
:=
cache
.
NewStore
(
cache
.
MetaNamespaceKeyFunc
)
handler
:=
&
provision
{
client
:
mockClient
,
store
:
store
,
}
pod
:=
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"123"
,
Namespace
:
namespace
},
Spec
:
api
.
PodSpec
{
Volumes
:
[]
api
.
Volume
{{
Name
:
"vol"
}},
Containers
:
[]
api
.
Container
{{
Name
:
"ctr"
,
Image
:
"image"
}},
},
}
err
:=
handler
.
Admit
(
admission
.
NewAttributesRecord
(
&
pod
,
namespace
,
"pods"
,
"CREATE"
))
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error returned from admission handler"
)
}
}
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