|
1 | 1 | // main template for namespaces
|
| 2 | +local com = import 'lib/commodore.libjsonnet'; |
2 | 3 | local kap = import 'lib/kapitan.libjsonnet';
|
3 | 4 | local kube = import 'lib/kube.libjsonnet';
|
4 | 5 | local inv = kap.inventory();
|
| 6 | + |
5 | 7 | // The hiera parameters for the component
|
6 | 8 | 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 | +}; |
7 | 33 |
|
8 | 34 | // Define outputs below
|
9 | 35 | {
|
| 36 | + [name]: namespace(name) |
| 37 | + for name in std.objectFields(params.namespaces) |
10 | 38 | }
|
0 commit comments