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

oci: Use default registry for Inspektor Gadget #2307

Merged
merged 3 commits into from
Jan 15, 2024

Conversation

mauriciovasquezbernal
Copy link
Member

See #2190

Testing

Before

It's not possible to run a gadget by just specifying their name:

$ sudo -E ig image list
INFO[0000] Experimental features enabled                
REPOSITORY                                  TAG                                         DIGEST 

$ sudo -E ig run trace_exec
INFO[0000] Experimental features enabled                
Error: getting gadget info: getting gadget image: pulling image "trace_exec": creating remote repository: creating remote repository: invalid reference: missing repository

After

Now it's possible

$ sudo -E ig image list
INFO[0000] Experimental features enabled                
REPOSITORY                                  TAG                                         DIGEST   

$ sudo -E ig run trace_exec
INFO[0000] Experimental features enabled                
RUNTIME.CONTAINERNAME     PID            PPID           UID           GID           R… COMM         

Fixes #2190

Copy link
Member

@mqasimsarfraz mqasimsarfraz left a comment

Choose a reason for hiding this comment

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

I tested it and works fine. It will simplify running official gadgets.

I have only one question regarding UX with list command. I am wondering if it makes sense to not show the default domain / default repo prefix when list the images. This should be similar to what docker does:

→ docker images
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
→ docker pull docker.io/library/alpine
Using default tag: latest
latest: Pulling from library/alpine
661ff4d9561e: Pull complete 
Digest: sha256:51b67269f354137895d43f3b3d810bfacd3945438e94dc5ac55fdac340352f48
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
→ docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
alpine       latest    f8c20f8bbcb6   5 weeks ago   7.38MB

Also, it will encourage to use names like trace_open for official gadget (after I just listed them using list). What do you think?

pkg/oci/oci.go Outdated Show resolved Hide resolved
pkg/oci/oci.go Outdated Show resolved Hide resolved
pkg/oci/oci.go Show resolved Hide resolved
// needs to be already validated before.
func splitIGDomain(name string) (domain, remainder string) {
i := strings.IndexRune(name, '/')
if i == -1 || (!strings.ContainsAny(name[:i], ".:") && name[:i] != localhost && strings.ToLower(name[:i]) == name[:i]) {
Copy link
Member

Choose a reason for hiding this comment

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

Just for my understanding, for strings.ToLower(name[:i]) == name[:i]) we assume it it a domain name since it contains capital letters?

Copy link
Member Author

Choose a reason for hiding this comment

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

TBH I took this from https://github.com/distribution/reference/blob/v0.5.0/normalize.go#L126 without studying it in depth. I think your analysis is correct, it assumes it's a domain if there are capital letters, but domains are supported to be lower case, aren't they?

It was introduced in distribution/reference@ca2a562, the tests cases added parse the domain with upper case, not sure what this is for and the commit doesn't contain anymore information.

Copy link
Member

Choose a reason for hiding this comment

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

domains are supported to be lower case, aren't they?

IIUC, domains are case insensitive, https://serverfault.com/a/261344

It was introduced in distribution/reference@ ca2a562, the tests cases added parse the domain with upper case, not sure what this is for and the commit doesn't contain anymore
information.

I found more information here, distribution/distribution#2979 and it gives more context why they did it.

Copy link
Member

@burak-ok burak-ok left a comment

Choose a reason for hiding this comment

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

Apart from the naming this looks good. I also added a unit test for the split function since it seems important :D
90b0934

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

@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.

What do you think?

I agree. Updated the PR to trim the prefix when listing images.

pkg/oci/oci.go Outdated Show resolved Hide resolved
pkg/oci/oci.go Show resolved Hide resolved
// needs to be already validated before.
func splitIGDomain(name string) (domain, remainder string) {
i := strings.IndexRune(name, '/')
if i == -1 || (!strings.ContainsAny(name[:i], ".:") && name[:i] != localhost && strings.ToLower(name[:i]) == name[:i]) {
Copy link
Member Author

Choose a reason for hiding this comment

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

TBH I took this from https://github.com/distribution/reference/blob/v0.5.0/normalize.go#L126 without studying it in depth. I think your analysis is correct, it assumes it's a domain if there are capital letters, but domains are supported to be lower case, aren't they?

It was introduced in distribution/reference@ca2a562, the tests cases added parse the domain with upper case, not sure what this is for and the commit doesn't contain anymore information.

if named, ok := parsed.(reference.Named); ok {
repository = named.Name()
}
repository = strings.TrimPrefix(repository, defaultDomain+"/"+officialRepoPrefix)
Copy link
Member

Choose a reason for hiding this comment

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

nit: Perhaps we can also trim the defaultDomain for cases like ghcr.io/foo/bar to be foo/bar

Copy link
Member Author

Choose a reason for hiding this comment

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

I prefer to trim it only when the full thing matches. I'm don't think we should be treating any other think than "ghcr.io/inspektor-gadget/gadgets" in a special way.

Copy link
Member

@mqasimsarfraz mqasimsarfraz left a comment

Choose a reason for hiding this comment

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

LGTM! I tested it and it works as described in the PR description.

- Don't export it as there is not any reason to export this function as
users interact through other functions that don't require it.
- Make it receive a "image reference.Named" to avoid calling
getRepositoryFromImage that is somehow duplicated.

Signed-off-by: Mauricio Vásquez <mauriciov@microsoft.com>
Move logic of getTagFromImage() and getRepositoryFromImage() directly to
ListGadgetImages.

Signed-off-by: Mauricio Vásquez <mauriciov@microsoft.com>
Signed-off-by: Burak Ok <burakok@microsoft.com>
@mauriciovasquezbernal mauriciovasquezbernal merged commit 36ffbe9 into main Jan 15, 2024
53 checks passed
@mauriciovasquezbernal mauriciovasquezbernal deleted the mauricio/default-registry branch January 15, 2024 18:54
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.

[Discussion] Default registries for image-based gadgets
4 participants