morecontainers / reloader

The Unlicense
1 stars 0 forks source link

Error at line 13, tested on MacOS. #2

Open Bogdan0w opened 3 years ago

Bogdan0w commented 3 years ago

Tried to run python file on MacOS with Python 3.8.2. I have installed all required libraries. Attached a screenshot of error. Can happened that I did something wrong.

1
hholst80 commented 3 years ago

Good catch. There is actually a set of environment variables that must be set.

  1. RELOADER_PATH must be set to a directory where reloader will write config files.
  2. RELOADER_CONFIGMAP exclusive or RELOADER_SECRET must be set to a resource name.

In order to test this properly you also need a Kubernetes endpoint to attach to.

Assuming you have that you can start a proxy with kubectl proxy and you will have a K8s endpoint listening at http://localhost:8001. Either minicube or k3s will work fine. For MacOS I think it is not yet possible to run k3s so your option is minicube, or host a K8s instance on another machine which runs Linux.

You can insert a dummy config by the command:

echo "# this is a test config" > config
kubectl create configmap test --from-file=config

When those pre-conditions are fulfilled you can start reloader:

RELOADER_PATH=/tmp RELOADER_CONFIGMAP=test python3 -m reloader

Every time you update the configmap test reloader will rewrite /tmp/config with the contents of that asset. You can change a configmap simply by running

EDITOR=nano kubectl edit configmap test
hholst80 commented 3 years ago

I think it would be more correct to:

  1. make RELOADER_PATH optional. If it is missing reloader should simply not save the asset. Requires a minor change to config.py. The logic is already there in __main__.py, if CONFIGMAP and PATH, so if PATH is None the update method is not called, same for the other branch if SECRET and PATH...
  2. Gracefully handle the no-op case when no assets are monitored for changes, and quit. That is, remove the xor assert from config.py and handle it in __main__.py.

I would be happy to receive a PR that addresses one or both of these suggestions.