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

registry library api change for multi-version stack/sample support #108

Merged
merged 4 commits into from
Mar 24, 2022

Conversation

yangcao77
Copy link
Contributor

Please specify the area for this PR
registry library

What does does this PR do / why we need it:
This PR adds registry option NewIndexSchema, if specifies to true to get the v2index schema. (default to false)
also adds MaxSchemaVersion and MinSchemaVersion to filter the v2index with devfile schema version.

Also update the param stack in PullStackFromRegistry, to contains both name and version information for backward compatibility. Use colon to split, name:version. If no version is provided, pull the default version.
version=latest is also supported

update the root.go under cmd and tested with this change.

MacBook-Pro:registry-library stephanie$ ./registry-library pull https://registry.stage.devfile.io nodejs:2.1.0 --new-index-schema
Failed to pull nodejs:2.1.0 from registry https://registry.stage.devfile.io: the requested verion 2.1.0 for stack nodejs does not exist in the registry https://registry.stage.devfile.io
MacBook-Pro:registry-library stephanie$ ./registry-library pull https://registry.stage.devfile.io nodejs:1.0.1 --new-index-schema
MacBook-Pro:registry-library stephanie$ ./registry-library pull https://registry.stage.devfile.io python:latest --new-index-schema
MacBook-Pro:registry-library stephanie$ ./registry-library pull https://registry.stage.devfile.io python --new-index-schema

Which issue(s) this PR fixes:

Fixes devfile/api#763

PR acceptance criteria:

  • Test (WIP)

  • Documentation (WIP)

How to test changes / Special notes to the reviewer:

… filter

Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
@yangcao77 yangcao77 changed the title registry library api registry library api change for multi-version stack/sample support Mar 16, 2022
Signed-off-by: Stephanie <yangcao@redhat.com>
@@ -0,0 +1,50 @@
schemaVersion: 2.0.0
Copy link
Member

Choose a reason for hiding this comment

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

I think this was accidentally added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this should be deleted.

endpoint = endpoint + "minSchemaVersion=" + options.Filter.MinSchemaVersion + "&"
}
if options.Filter.MaxSchemaVersion != "" {
endpoint = endpoint + "maxSchemaVersion=" + options.Filter.MaxSchemaVersion + "&"
Copy link
Member

Choose a reason for hiding this comment

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

Is the "&" necessary on this line? Since we always just trim it afterwards?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since updated to use query.add() as suggested, this part has been removed as no need to manually build the query string using &

@@ -129,6 +145,16 @@ func GetRegistryIndex(registryURL string, options RegistryOptions, devfileTypes
endpoint = strings.TrimSuffix(endpoint, "&")
}

if options.NewIndexSchema && (options.Filter.MaxSchemaVersion != "" || options.Filter.MinSchemaVersion != "") {
if options.Filter.MinSchemaVersion != "" {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it would be better to add the query parameters like so:

req, err := http.NewRequest("GET", "<registry-url>", nil)
if err != nil {
    ...
}

q := req.URL.Query()
if options.Filter.MinSchemaVersion != "" {
    q.Add("minSchemaVersion", "options.Filter.MinSchemaVersion")
}
if options.Filter.MaxSchemaVersion != "" {
    q.Add("maxSchemaVersion", "options.Filter.MaxSchemaVersion")
}

req.URL.RawQuery = q.Encode()
...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Signed-off-by: Stephanie <yangcao@redhat.com>
@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Mar 24, 2022
@openshift-ci
Copy link

openshift-ci bot commented Mar 24, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: johnmcollier, yangcao77

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 24, 2022
@yangcao77 yangcao77 merged commit d57101e into devfile:main Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
2 participants