kiwigrid / k8s-sidecar

This is a docker container intended to run inside a kubernetes cluster to collect config maps with a specified label and store the included files in a local folder.
MIT License
585 stars 181 forks source link

Side car do not remove the files of a config map when it is deleted #267

Open vkjv opened 1 year ago

vkjv commented 1 year ago

Hi, I have configured k8s-sidecar to monitor some of the configmaps for json file contents and create them as files in the file system. Creation, modification is working fine. But when I remove the configmap itself, side car do not seems to be removing those files which are part if the deleted configmap. Even removing the content from the configmap also, do not seem to be removing the corresponding file. Am I missing something here?

jekkel commented 1 year ago

@vkjv Are you using the latest version? Could you provide (anonymized) logs of the sidecar?

vkjv commented 1 year ago

@vkjv Are you using the latest version? Could you provide (anonymized) logs of the sidecar?

Hi, I made it work using the WATCH. From the documentation it is hard make out in the first place. Since it documents only SLEEP and LIST. SLEEP do not monitor removal of configmap contents. So it worked with WATCH. Please update the documentation and close this case.

Thank you.

jekkel commented 1 year ago

Glad that you were able to make it work for you. I am not sure it's not supposed to work with SLEEP though. Any chance you could provide the requested information?

Any suggestions for the improvements of this:

If METHOD is set to LIST, the sidecar will just list config-maps/secrets and exit. With SLEEP it will list all config-maps/secrets, then sleep for SLEEP_TIME seconds. Anything else will continuously watch for changes.

?

ns-phegde commented 1 year ago

@jekkel I'm also having the same issue with METHOD: "SLEEP". I'm getting the below error when I use something like the config I've specified. To be more precise this happens when a configmap is deleted.

ERROR:

Traceback (most recent call last):
  File "/app/resources.py", line 300, in _update_file
    return remove_file(dest_folder, filename)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/helpers.py", line 103, in remove_file
    complete_file = os.path.join(folder, filename)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 76, in join
TypeError: expected str, bytes or os.PathLike object, not NoneType

CONFIG:

      - name:k8s-sidecar
        image: kiwigrid/k8s-sidecar:1.25.2
        imagePullPolicy: IfNotPresent
        volumeMounts:
          - name: config-volume
            mountPath: "/config/"
          - name: merge-script-volume
            mountPath: "/opt/merge.sh"
            subPath: "merge.sh"
          - name: merge-script-volume
            mountPath: "/opt/config_merge.py"
            subPath: "config_merge.py"
          - name: merge-script-volume
            mountPath: "/opt/requirements.txt"
            subPath: "requirements.txt"
        env:
          - name: LABEL
            value: "config"
          - name: FOLDER
            value: "/config/"
          - name: RESOURCE
            value: "configmap"
          - name: REQ_URL
            value: "http://localhost:8080/reload"
          - name: NAMESPACE
            value: "config-dev"
          - name: SCRIPT
            value: "/opt/merge.sh"
          - name: REQ_METHOD
            value: "POST"
          - name: REQ_SKIP_TLS_VERIFY
            value: "true"
          - name: METHOD
            value: "SLEEP"
          - name: IGNORE_ALREADY_PROCESSED
            value: "true"
github-actions[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has not had any activity in the last 60 days. Thank you for your contributions.