Skip to content

Commit

Permalink
Support new schema (#192)
Browse files Browse the repository at this point in the history
Add bootstrap chart support

Co-authored-by: makrelas <[email protected]>
Co-authored-by: Nikolas Philips <[email protected]>
  • Loading branch information
3 people committed Nov 28, 2022
1 parent f6e81fd commit f351bc4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ init:
pre-commit install

format:
black $(BLACK_ARGS)
python3 -m black $(BLACK_ARGS)

format-check:
black $(BLACK_ARGS) --check
python3 -m black $(BLACK_ARGS) --check

lint:
pylint gitopscli
python3 -m pylint gitopscli

mypy:
python3 -m mypy --install-types --non-interactive .
Expand Down
7 changes: 7 additions & 0 deletions docs/commands/sync-apps.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ bootstrap:
- name: team-a # <- every entry links to a YAML file in the `apps/` directory
- name: team-b
```
Alternative, when using a Chart as dependency with an alias 'config':
```yaml
config:
bootstrap:
- name: team-a # <- every entry links to a YAML file in the `apps/` directory
- name: team-b
```
**apps/team-a.yaml**
```yaml
Expand Down
8 changes: 5 additions & 3 deletions gitopscli/commands/sync_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ def __get_bootstrap_entries(root_config_git_repo: GitRepo) -> Any:
bootstrap_yaml = yaml_file_load(bootstrap_values_file)
except FileNotFoundError as ex:
raise GitOpsException("File 'bootstrap/values.yaml' not found in root repository.") from ex
if "bootstrap" not in bootstrap_yaml:
raise GitOpsException("Cannot find key 'bootstrap' in 'bootstrap/values.yaml'")
return bootstrap_yaml["bootstrap"]
if "bootstrap" in bootstrap_yaml:
return bootstrap_yaml["bootstrap"]
if "config" in bootstrap_yaml and "bootstrap" in bootstrap_yaml["config"]:
return bootstrap_yaml["config"]["bootstrap"]
raise GitOpsException("Cannot find key 'bootstrap' or 'config.bootstrap' in 'bootstrap/values.yaml'")


def __get_repo_apps(team_config_git_repo: GitRepo) -> Set[str]:
Expand Down
23 changes: 22 additions & 1 deletion tests/commands/test_sync_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ def test_sync_apps_already_up_to_date(self):
call.logging.info("Root repository already up-to-date. I'm done here."),
]

def test_sync_apps_bootstrap_chart(self):
self.yaml_file_load_mock.side_effect = lambda file_path: {
"/tmp/root-config-repo/bootstrap/values.yaml": {
"config": {
"bootstrap": [{"name": "team-non-prod"}, {"name": "other-team-non-prod"}],
}
},
"/tmp/root-config-repo/apps/team-non-prod.yaml": {
"repository": "https://team.config.repo.git",
"applications": {"my-app": None}, # my-app already exists
},
"/tmp/root-config-repo/apps/other-team-non-prod.yaml": {
"repository": "https://other-team.config.repo.git",
"applications": {},
},
}[file_path]
try:
SyncAppsCommand(ARGS).execute()
except GitOpsException:
self.fail("'config.bootstrap' should be read correctly'")

def test_sync_apps_bootstrap_yaml_not_found(self):
self.yaml_file_load_mock.side_effect = FileNotFoundError()

Expand Down Expand Up @@ -199,7 +220,7 @@ def test_sync_apps_missing_bootstrap_element_in_bootstrap_yaml(self):
SyncAppsCommand(ARGS).execute()
self.fail()
except GitOpsException as ex:
self.assertEqual("Cannot find key 'bootstrap' in 'bootstrap/values.yaml'", str(ex))
self.assertEqual("Cannot find key 'bootstrap' or 'config.bootstrap' in 'bootstrap/values.yaml'", str(ex))

def test_sync_apps_invalid_bootstrap_entry_in_bootstrap_yaml(self):
self.yaml_file_load_mock.side_effect = lambda file_path: {
Expand Down

0 comments on commit f351bc4

Please sign in to comment.