Skip to content

feat: suppport repo ls sub-namespace#768

Merged
shizhMSFT merged 3 commits into
oras-project:mainfrom
wangxiaoxuan273:sub-namespaces
Feb 3, 2023
Merged

feat: suppport repo ls sub-namespace#768
shizhMSFT merged 3 commits into
oras-project:mainfrom
wangxiaoxuan273:sub-namespaces

Conversation

@wangxiaoxuan273

@wangxiaoxuan273 wangxiaoxuan273 commented Jan 28, 2023

Copy link
Copy Markdown
Contributor

Resolves #733

Test output on terminal:
image

Signed-off-by: wangxiaoxuan273 wangxiaoxuan119@gmail.com

@wangxiaoxuan273

wangxiaoxuan273 commented Jan 28, 2023

Copy link
Copy Markdown
Contributor Author

I have two design questions:

  • When engineering is a repository and a namespace, should example-registry/engineering return the engineering repository?

i.e. :

$ oras repo ls example-registry
employeehandbook
engineering
engineering/bestpractices
engineering/newhires/onboarding
engineering/newhires/teamoverview

currently the engineering repository is not returned given example-registry/engineering.

$ oras repo ls example-registry/engineering
engineering/bestpractices
engineering/newhires/onboarding
engineering/newhires/teamoverview
  • Which display is better?

currently:

$ oras repo ls example-registry/engineering
engineering/bestpractices
engineering/newhires/onboarding
engineering/newhires/teamoverview

or

$ oras repo ls example-registry/engineering
bestpractices
newhires/onboarding
newhires/teamoverview

@qweeah

qweeah commented Jan 28, 2023

Copy link
Copy Markdown
Contributor

@qweeah Please take a look at the failed e2e CI test. It's likely that the failed test need to be changed for this feature.

Yes you are right. One assertion can be removed since oras repo ls $REG/$REPO_SUFFIX is now a valid input.

@qweeah

qweeah commented Jan 28, 2023

Copy link
Copy Markdown
Contributor

When engineering is a repository and a namespace, should example-registry/engineering return the engineering repository?

  • If a registry need to explicitly define a separate namespace concept from repository(e.g. ghcr, dockerhub), I don't think engineering can be a repository and a namespace at the same time.
  • If repository is only a slash separated path for a regsitry (e.g. ACR, MCR), engineering SHOULD be included in the result of oras repo ls example.registry/engineering. There is no need to hide the result of a full match.

@qweeah

qweeah commented Jan 28, 2023

Copy link
Copy Markdown
Contributor

Which display is better?

I think the latter is out-of-option. Consider the scenario: How can the result of oras repo ls some.registry/my/repo be displayed if my/repo is a repository?

Comment thread cmd/oras/repository/ls.go Outdated
Comment on lines +58 to +61
hostname, namespace, _ := strings.Cut(args[0], "/")
opts.hostname = hostname
opts.namespace = namespace
// namespace is invalid if a tag is provided
if strings.Contains(namespace, ":") {
return fmt.Errorf("invalid namespace")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we refactor this part into a function so that we can unit test it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Parsing can be simplified in an easier way.

If args[0] contains /, we can parse it using ParseReference(). Otherwise, it is a hostname.

@wangxiaoxuan273 wangxiaoxuan273 Jan 31, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Used ParseReference and created the function parseRepoPath to use in RunE.

Comment thread cmd/oras/repository/ls.go
Comment thread cmd/oras/repository/ls.go Outdated
Comment on lines +94 to +98
before, after, found := strings.Cut(repopath, requestedNamespace)
if !found || after == "" || before != "" {
return false
}
return after[0] == '/'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It partially works and is not readable. Can we choose a simpler implementation?

The reason why it partially works is that the inNamespace("foo", "foo") returns false, which should be true. You need unit tests to ensure code quality.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems to be a UX issue other than a bug.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Used strings.HasPrefix(repopath, opts.namespace+"/") here after discussion.

@codecov-commenter

codecov-commenter commented Jan 29, 2023

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 64.00000% with 9 lines in your changes missing coverage. Please review.

Project coverage is 55.86%. Comparing base (6fe1271) to head (d8956cd).
Report is 422 commits behind head on main.

Files with missing lines Patch % Lines
cmd/oras/repository/ls.go 64.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #768      +/-   ##
==========================================
- Coverage   62.71%   55.86%   -6.86%     
==========================================
  Files          20       23       +3     
  Lines         802      929     +127     
==========================================
+ Hits          503      519      +16     
- Misses        257      368     +111     
  Partials       42       42              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shizhMSFT

Copy link
Copy Markdown
Contributor

I have two design questions:

  • When engineering is a repository and a namespace, should example-registry/engineering return the engineering repository?

i.e. :

$ oras repo ls example-registry
employeehandbook
engineering
engineering/bestpractices
engineering/newhires/onboarding
engineering/newhires/teamoverview

currently the engineering repository is not returned given example-registry/engineering.

$ oras repo ls example-registry/engineering
engineering/bestpractices
engineering/newhires/onboarding
engineering/newhires/teamoverview
  • Which display is better?

currently:

$ oras repo ls example-registry/engineering
engineering/bestpractices
engineering/newhires/onboarding
engineering/newhires/teamoverview

or

$ oras repo ls example-registry/engineering
bestpractices
newhires/onboarding
newhires/teamoverview

This is a good question. I would suggest the latter one:

$ oras repo ls example-registry/engineering
bestpractices
newhires/onboarding
newhires/teamoverview

In this way, it is more consistent with the UNIX ls command. In addition, it is more script-friendly that you can do

namespace=example-registry/engineering
oras repo ls $namespace | while read repo; do
    repo=$namespace/$repo
    echo Tags in $repo:
    oras repo tags $repo
    echo
done

@shizhMSFT shizhMSFT requested a review from FeynmanZhou January 29, 2023 09:28
@FeynmanZhou

Copy link
Copy Markdown
Member

@wangxiaoxuan273 I vote for the latter one and agree with @shizhMSFT 's suggestion.

@wangxiaoxuan273

Copy link
Copy Markdown
Contributor Author

Which display is better?

I think the latter is out-of-option. Consider the scenario: How can the result of oras repo ls some.registry/my/repo be displayed if my/repo is a repository?

Then oras repo ls some.registry/my/repo does not return 'my/repo', if we choose the latter one.
Update: we've decided to use the latter display.

@wangxiaoxuan273 wangxiaoxuan273 requested review from shizhMSFT and removed request for FeynmanZhou February 3, 2023 06:41
Comment thread cmd/oras/repository/ls.go
return cmd
}

func parseRepoPath(opts *repositoryOptions, arg string) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add unit tests for this function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added unit tests.

Comment thread cmd/oras/repository/ls.go Outdated
return err
}
opts.hostname = reference.Registry
opts.namespace = reference.Repository

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
opts.namespace = reference.Repository
opts.namespace = reference.Repository + "/"

so that we don't need to calculate it multiple time in a loop at line 96.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed accordingly.

Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>

@shizhMSFT shizhMSFT left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@shizhMSFT shizhMSFT merged commit 076d859 into oras-project:main Feb 3, 2023
@wangxiaoxuan273 wangxiaoxuan273 deleted the sub-namespaces branch February 3, 2023 11:19
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.

oras repo ls to support sub namespaces

5 participants