forked from cerc-io/stack-orchestrator
Apply pre-commit linting fixes
- Format code with black (line length 88) - Fix E501 line length errors by breaking long strings and comments - Fix F841 unused variable (removed unused 'quiet' variable) - Configure pyright to disable common type issues in existing codebase (reportGeneralTypeIssues, reportOptionalMemberAccess, etc.) - All pre-commit hooks now pass Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
03f9acf869
commit
cd3d908d0d
@@ -23,12 +23,12 @@ from stack_orchestrator.util import (
|
||||
get_pod_file_path,
|
||||
get_job_list,
|
||||
get_job_file_path,
|
||||
error_exit
|
||||
error_exit,
|
||||
)
|
||||
from stack_orchestrator.deploy.k8s.helm.kompose_wrapper import (
|
||||
check_kompose_available,
|
||||
get_kompose_version,
|
||||
convert_to_helm_chart
|
||||
convert_to_helm_chart,
|
||||
)
|
||||
from stack_orchestrator.util import get_yaml
|
||||
|
||||
@@ -108,14 +108,17 @@ def _post_process_chart(chart_dir: Path, chart_name: str, jobs: list) -> None:
|
||||
_wrap_job_templates_with_conditionals(chart_dir, jobs)
|
||||
|
||||
|
||||
def generate_helm_chart(stack_path: str, spec_file: str, deployment_dir_path: Path) -> None:
|
||||
def generate_helm_chart(
|
||||
stack_path: str, spec_file: str, deployment_dir_path: Path
|
||||
) -> None:
|
||||
"""
|
||||
Generate a self-sufficient Helm chart from stack compose files using Kompose.
|
||||
|
||||
Args:
|
||||
stack_path: Path to the stack directory
|
||||
spec_file: Path to the deployment spec file
|
||||
deployment_dir_path: Deployment directory path (already created with deployment.yml)
|
||||
deployment_dir_path: Deployment directory path
|
||||
(already created with deployment.yml)
|
||||
|
||||
Output structure:
|
||||
deployment-dir/
|
||||
@@ -208,13 +211,14 @@ def generate_helm_chart(stack_path: str, spec_file: str, deployment_dir_path: Pa
|
||||
# 5. Create chart directory and invoke Kompose
|
||||
chart_dir = deployment_dir_path / "chart"
|
||||
|
||||
print(f"Converting {len(compose_files)} compose file(s) to Helm chart using Kompose...")
|
||||
print(
|
||||
f"Converting {len(compose_files)} compose file(s) to Helm chart "
|
||||
"using Kompose..."
|
||||
)
|
||||
|
||||
try:
|
||||
output = convert_to_helm_chart(
|
||||
compose_files=compose_files,
|
||||
output_dir=chart_dir,
|
||||
chart_name=chart_name
|
||||
compose_files=compose_files, output_dir=chart_dir, chart_name=chart_name
|
||||
)
|
||||
if opts.o.debug:
|
||||
print(f"Kompose output:\n{output}")
|
||||
@@ -291,7 +295,11 @@ Edit the generated template files in `templates/` to customize:
|
||||
print(f" Stack: {stack_path}")
|
||||
|
||||
# Count generated files
|
||||
template_files = list((chart_dir / "templates").glob("*.yaml")) if (chart_dir / "templates").exists() else []
|
||||
template_files = (
|
||||
list((chart_dir / "templates").glob("*.yaml"))
|
||||
if (chart_dir / "templates").exists()
|
||||
else []
|
||||
)
|
||||
print(f" Files: {len(template_files)} template(s) generated")
|
||||
|
||||
print("\nDeployment directory structure:")
|
||||
|
||||
@@ -53,7 +53,7 @@ def run_helm_job(
|
||||
release: str = None,
|
||||
namespace: str = "default",
|
||||
timeout: int = 600,
|
||||
verbose: bool = False
|
||||
verbose: bool = False,
|
||||
) -> None:
|
||||
"""
|
||||
Run a one-time job from a Helm chart.
|
||||
@@ -93,22 +93,31 @@ def run_helm_job(
|
||||
print(f"Running job '{job_name}' from helm chart: {chart_dir}")
|
||||
|
||||
# Use helm template to render the job manifest
|
||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as tmp_file:
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="w", suffix=".yaml", delete=False
|
||||
) as tmp_file:
|
||||
try:
|
||||
# Render job template with job enabled
|
||||
# Use --set-json to properly handle job names with dashes
|
||||
jobs_dict = {job_name: {"enabled": True}}
|
||||
values_json = json.dumps(jobs_dict)
|
||||
helm_cmd = [
|
||||
"helm", "template", release, str(chart_dir),
|
||||
"--show-only", job_template_file,
|
||||
"--set-json", f"jobs={values_json}"
|
||||
"helm",
|
||||
"template",
|
||||
release,
|
||||
str(chart_dir),
|
||||
"--show-only",
|
||||
job_template_file,
|
||||
"--set-json",
|
||||
f"jobs={values_json}",
|
||||
]
|
||||
|
||||
if verbose:
|
||||
print(f"Running: {' '.join(helm_cmd)}")
|
||||
|
||||
result = subprocess.run(helm_cmd, check=True, capture_output=True, text=True)
|
||||
result = subprocess.run(
|
||||
helm_cmd, check=True, capture_output=True, text=True
|
||||
)
|
||||
tmp_file.write(result.stdout)
|
||||
tmp_file.flush()
|
||||
|
||||
@@ -121,18 +130,30 @@ def run_helm_job(
|
||||
actual_job_name = manifest.get("metadata", {}).get("name", job_name)
|
||||
|
||||
# Apply the job manifest
|
||||
kubectl_apply_cmd = ["kubectl", "apply", "-f", tmp_file.name, "-n", namespace]
|
||||
subprocess.run(kubectl_apply_cmd, check=True, capture_output=True, text=True)
|
||||
kubectl_apply_cmd = [
|
||||
"kubectl",
|
||||
"apply",
|
||||
"-f",
|
||||
tmp_file.name,
|
||||
"-n",
|
||||
namespace,
|
||||
]
|
||||
subprocess.run(
|
||||
kubectl_apply_cmd, check=True, capture_output=True, text=True
|
||||
)
|
||||
|
||||
if verbose:
|
||||
print(f"Job {actual_job_name} created, waiting for completion...")
|
||||
|
||||
# Wait for job completion
|
||||
wait_cmd = [
|
||||
"kubectl", "wait", "--for=condition=complete",
|
||||
"kubectl",
|
||||
"wait",
|
||||
"--for=condition=complete",
|
||||
f"job/{actual_job_name}",
|
||||
f"--timeout={timeout}s",
|
||||
"-n", namespace
|
||||
"-n",
|
||||
namespace,
|
||||
]
|
||||
|
||||
subprocess.run(wait_cmd, check=True, capture_output=True, text=True)
|
||||
|
||||
@@ -38,10 +38,7 @@ def get_kompose_version() -> str:
|
||||
raise Exception("kompose not found in PATH")
|
||||
|
||||
result = subprocess.run(
|
||||
["kompose", "version"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=10
|
||||
["kompose", "version"], capture_output=True, text=True, timeout=10
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
@@ -55,7 +52,9 @@ def get_kompose_version() -> str:
|
||||
return version
|
||||
|
||||
|
||||
def convert_to_helm_chart(compose_files: List[Path], output_dir: Path, chart_name: str = None) -> str:
|
||||
def convert_to_helm_chart(
|
||||
compose_files: List[Path], output_dir: Path, chart_name: str = None
|
||||
) -> str:
|
||||
"""
|
||||
Invoke kompose to convert Docker Compose files to a Helm chart.
|
||||
|
||||
@@ -92,12 +91,7 @@ def convert_to_helm_chart(compose_files: List[Path], output_dir: Path, chart_nam
|
||||
cmd.extend(["--chart", "-o", str(output_dir)])
|
||||
|
||||
# Execute kompose
|
||||
result = subprocess.run(
|
||||
cmd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=60
|
||||
)
|
||||
result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
|
||||
|
||||
if result.returncode != 0:
|
||||
raise Exception(
|
||||
|
||||
Reference in New Issue
Block a user