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

run: Add pull policy --pull flag #2179

Merged
merged 4 commits into from
Oct 30, 2023
Merged

run: Add pull policy --pull flag #2179

merged 4 commits into from
Oct 30, 2023

Conversation

burak-ok
Copy link
Member

run: Add pull policy --pull flag

  • --pull missing (default) only pulls the image when it is missing
  • --pull always Pulls always
  • --pull never Never pulls

The pull policy behavior is the same as Docker, but not the same as for K8s. For K8s in the default case the pull policy is missing, except when the latest tag is used. Then it is always pulling

Fixes #2101
Slack Discussion: https://kubernetes.slack.com/archives/CSYL75LF6/p1697722813839619

@mqasimsarfraz
Copy link
Member

I tried it together with @claudiamarcubina and it seems that it isn't working as expected for pull policy always:

$ go run -exec "sudo -E" ./cmd/ig image pull ghcr.io/inspektor-gadget/gadget/trace_open:latest
$ go run -exec "sudo -E" ./cmd/ig image pull ghcr.io/inspektor-gadget/gadget/trace_exec:latest
$ go run -exec "sudo -E" ./cmd/ig image tag ghcr.io/inspektor-gadget/gadget/trace_exec:latest ghcr.io/inspektor-gadget/gadget/trace_open:latest
# ensure trace_open is actually trace_exec
$ go run -exec "sudo -E" ./cmd/ig run ghcr.io/inspektor-gadget/gadget/trace_exec:latest
$ go run -exec "sudo -E" ./cmd/ig run ghcr.io/inspektor-gadget/gadget/trace_open:latest
# verify trace_open is trace_open
$ go run -exec "sudo -E" ./cmd/ig run --pull always ghcr.io/inspektor-gadget/gadget/trace_open:latest

It seems oci-store used by PullGadgetImage isn't in sync with one used by GetGadgetImage

@burak-ok
Copy link
Member Author

I tried it together with @claudiamarcubina and it seems that it isn't working as expected for pull policy always:

I tested it locally and its interesting:

➭ go run --exec "sudo -E" ./cmd/ig/... image list                                                                                   
INFO[0000] Experimental features enabled                
REPOSITORY                             TAG          DIGEST      
ghcr.io/burak-ok/trace_exec            latest       30507a96ca40
ghcr.io/burak-ok/trace_open            latest       d798a768d944

➭ go run --exec "sudo -E" ./cmd/ig/... image tag ghcr.io/burak-ok/trace_open ghcr.io/burak-ok/trace_exec
INFO[0000] Experimental features enabled                
Successfully tagged with ghcr.io/burak-ok/trace_exec:latest@sha256:d798a768d9449b13694aae2d0eb074e5f39cdddbc6a116fc26afe8a671afcfb9

➭ go run --exec "sudo -E" ./cmd/ig/... image list                                                       
INFO[0000] Experimental features enabled                
REPOSITORY                             TAG           DIGEST      
ghcr.io/burak-ok/trace_exec            latest        d798a768d944
ghcr.io/burak-ok/trace_open            latest        d798a768d944

➭ go run --exec "sudo -E" ./cmd/ig/... run ghcr.io/burak-ok/trace_exec --pull always                                                
INFO[0000] Experimental features enabled                
RUNTIME.CONTAINERNAME      PID           COMM             UID      GID      RET      FNAME                                              
minikube-docker            1894556888                     1041     57564    -1                                                          
minikube-docker            1902313085                     1041     57570    -1       -init                                              
^C%

➭ go run --exec "sudo -E" ./cmd/ig/... image list                                                       
INFO[0000] Experimental features enabled                
REPOSITORY                             TAG           DIGEST      
ghcr.io/burak-ok/trace_exec            latest        30507a96ca40
ghcr.io/burak-ok/trace_open            latest        d798a768d944

➭ go run --exec "sudo -E" ./cmd/ig/... run ghcr.io/burak-ok/trace_exec --pull never 
INFO[0000] Experimental features enabled                
RUNTIME.CONTAINERNAME                               PID                         PPID                        COMM             UID                         GID                        RETVAL                    
minikube-docker                                     64419                       19274                       bridge           0                           0                          0                         
minikube-docker                                     64425                       19274                       portmap          0                           0                          0                         

The first running gadget is clearly trace_open. But image list shows the correct trace_exec image right after the ig run --pull always command.
It can also be seen in the ig run --pull never command right after it that it is the correct trace_exec image.

Just wanted to share - Fixing it :)

@burak-ok
Copy link
Member Author

It seems oci-store used by PullGadgetImage isn't in sync with one used by GetGadgetImage

That was totally correct. It didn't refer to the same imageStore instance. I thought it would always operate on the underlying filesystem - instead it caches it in memory in the instance somewhere.

I just had to "reload" the imageStore

Copy link
Member

@claudiamarcubina claudiamarcubina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works as described ✅ Thanks!

pkg/oci/oci.go Outdated Show resolved Hide resolved
Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine. Just one blocker question on the first commit. LGTM otherwise.

pkg/oci/oci.go Outdated Show resolved Hide resolved
pkg/oci/oci.go Show resolved Hide resolved
Signed-off-by: Burak Ok <burakok@microsoft.com>
Signed-off-by: Burak Ok <burakok@microsoft.com>
Signed-off-by: Burak Ok <burakok@microsoft.com>
Signed-off-by: Burak Ok <burakok@microsoft.com>
Copy link
Member

@mauriciovasquezbernal mauriciovasquezbernal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for working on this!

@burak-ok burak-ok merged commit cbe1bb8 into main Oct 30, 2023
50 checks passed
@burak-ok burak-ok deleted the burak/run/pull_policy branch October 30, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

run: Implement --pull argument
4 participants