Skip to content

Commit f351bc4

Browse files
makrelasmakrelasNikolas Philips
authored
Support new schema (#192)
Add bootstrap chart support Co-authored-by: makrelas <[email protected]> Co-authored-by: Nikolas Philips <[email protected]>
1 parent f6e81fd commit f351bc4

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ init:
77
pre-commit install
88

99
format:
10-
black $(BLACK_ARGS)
10+
python3 -m black $(BLACK_ARGS)
1111

1212
format-check:
13-
black $(BLACK_ARGS) --check
13+
python3 -m black $(BLACK_ARGS) --check
1414

1515
lint:
16-
pylint gitopscli
16+
python3 -m pylint gitopscli
1717

1818
mypy:
1919
python3 -m mypy --install-types --non-interactive .

docs/commands/sync-apps.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ bootstrap:
3535
- name: team-a # <- every entry links to a YAML file in the `apps/` directory
3636
- name: team-b
3737
```
38+
Alternative, when using a Chart as dependency with an alias 'config':
39+
```yaml
40+
config:
41+
bootstrap:
42+
- name: team-a # <- every entry links to a YAML file in the `apps/` directory
43+
- name: team-b
44+
```
3845
3946
**apps/team-a.yaml**
4047
```yaml

gitopscli/commands/sync_apps.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ def __get_bootstrap_entries(root_config_git_repo: GitRepo) -> Any:
129129
bootstrap_yaml = yaml_file_load(bootstrap_values_file)
130130
except FileNotFoundError as ex:
131131
raise GitOpsException("File 'bootstrap/values.yaml' not found in root repository.") from ex
132-
if "bootstrap" not in bootstrap_yaml:
133-
raise GitOpsException("Cannot find key 'bootstrap' in 'bootstrap/values.yaml'")
134-
return bootstrap_yaml["bootstrap"]
132+
if "bootstrap" in bootstrap_yaml:
133+
return bootstrap_yaml["bootstrap"]
134+
if "config" in bootstrap_yaml and "bootstrap" in bootstrap_yaml["config"]:
135+
return bootstrap_yaml["config"]["bootstrap"]
136+
raise GitOpsException("Cannot find key 'bootstrap' or 'config.bootstrap' in 'bootstrap/values.yaml'")
135137

136138

137139
def __get_repo_apps(team_config_git_repo: GitRepo) -> Set[str]:

tests/commands/test_sync_apps.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,27 @@ def test_sync_apps_already_up_to_date(self):
169169
call.logging.info("Root repository already up-to-date. I'm done here."),
170170
]
171171

172+
def test_sync_apps_bootstrap_chart(self):
173+
self.yaml_file_load_mock.side_effect = lambda file_path: {
174+
"/tmp/root-config-repo/bootstrap/values.yaml": {
175+
"config": {
176+
"bootstrap": [{"name": "team-non-prod"}, {"name": "other-team-non-prod"}],
177+
}
178+
},
179+
"/tmp/root-config-repo/apps/team-non-prod.yaml": {
180+
"repository": "https://team.config.repo.git",
181+
"applications": {"my-app": None}, # my-app already exists
182+
},
183+
"/tmp/root-config-repo/apps/other-team-non-prod.yaml": {
184+
"repository": "https://other-team.config.repo.git",
185+
"applications": {},
186+
},
187+
}[file_path]
188+
try:
189+
SyncAppsCommand(ARGS).execute()
190+
except GitOpsException:
191+
self.fail("'config.bootstrap' should be read correctly'")
192+
172193
def test_sync_apps_bootstrap_yaml_not_found(self):
173194
self.yaml_file_load_mock.side_effect = FileNotFoundError()
174195

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

204225
def test_sync_apps_invalid_bootstrap_entry_in_bootstrap_yaml(self):
205226
self.yaml_file_load_mock.side_effect = lambda file_path: {

0 commit comments

Comments
 (0)