diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..677eaf80 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,9 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/kubernetes-helm +{ + "name": "Kubernetes - Local Configuration", + "build": { + "context": "..", + "dockerfile": "../Dockerfile" + } +} diff --git a/.github/workflows/python-package.yaml b/.github/workflows/python-package.yaml index 363e2081..3bd09184 100644 --- a/.github/workflows/python-package.yaml +++ b/.github/workflows/python-package.yaml @@ -38,6 +38,10 @@ jobs: - name: Test with pytest run: | SKIP_DIFF_TESTS=1 pytest --cov=flux_local --cov-report=term-missing + - name: Test with pytest pydantic v1 + run: | + pip install pydantic==1.10.11 + SKIP_DIFF_TESTS=1 pytest --cov=flux_local --cov-report=term-missing - uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f8174f7c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# Docker environment for local development in devcontainer +FROM ubuntu:jammy-20230308 + +RUN apt-get update --fix-missing && \ + apt-get upgrade -y && \ + apt-get install -y --fix-missing \ + curl \ + unzip \ + software-properties-common \ + vim \ + git \ + python3-pip + +# renovate: datasource=github-releases depName=kubernetes-sigs/kustomize +ARG KUSTOMIZE_VERSION=v5.0.3 +RUN cd /usr/local/bin/ && \ + curl -OL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz && \ + tar xf kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz && \ + chmod +x kustomize +RUN kustomize version + +# renovate: datasource=github-releases depName=helm/helm +ARG HELM_CLI_VERSION=v3.12.1 +RUN mkdir -p /src && \ + cd /src && \ + curl -OL https://get.helm.sh/helm-${HELM_CLI_VERSION}-linux-amd64.tar.gz && \ + tar xf helm-${HELM_CLI_VERSION}-linux-amd64.tar.gz && \ + cp linux-amd64/helm /usr/local/bin/helm && \ + rm -fr /src +RUN helm version + +# renovate: datasource=github-releases depName=kyverno/kyverno +ARG KYVERNO_VERSION=v1.10.0 +RUN mkdir -p /src && \ + cd /src && \ + curl -OL https://github.com/kyverno/kyverno/releases/download/${KYVERNO_VERSION}/kyverno-cli_${KYVERNO_VERSION}_linux_x86_64.tar.gz && \ + tar xf kyverno-cli_${KYVERNO_VERSION}_linux_x86_64.tar.gz && \ + cp kyverno /usr/local/bin/kyverno && \ + chmod +x /usr/local/bin/kyverno && \ + rm -fr /src +RUN kyverno version + +COPY . /src/ +WORKDIR /src/ +RUN pip3 install -r /src/requirements.txt + +SHELL ["/bin/bash", "-c"] \ No newline at end of file diff --git a/flux_local/manifest.py b/flux_local/manifest.py index 68378db9..96b18e9a 100644 --- a/flux_local/manifest.py +++ b/flux_local/manifest.py @@ -10,7 +10,10 @@ import aiofiles import yaml -from pydantic import BaseModel, Field +try: + from pydantic.v1 import BaseModel, Field +except ImportError: + from pydantic import BaseModel, Field from .exceptions import InputException @@ -427,6 +430,8 @@ async def read_manifest(manifest_path: Path) -> Manifest: """ async with aiofiles.open(str(manifest_path)) as manifest_file: content = await manifest_file.read() + if not content: + raise ValueError("validation error for Manifest file {manifest_path}") return cast(Manifest, Manifest.parse_yaml(content)) diff --git a/requirements.txt b/requirements.txt index a7de88f2..b19e1987 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ nest_asyncio==1.5.6 pdoc==14.0.0 pip==23.1.2 pre-commit==3.3.3 -pydantic==1.10.11 +pydantic==2.0.3 pytest==7.4.0 pytest-asyncio==0.21.1 pytest-cov==4.1.0 diff --git a/tests/test_manifest.py b/tests/test_manifest.py index ac16d8eb..d47fdcd3 100644 --- a/tests/test_manifest.py +++ b/tests/test_manifest.py @@ -4,7 +4,6 @@ import pytest import yaml -from pydantic import ValidationError from flux_local.manifest import ( Cluster, @@ -94,7 +93,7 @@ async def test_read_write_empty_manifest(tmp_path: Path) -> None: async def test_read_manifest_invalid_file() -> None: """Test reading an invalid manifest file.""" - with pytest.raises(ValidationError, match="validation error for Manifest"): + with pytest.raises(ValueError, match="validation error for Manifest"): await read_manifest(Path("/dev/null"))