Skip to content

Commit

Permalink
misc: adjust log levels
Browse files Browse the repository at this point in the history
misc: log app/env on kustomize error
  • Loading branch information
Karandash8 committed Jul 9, 2024
1 parent 894f498 commit afb58f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions make_argocd_fly/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def generate_resources(self) -> None:
resources.append(content)

self.resources = '\n---\n'.join(resources)
log.info('Generated resources for application {} in environment {}'.format(self.app_name, self.env_name))
log.debug('Generated resources for application {} in environment {}'.format(self.app_name, self.env_name))


class Application(AbstractApplication):
Expand All @@ -123,7 +123,7 @@ async def generate_resources(self) -> None:
resources.append(content)

self.resources = '\n---\n'.join(resources)
log.info('Generated resources for application {} in environment {}'.format(self.app_name, self.env_name))
log.debug('Generated resources for application {} in environment {}'.format(self.app_name, self.env_name))


class KustomizeApplication(AbstractApplication):
Expand All @@ -147,7 +147,7 @@ async def _run_kustomize(self, dir_path: str, retries: int = 3) -> str:
continue
break
else:
raise Exception('Kustomize run failed')
raise Exception('Kustomize execution failed for application {} in environment {}'.format(self.app_name, self.env_name))

return stdout.decode("utf-8")

Expand Down Expand Up @@ -188,19 +188,19 @@ async def generate_resources(self) -> None:
yml_child = tmp_source_viewer.get_element(os.path.join(self.env_name, 'kustomization.yml'))
if yml_child:
self.resources = await self._run_kustomize(os.path.join(tmp_source_viewer.root_element_abs_path, os.path.dirname(yml_child.element_rel_path)))
log.info('Generated resources for application {} in environment {}'.format(self.app_name, self.env_name))
log.debug('Generated resources for application {} in environment {}'.format(self.app_name, self.env_name))
return

yml_child = tmp_source_viewer.get_element(os.path.join('base', 'kustomization.yml'))
if yml_child:
self.resources = await self._run_kustomize(os.path.join(tmp_source_viewer.root_element_abs_path, os.path.dirname(yml_child.element_rel_path)))
log.info('Generated resources for application {} in environment {}'.format(self.app_name, self.env_name))
log.debug('Generated resources for application {} in environment {}'.format(self.app_name, self.env_name))
return

yml_child = tmp_source_viewer.get_element('kustomization.yml')
if yml_child:
self.resources = await self._run_kustomize(os.path.join(tmp_source_viewer.root_element_abs_path, os.path.dirname(yml_child.element_rel_path)))
log.info('Generated resources for application {} in environment {}'.format(self.app_name, self.env_name))
log.debug('Generated resources for application {} in environment {}'.format(self.app_name, self.env_name))
return

log.error('Missing kustomization.yml in the application directory. Skipping application')
Expand Down
10 changes: 5 additions & 5 deletions make_argocd_fly/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def read_config(root_dir: str, config_file: str, source_dir: str, output_dir: st

config.init_config(root_dir, config_content, source_dir, output_dir, tmp_dir)

log.debug('Root directory: {}'.format(root_dir))
log.debug('Config file: {}'.format(get_abs_path(root_dir, config_file)))
log.debug('Source directory: {}'.format(config.get_source_dir()))
log.debug('Output directory: {}'.format(config.get_output_dir()))
log.debug('Temporary directory: {}'.format(config.get_tmp_dir()))
log.info('Root directory: {}'.format(root_dir))
log.info('Config file: {}'.format(get_abs_path(root_dir, config_file)))
log.info('Source directory: {}'.format(config.get_source_dir()))
log.info('Output directory: {}'.format(config.get_output_dir()))
log.info('Temporary directory: {}'.format(config.get_tmp_dir()))

return config

Expand Down
14 changes: 7 additions & 7 deletions make_argocd_fly/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def init_logging(loglevel: str) -> None:
def create_applications(render_apps, render_envs):
config = get_config()

log.debug('Reading source directory')
log.info('Reading source directory')
source_viewer = ResourceViewer(config.get_source_dir())
source_viewer.build()

apps_to_render = render_apps.split(',') if render_apps is not None else []
envs_to_render = render_envs.split(',') if render_envs is not None else []
apps = []

log.debug('Creating applications')
log.info('Creating applications')
for env_name, env_data in config.get_envs().items():
if envs_to_render and env_name not in envs_to_render:
continue
Expand All @@ -62,10 +62,10 @@ async def generate(render_envs, render_apps) -> None:
apps = create_applications(render_apps, render_envs)

try:
log.debug('Generating temporary files')
log.info('Generating temporary files')
await asyncio.gather(*[asyncio.create_task(app.prepare()) for app in apps])

log.debug('Rendering resources')
log.info('Rendering resources')
await asyncio.gather(*[asyncio.create_task(app.generate_resources()) for app in apps])
except Exception:
raise
Expand All @@ -77,15 +77,15 @@ async def generate(render_envs, render_apps) -> None:
output_writer.store_resource(file_path, resource_yml)

if apps:
log.debug('The following applications have been updated:')
log.info('The following applications have been updated:')
if os.path.exists(config.get_output_dir()):
for app in apps:
app_dir = os.path.join(config.get_output_dir(), app.get_app_rel_path())
log.debug('Environment: {}, Application: {}, Path: {}'.format(app.env_name, app.app_name, app_dir))
log.info('Environment: {}, Application: {}, Path: {}'.format(app.env_name, app.app_name, app_dir))
if os.path.exists(app_dir):
shutil.rmtree(app_dir)

log.debug('Writing resources files')
log.info('Writing resources files')
os.makedirs(config.get_output_dir(), exist_ok=True)
await output_writer.write_resources()

Expand Down

0 comments on commit afb58f3

Please sign in to comment.