Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support symbolic linked pipelines to avoid repetition #580

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion kpops/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from collections.abc import Iterable, Iterator
from pathlib import Path
from glob import glob

from kpops.const.file_type import PIPELINE_YAML

Expand All @@ -20,7 +21,11 @@ def collect_pipeline_paths(pipeline_paths: Iterable[Path]) -> Iterator[Path]:
if pipeline_path.is_file():
yield pipeline_path
elif pipeline_path.is_dir():
yield from sorted(pipeline_path.glob(f"**/{PIPELINE_YAML}"))
# TODO: In python 3.13 symbolic links become supported by Path.glob
# docs.python.org/3.13#pathlib.Path.glob, probably it make sense to use it after ugprading,
# likely the code will look like:
# yield from sorted(pipeline_path.glob(f"**/{PIPELINE_YAML}", recurse_symlinks=True))
yield from sorted(Path(p).resolve() for p in glob(f"{pipeline_path}/**/{PIPELINE_YAML}", recursive=True))
else:
msg = f"The entered pipeline path '{pipeline_path}' should be a directory or file."
raise ValueError(msg)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- type: filter
name: "a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name-a-long-name"
values:
commandLine:
TYPE: "nothing"
resources:
requests:
memory: 3G
replicaCount: 4
autoscaling:
minReplicas: 4
maxReplicas: 4
1 change: 1 addition & 0 deletions tests/pipeline/resources/symlinked-folder
36 changes: 36 additions & 0 deletions tests/pipeline/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,3 +882,39 @@ def test_streams_bootstrap(self, snapshot: Snapshot):
assert result.exit_code == 0, result.stdout

snapshot.assert_match(result.stdout, PIPELINE_YAML)

def test_symlinked_pipeline_as_original_pipeline(
self,
):
pipeline_original = kpops.generate(
RESOURCE_PATH / "first-pipeline" / PIPELINE_YAML,
)
pipeline_symlinked = kpops.generate(
RESOURCE_PATH / "pipeline-symlinked" / PIPELINE_YAML,
)

assert pipeline_original == pipeline_symlinked

def test_symlinked_folder_renders_as_original_folder_pipeline(
self,
):
pipeline_original = kpops.generate(
RESOURCE_PATH / "first-pipeline" / PIPELINE_YAML,
)
pipeline_symlinked = kpops.generate(
RESOURCE_PATH / "symlinked-folder" / PIPELINE_YAML,
)

assert pipeline_original == pipeline_symlinked

def test_symlinked_folder_and_pipelines_with_normal_pipeline_render_as_original(
self,
):
pipeline_original = kpops.generate(
RESOURCE_PATH / "pipeline-folders" / PIPELINE_YAML,
)
pipeline_symlinked = kpops.generate(
RESOURCE_PATH / "pipeline-folders-with-symlinks" / PIPELINE_YAML,
)

assert pipeline_original == pipeline_symlinked