Skip to content

Commit

Permalink
Merge pull request #91 from projectsyn/organize-classes
Browse files Browse the repository at this point in the history
Organize global classes in folders
  • Loading branch information
Simon Rüegg authored May 14, 2020
2 parents d5e31d0 + 240db95 commit 6cbc43b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 4 additions & 2 deletions commodore/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ def _full_target(cluster, components, catalog):
customer = cluster['tenant']
component_defaults = [f"defaults.{cn}" for cn in components if
(P('inventory/classes/defaults') / f"{cn}.yml").is_file()]
global_defaults = ['global.common', f"global.{cluster_distro}", f"global.{cloud_provider}"]
global_defaults = ['global.common',
f"global.distribution.{cluster_distro}",
f"global.cloud.{cloud_provider}"]
if 'region' in cluster_facts:
global_defaults.append(f"global.{cloud_provider}.{cluster_facts['region']}")
global_defaults.append(f"global.cloud.{cloud_provider}.{cluster_facts['region']}")
global_defaults.append(f"{customer}.{cluster_id}")
target = {
'classes': component_defaults + global_defaults,
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/ROOT/pages/writing-a-component.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ The hierarchy is as follows (starting at the lowest precedence):

* Component defaults, included as `defaults.<component-name>` for each component
* Global defaults, `global.common`
* Kubernetes distribution defaults, `global.<kubernetes-distribution>`. The
* Kubernetes distribution defaults, `global.distribution.<kubernetes-distribution>`. The
intention of the hierarchy is that component classes are included in each
distribution class separately to allow bootstrapping of new distributions in
a multi-distribution environment easier
* Cloud provider defaults, `global.<cloud-provider>`
* Cloud provider region defaults, `global.<cloud-provider>.<region>`
* Cloud provider defaults, `global.cloud.<cloud-provider>`
* Cloud provider region defaults, `global.cloud.<cloud-provider>.<region>`
* Cluster configuration, `<customer>.<cluster>`. The cluster configuration is
managed in the customer's configuration repository. The customer repository
can have any structure, the only requirement is that it contains a Kapitan
Expand All @@ -76,7 +76,7 @@ Kapitan classes is that components can be included at any point in the
hierarchy, without having their defaults overwrite defaults defined higher up
in the configuration hierarchy. F.e. without the split, a component included
for a particular cloud provider would overwrite configuration values specified
in `global.common` or `global.<kubernetes-distribution>` for which the
in `global.common` or `global.distribution.<kubernetes-distribution>` for which the
component provides defaults.

== The component templates
Expand Down
10 changes: 5 additions & 5 deletions tests/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_render_target():
facts = cluster_obj['facts']
all_classes = [f"defaults.{cn}" for cn in components] + [
'global.common',
f"global.{facts['distribution']}",
f"global.{facts['cloud']}",
f"global.distribution.{facts['distribution']}",
f"global.cloud.{facts['cloud']}",
f"{cluster_obj['tenant']}.{cluster_obj['id']}"]
assert target != ""
assert len(target['classes']) == len(all_classes), \
Expand All @@ -39,7 +39,7 @@ def test_optional_facts():
cluster_obj['facts']['region'] = 'rma1'
target = cluster._full_target(cluster_obj, components, catalog)
facts = cluster_obj['facts']
assert f"global.{facts['cloud']}.{facts['region']}" in target['classes']
assert f"global.cloud.{facts['cloud']}.{facts['region']}" in target['classes']


def test_missing_facts():
Expand All @@ -60,8 +60,8 @@ def test_reconstruct_api_response(tmp_path):
file.write('''classes:
- defaults.argocd
- global.common
- global.k3d
- global.localdev
- global.distribution.k3d
- global.cloud.localdev
- t-delicate-pine-3938.c-twilight-water-9032
parameters:
cloud:
Expand Down

0 comments on commit 6cbc43b

Please sign in to comment.