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
84985327
Commit
84985327
authored
Apr 10, 2017
by
Jacek N
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add namespace-{list, create, delete} actions to the kubernetes-master layer
parent
a177c8e8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
0 deletions
+86
-0
actions.yaml
cluster/juju/layers/kubernetes-master/actions.yaml
+20
-0
namespace-create
...er/juju/layers/kubernetes-master/actions/namespace-create
+56
-0
namespace-delete
...er/juju/layers/kubernetes-master/actions/namespace-delete
+2
-0
namespace-list
cluster/juju/layers/kubernetes-master/actions/namespace-list
+2
-0
create-namespace.yaml.j2
...yers/kubernetes-master/templates/create-namespace.yaml.j2
+6
-0
No files found.
cluster/juju/layers/kubernetes-master/actions.yaml
View file @
84985327
...
...
@@ -26,3 +26,23 @@ create-rbd-pv:
required
:
-
name
-
size
namespace-list
:
description
:
List existing k8s namespaces
namespace-create
:
description
:
Create new namespace
params
:
name
:
type
:
string
description
:
Namespace name eg. staging
minLength
:
2
required
:
-
name
namespace-delete
:
description
:
Delete namespace
params
:
name
:
type
:
string
description
:
Namespace name eg. staging
minLength
:
2
required
:
-
name
cluster/juju/layers/kubernetes-master/actions/namespace-create
0 → 100644
View file @
84985327
#!/usr/bin/env python3
from
yaml
import
safe_load
as
load
from
charmhelpers.core.hookenv
import
(
action_get
,
action_set
,
action_fail
,
action_name
)
from
charms.templating.jinja2
import
render
from
subprocess
import
check_output
def
kubectl
(
args
):
cmd
=
[
'kubectl'
]
+
args
return
check_output
(
cmd
)
def
namespace_list
():
y
=
load
(
kubectl
([
'get'
,
'namespaces'
,
'-o'
,
'yaml'
]))
ns
=
[
i
[
'metadata'
][
'name'
]
for
i
in
y
[
'items'
]]
action_set
({
'namespaces'
:
', '
.
join
(
ns
)
+
'.'
})
return
ns
def
namespace_create
():
name
=
action_get
(
'name'
)
if
name
in
namespace_list
():
action_fail
(
'Namespace "{}" already exists.'
.
format
(
name
))
return
render
(
'create-namespace.yaml.j2'
,
'/etc/kubernetes/addons/create-namespace.yaml'
,
context
=
{
'name'
:
name
})
kubectl
([
'create'
,
'-f'
,
'/etc/kubernetes/addons/create-namespace.yaml'
])
action_set
({
'msg'
:
'Namespace "{}" created.'
.
format
(
name
)})
def
namespace_delete
():
name
=
action_get
(
'name'
)
if
name
in
[
'default'
,
'kube-system'
]:
action_fail
(
'Not allowed to delete "{}".'
.
format
(
name
))
return
if
name
not
in
namespace_list
():
action_fail
(
'Namespace "{}" does not exist.'
.
format
(
name
))
return
kubectl
([
'delete'
,
'ns/'
+
name
])
action_set
({
'msg'
:
'Namespace "{}" deleted.'
.
format
(
name
)})
action
=
action_name
()
.
replace
(
'namespace-'
,
''
)
if
action
==
'create'
:
namespace_create
()
elif
action
==
'list'
:
namespace_list
()
elif
action
==
'delete'
:
namespace_delete
()
cluster/juju/layers/kubernetes-master/actions/namespace-delete
0 → 120000
View file @
84985327
namespace-create
\ No newline at end of file
cluster/juju/layers/kubernetes-master/actions/namespace-list
0 → 120000
View file @
84985327
namespace-create
\ No newline at end of file
cluster/juju/layers/kubernetes-master/templates/create-namespace.yaml.j2
0 → 100644
View file @
84985327
apiVersion: v1
kind: Namespace
metadata:
name: {{ name }}
labels:
name: {{ name }}
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