|
| 1 | += Make a Commodore component multi-tenant aware |
| 2 | + |
| 3 | +Project Syn supports xref:explanations/argocd-multitenancy.adoc[multi-tenancy in the Project Syn ArgoCD instance]. |
| 4 | + |
| 5 | +Currently components need to be marked as multi-tenant aware explicitly. |
| 6 | +This how-to provides the bare minimum configuration that's necessary to make an existing component multi-tenant aware. |
| 7 | + |
| 8 | +[NOTE] |
| 9 | +==== |
| 10 | +The default https://github.com/projectsyn/commodore-component-template[Commodore component template] is updated to generate multi-tenant aware components by default. |
| 11 | +
|
| 12 | +Components which receive template updates should already be updated to be multi-tenant aware. |
| 13 | +==== |
| 14 | + |
| 15 | +. Adjust the component's ArgoCD application manifest generation (usually in `component/app.jsonnet`) |
| 16 | ++ |
| 17 | +.`component/app.jsonnet` |
| 18 | +[source,jsonnet] |
| 19 | +---- |
| 20 | +local kap = import 'lib/kapitan.libjsonnet'; |
| 21 | +local kube = import 'lib/kube.libjsonnet'; |
| 22 | +local inv = kap.inventory(); |
| 23 | +local params = inv.parameters.<component>; <1> |
| 24 | +local argocd = import 'lib/argocd.libjsonnet'; |
| 25 | + |
| 26 | +local app = argocd.App(<component>, params.namespace, secrets=true); <1> |
| 27 | + |
| 28 | +local appPath = |
| 29 | + local project = std.get(app, 'spec', { project: 'syn' }).project; <2> |
| 30 | + if project == 'syn' then 'apps' else 'apps-%s' % project; |
| 31 | + |
| 32 | +{ |
| 33 | + ['%s/<component>' % appPath]: app, <1> |
| 34 | +} |
| 35 | +---- |
| 36 | +<1> Replace `<component> with the component's name. |
| 37 | +<2> We use `std.get()` here because `commodore component compile` generates an empty application manifest by default. |
| 38 | + |
| 39 | +. Adjust the component's Kapitan compile step for the application manifests (in `class/<component-name>.yml`) |
| 40 | ++ |
| 41 | +.`class/<component-name>.yml` |
| 42 | +[source,yaml] |
| 43 | +---- |
| 44 | +parameters: |
| 45 | + kapitan: |
| 46 | + compile: |
| 47 | + - input_paths: |
| 48 | + - ${_instance}/component/app.jsonnet |
| 49 | + input_type: jsonnet |
| 50 | + output_path: apps/ |
| 51 | + output_path: . |
| 52 | +---- |
| 53 | + |
| 54 | +. Mark the component as multi-tenant aware |
| 55 | ++ |
| 56 | +[source,yaml] |
| 57 | +---- |
| 58 | +parameters: |
| 59 | + <component_name>: <1> |
| 60 | + =_metadata: <2> |
| 61 | + multi_tenant: true |
| 62 | +---- |
| 63 | +<1> Replace `component_name` with the component's parameter key. |
| 64 | +<2> We recommend making the component's metadata constant if it isn't already. |
0 commit comments