"""YuanRong datasystem CLI command to generate Helm chart."""
import os
import shutil
from pathlib import Path
import yr.datasystem.cli.common.util as util
from yr.datasystem.cli.command import BaseCommand
class Command(BaseCommand):
"""
Generate Helm chart for yuanrong datasystem deployment.
"""
name = 'generate_helm_chart'
description = 'generate Helm chart for yuanrong datasystem deployment'
@staticmethod
def add_arguments(parser):
"""
Add arguments to parser.
Args:
parser (ArgumentParser): Specify parser to which arguments are added.
"""
parser.add_argument(
'-o', '--output_path',
type=str,
metavar='OUTPUT_PATH',
default=os.getcwd(),
help='path to save the generated Helm chart, default path is the current directory. \
Example: dscli generate_helm_chart --output_path /home/user/helmCharts'
)
def run(self, args):
"""
Execute for generate_helm_chart command.
Args:
args (Namespace): Parsed command-line arguments.
"""
output_path = Path(args.output_path) / 'datasystem-helm-chart'
output_path = output_path.resolve()
util.valid_safe_path(output_path)
output_path.mkdir(parents=True, exist_ok=True)
helm_chart_template_path = os.path.join(self._base_dir, 'helm_chart')
try:
shutil.copytree(helm_chart_template_path, output_path, dirs_exist_ok=True)
except shutil.Error as e:
self.logger.error(f"Error copying files: {e}")
return self.FAILURE
except OSError as e:
self.logger.error(f"OS error occurred: {e}")
return self.FAILURE
self.logger.info(f"\nHelm chart generated successfully at: {output_path}")
self.logger.info("You can now use this chart for deployment with Helm.")
return self.SUCCESS