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 handling of binaryData .url keys #251

Merged
merged 5 commits into from
Jan 23, 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
11 changes: 10 additions & 1 deletion .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
jekkel marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build sidecar
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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 &&
Expand All @@ -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 &&
Expand Down
6 changes: 5 additions & 1 deletion src/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions test/resources/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions test/server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
3 changes: 3 additions & 0 deletions test/server/server.py
Original file line number Diff line number Diff line change
@@ -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()


Expand Down
Empty file added test/server/static/.empty
Empty file.