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

Fix support for Kustomizations with absolute paths #426

Merged
merged 1 commit into from
Dec 17, 2023
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
5 changes: 4 additions & 1 deletion flux_local/git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ def adjust_ks_path(doc: Kustomization, selector: PathSelector) -> Path | None:
)
return None

return Path(doc.path)
path = Path(doc.path)
if path.is_absolute():
return path.relative_to("/")
return path


async def kustomization_traversal(selector: PathSelector) -> list[Kustomization]:
Expand Down
24 changes: 23 additions & 1 deletion tests/test_git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
Source,
PathSelector,
is_allowed_source,
adjust_ks_path
)
from flux_local.kustomize import Kustomize, Stash
from flux_local.command import Task, run_piped
from flux_local.manifest import Kustomization
from flux_local.context import trace

TESTDATA = Path("tests/testdata/cluster")

TESTDATA_FULL_PATH = Path.cwd() / TESTDATA

async def test_build_manifest(snapshot: SnapshotAssertion) -> None:
"""Tests for building the manifest."""
Expand Down Expand Up @@ -259,3 +260,24 @@ async def piped_recorder(tasks: Sequence[Task]) -> str:
await build_manifest(selector=selector)

assert context_cmds == snapshot


@pytest.mark.parametrize(
("path", "expected_path"),
[
("kubernetes/apps/example", "kubernetes/apps/example"),
("./kubernetes/apps/example", "kubernetes/apps/example"),
("/kubernetes/apps/example", "kubernetes/apps/example"),
("", str(TESTDATA))
]
)
def test_adjust_ks_path(path: str, expected_path: str) -> None:
"""Test adjusting the Kustomization path relative directory."""
ks = Kustomization(
name="ks",
namespace="flux-system",
path=path,
source_name="flux-system",
)
selector = PathSelector(TESTDATA_FULL_PATH)
assert adjust_ks_path(ks, selector) == Path(expected_path)
2 changes: 1 addition & 1 deletion tests/testdata/cluster7/clusters/home/charts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
namespace: flux-system
spec:
interval: 10m0s
path: ./tests/testdata/cluster7/flux/charts
path: /tests/testdata/cluster7/flux/charts
prune: true
sourceRef:
kind: GitRepository
Expand Down