diff --git a/.github/workflows/build_and_test.yaml b/.github/workflows/build_and_test.yaml index a11b04e..4180cfd 100644 --- a/.github/workflows/build_and_test.yaml +++ b/.github/workflows/build_and_test.yaml @@ -6,6 +6,8 @@ jobs: build: runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - name: Build sidecar @@ -14,10 +16,13 @@ jobs: push: false outputs: type=docker,dest=/tmp/k8s-sidecar.tar tags: "kiwigrid/k8s-sidecar:testing" + - name: Prepare dummy server static resources + run: | + cp test/kubelogo.png test/server/static/ - name: Build dummy server uses: docker/build-push-action@v3 with: - context: "{{defaultContext}}:test/server" + context: "test/server" push: false outputs: type=docker,dest=/tmp/dummy-server.tar tags: "dummy-server:1.0.0" @@ -123,6 +128,7 @@ jobs: kubectl cp sidecar:/tmp/hello.world /tmp/hello.world kubectl cp sidecar:/tmp/cm-kubelogo.png /tmp/cm-kubelogo.png kubectl cp sidecar:/tmp/secret-kubelogo.png /tmp/secret-kubelogo.png + kubectl cp sidecar:/tmp/url-downloaded-kubelogo.png /tmp/url-downloaded-kubelogo.png kubectl cp sidecar:/tmp/script_result /tmp/script_result kubectl cp sidecar:/tmp/absolute/absolute.txt /tmp/absolute.txt kubectl cp sidecar:/tmp/relative/relative.txt /tmp/relative.txt @@ -134,6 +140,7 @@ jobs: kubectl cp sidecar-5xx:/tmp-5xx/hello.world /tmp/5xx/hello.world kubectl cp sidecar-5xx:/tmp-5xx/cm-kubelogo.png /tmp/5xx/cm-kubelogo.png kubectl cp sidecar-5xx:/tmp-5xx/secret-kubelogo.png /tmp/5xx/secret-kubelogo.png + kubectl cp sidecar-5xx:/tmp-5xx/url-downloaded-kubelogo.png /tmp/5xx/url-downloaded-kubelogo.png # script also generates into '/tmp' kubectl cp sidecar-5xx:/tmp/script_result /tmp/5xx/script_result # absolute path in configmap points to /tmp in 'absolute-configmap' @@ -169,6 +176,7 @@ jobs: echo -n "Hello World!" | diff - /tmp/hello.world && diff test/kubelogo.png /tmp/cm-kubelogo.png && diff test/kubelogo.png /tmp/secret-kubelogo.png && + diff test/kubelogo.png /tmp/url-downloaded-kubelogo.png && echo -n "This absolutely exists" | diff - /tmp/absolute.txt && echo -n "This relatively exists" | diff - /tmp/relative.txt && echo -n "This change-dir exists" | diff - /tmp/change-dir.txt && @@ -179,6 +187,7 @@ jobs: echo -n "Hello World!" | diff - /tmp/5xx/hello.world && diff test/kubelogo.png /tmp/5xx/cm-kubelogo.png && diff test/kubelogo.png /tmp/5xx/secret-kubelogo.png && + diff test/kubelogo.png /tmp/5xx/url-downloaded-kubelogo.png && echo -n "This absolutely exists" | diff - /tmp/5xx/absolute.txt && echo -n "This relatively exists" | diff - /tmp/5xx/relative.txt && echo -n "This change-dir exists" | diff - /tmp/5xx/change-dir.txt && diff --git a/src/resources.py b/src/resources.py index 1d4c51a..40d96a9 100755 --- a/src/resources.py +++ b/src/resources.py @@ -54,7 +54,11 @@ def _get_file_data_and_name(full_filename, content, enable_5xx, content_type=CON if full_filename.endswith(".url"): filename = full_filename[:-4] - file_data = request(file_data, "GET", enable_5xx).text + if content_type == CONTENT_TYPE_BASE64_BINARY: + file_url = file_data.decode('utf8') + file_data = request(file_url, "GET", enable_5xx).content + else: + file_data = request(file_data, "GET", enable_5xx).text else: filename = full_filename diff --git a/test/resources/resources.yaml b/test/resources/resources.yaml index 1326440..5bb4a10 100644 --- a/test/resources/resources.yaml +++ b/test/resources/resources.yaml @@ -72,3 +72,13 @@ metadata: findme: "yup" data: secured.txt.url: "http://dummy-server/secured" +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: url-configmap-binary-download + labels: + findme: "yup" +binaryData: + # Base64 encoded url is 'http://dummy-server/static/kubelogo.png' + url-downloaded-kubelogo.png.url: "aHR0cDovL2R1bW15LXNlcnZlci9zdGF0aWMva3ViZWxvZ28ucG5n" diff --git a/test/server/Dockerfile b/test/server/Dockerfile index 1992415..059d764 100644 --- a/test/server/Dockerfile +++ b/test/server/Dockerfile @@ -2,4 +2,5 @@ FROM python:3.9-alpine RUN pip install fastapi uvicorn EXPOSE 80 COPY server.py /server.py +COPY static /static/ CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "80"] diff --git a/test/server/server.py b/test/server/server.py index c6ea0d3..23cf915 100644 --- a/test/server/server.py +++ b/test/server/server.py @@ -1,10 +1,13 @@ from fastapi import Depends, FastAPI, status, HTTPException from fastapi.logger import logger from fastapi.security import HTTPBasic, HTTPBasicCredentials +from fastapi.staticfiles import StaticFiles from starlette.responses import PlainTextResponse app = FastAPI() +app.mount("/static", StaticFiles(directory="static"), name="static") + basic_auth_scheme = HTTPBasic() diff --git a/test/server/static/.empty b/test/server/static/.empty new file mode 100644 index 0000000..e69de29