Skip to content

Commit f0a73ef

Browse files
committed
Initial implementation
1 parent ba55b33 commit f0a73ef

File tree

20 files changed

+114
-21
lines changed

20 files changed

+114
-21
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ jobs:
3232
strategy:
3333
matrix:
3434
instance:
35-
- defaults
3635
- team1
3736
- team2
3837
defaults:
@@ -49,7 +48,6 @@ jobs:
4948
strategy:
5049
matrix:
5150
instance:
52-
- defaults
5351
- team1
5452
- team2
5553
defaults:

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ SHELL := bash
66
.SUFFIXES:
77

88
include Makefile.vars.mk
9+
include Makefile.custom.mk
910

1011
.PHONY: help
1112
help: ## Show this help

Makefile.custom.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Configure instance alias for commodore component compile
2+
commodore_args += --alias $(instance)

Makefile.vars.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ KUBENT_ARGS ?= -c=false --helm3=false -e
4949
KUBENT_IMAGE ?= ghcr.io/doitintl/kube-no-trouble:latest
5050
KUBENT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(root_volume) --entrypoint=/app/kubent $(KUBENT_IMAGE)
5151

52-
instance ?= defaults
53-
test_instances = tests/defaults.yml tests/team1.yml tests/team2.yml
52+
instance ?= team1
53+
test_instances = tests/team1.yml tests/team2.yml

class/defaults.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
parameters:
22
namespaces:
33
=_metadata:
4+
multi_instance: true
45
multi_tenant: true
5-
namespace: syn-namespaces
6+
7+
namespaces: {}

class/namespaces.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ parameters:
88
- input_paths:
99
- ${_base_directory}/component/main.jsonnet
1010
input_type: jsonnet
11-
output_path: namespaces/
11+
output_path: ${_instance}/

component/app.jsonnet

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@ local inv = kap.inventory();
33
local params = inv.parameters.namespaces;
44
local argocd = import 'lib/argocd.libjsonnet';
55

6-
local app = argocd.App('namespaces', params.namespace);
6+
local app = argocd.App('namespaces', params.namespace) {
7+
spec+: {
8+
syncPolicy+: {
9+
syncOptions+: [
10+
'ServerSideApply=true',
11+
],
12+
},
13+
},
14+
};
715

816
local appPath =
917
local project = std.get(std.get(app, 'spec', {}), 'project', 'syn');

component/main.jsonnet

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
11
// main template for namespaces
2+
local com = import 'lib/commodore.libjsonnet';
23
local kap = import 'lib/kapitan.libjsonnet';
34
local kube = import 'lib/kube.libjsonnet';
45
local inv = kap.inventory();
6+
57
// The hiera parameters for the component
68
local params = inv.parameters.namespaces;
9+
local instanceName = inv.parameters._instance;
10+
11+
// Prevent creating a namespace that is not instantiated
12+
assert instanceName != 'namespace' : 'component must be instantiated with a name';
13+
14+
local namespace(name) = {
15+
// Prevent creating a namespace that is a reserved Kubernetes namespace
16+
assert !std.startsWith(name, 'kube') : 'namespace name must not start with "kube"',
17+
assert !std.startsWith(name, 'openshift') : 'namespace name must not start with "openshift"',
18+
// Prevent creating a namespace that is a reserved Syn namespace
19+
assert !std.startsWith(name, 'syn') : 'namespace name must not start with "syn"',
20+
21+
apiVersion: 'v1',
22+
kind: 'Namespace',
23+
metadata: {
24+
annotations: {
25+
'argocd.argoproj.io/sync-options': 'Delete=false',
26+
} + com.makeMergeable(std.get(params.namespaces[name], 'annotations', {})),
27+
labels: {
28+
name: name,
29+
} + com.makeMergeable(std.get(params.namespaces[name], 'labels', {})),
30+
name: name,
31+
},
32+
};
733

834
// Define outputs below
935
{
36+
[name]: namespace(name)
37+
for name in std.objectFields(params.namespaces)
1038
}

docs/modules/ROOT/pages/index.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22

33
namespaces is a Commodore component to manage Managed Namespaces.
44

5+
[TIP]
6+
====
7+
Please ensure that you instantiate the component with a name and that you configure ownership of the instance if you are not the cluster owner.
8+
====
9+
510
See the xref:references/parameters.adoc[parameters] reference for further details.

docs/modules/ROOT/pages/references/parameters.adoc

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,38 @@
22

33
The parent key for all of the following parameters is `namespaces`.
44

5-
== `namespace`
5+
== `namespaces`
66

77
[horizontal]
8-
type:: string
9-
default:: `syn-namespaces`
8+
type:: object
9+
default:: {}
1010

11-
The namespace in which to deploy this component.
11+
Contains a list of namespaces to create.
1212

1313

1414
== Example
1515

1616
[source,yaml]
1717
----
18-
namespace: example-namespace
18+
applications:
19+
- namespaces as namespaces-team1 <1>
20+
21+
parameters:
22+
syn:
23+
teams:
24+
team1:
25+
instances:
26+
- namespaces-team1 <2>
27+
28+
namespaces_team1:
29+
namespaces:
30+
plain-namespace: {}
31+
with-annotations:
32+
annotations:
33+
team: team1
34+
with-labels:
35+
labels:
36+
team: team1
1937
----
38+
<1> Make sure you include the component as an instance.
39+
<2> Make sure you configure ownership of the instance if you are not the cluster owner.

0 commit comments

Comments
 (0)