GoogleContainerTools / skaffold

Easy and Repeatable Kubernetes Development
https://skaffold.dev/
Apache License 2.0
15.03k stars 1.62k forks source link

Skaffold File Sync - Subsequent Pod Deploy #6924

Open SizZiKe opened 2 years ago

SizZiKe commented 2 years ago

Expected behavior

Skaffold resyncs files after a breaking change causes a pod to redeploy

Actual behavior

Skaffold doesn't do anything - it will continue to sync files to the new pod when changes are made but previous changes are ignored. I understand the files are synced to the pod rather than the container, but this requires skaffold dev to be restarted if the pod ever crashes.

Information

  - image: myapp
    context: myapp
    docker:
      dockerfile: myapp.Dockerfile
    sync:
      infer:
      - '**'

Steps to reproduce the behavior

  1. setup skaffold with file sync
  2. once stable, make a change to trigger the file sync
  3. delete the pod that the file was synced to
  4. examine the new pod, the content isn't synced on pod standup
tejal29 commented 2 years ago

Thanks for the bug @SizZiKe. Someone from the team will take a look. Lets us know if you are interested in contributing and we can get a team member to help you!

circlingthesun commented 2 years ago

I currently have a large amount of unstaged files. Whenever a pod restarts I have to restart skaffold. As of late that's not even working because skaffold detects that the image is available in docker's cache and therefore just starts an old container with none of my changes, so I have to ssh into minikube to purge the cache. Are there any workarounds? Can I force skaffold to sync all files?

stefanhenseler commented 1 year ago

@tejal29 I'm also experiencing the same issue. It would be nice if Skaffold triggers a resync of changed or created files after the pod restarts. I'm using a manual sync in my scenario, but I have the same symptoms. After pods are redeployed, I need to "update" all the files again to trigger a sync. In any case, a user would expect the files to remain in sync locally, similar to how the bind mount in docker-compose works. I'm happy to help with the implementation of this.

gianfrancodemarco commented 1 year ago

Same here, as @stefanhenseler mentioned, the only way I found to make it work is to re-update manually all of the files to trigger the sync again. I think this is crucial for anyone using the sync functionality.

MrCox007 commented 7 months ago

Any news on this?

filipenf commented 5 months ago

I use this as a workaround:

function sync_changed() {
    pod_name=$(find_pod_by_app_name "my-app")
    changed_files=$(git diff --name-only origin/master -- src/)
    force_sync=<some files that need to be synced every time>
    echo $changed_files $always_sync | xargs tar -cvf - | \
        kubectl exec -i ${pod_name} -- bash -c "tar -xvf - -C /app/"
}

It does the trick but it is not perfect since it doesn't implement the same logic as skaffold