-
Notifications
You must be signed in to change notification settings - Fork 104
Providing Repo Include Feature #1479
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
455d5ce
ca5addf
7e3484b
536c879
8637e6e
2335f22
7a0537d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
|
|
||
| "github.com/spf13/afero" | ||
|
|
||
| "github.com/kudobuilder/kudo/pkg/kudoctl/clog" | ||
| "github.com/kudobuilder/kudo/pkg/kudoctl/http" | ||
| "github.com/kudobuilder/kudo/pkg/kudoctl/kudohome" | ||
| ) | ||
|
|
@@ -50,20 +51,28 @@ func NewClient(conf *Configuration) (*Client, error) { | |
|
|
||
| // DownloadIndexFile fetches the index file from a repository. | ||
| func (c *Client) DownloadIndexFile() (*IndexFile, error) { | ||
| var indexURL string | ||
| parsedURL, err := url.Parse(c.Config.URL) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("parsing config url: %w", err) | ||
| } | ||
| parsedURL.Path = fmt.Sprintf("%s/index.yaml", strings.TrimSuffix(parsedURL.Path, "/")) | ||
|
|
||
| indexURL = parsedURL.String() | ||
| return c.downloadIndexFile(nil, parsedURL) | ||
| } | ||
|
|
||
| func (c *Client) downloadIndexFile(parent *IndexFile, url *url.URL) (*IndexFile, error) { | ||
| var resp *bytes.Buffer | ||
| if strings.HasPrefix(indexURL, "file:") { | ||
| b, _ := ioutil.ReadFile(parsedURL.Path) | ||
| var err error | ||
| // we need the index.yaml at the url provided | ||
| url.Path = fmt.Sprintf("%s/index.yaml", strings.TrimSuffix(url.Path, "/")) | ||
|
|
||
| if url.Scheme == "file" || strings.HasPrefix(url.String(), "file:") { | ||
| b, err := ioutil.ReadFile(url.Path) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| resp = bytes.NewBuffer(b) | ||
| } else { | ||
| resp, err = c.Client.Get(indexURL) | ||
| resp, err = c.Client.Get(url.String()) | ||
| } | ||
| if err != nil { | ||
| return nil, fmt.Errorf("getting index url: %w", err) | ||
|
|
@@ -75,5 +84,39 @@ func (c *Client) DownloadIndexFile() (*IndexFile, error) { | |
| } | ||
|
|
||
| indexFile, err := ParseIndexFile(indexBytes) | ||
| //TODO (kensipe): err handling such that error in includes are ignored (but not root) | ||
| //TODO (kensipe): track which includes have happened so there are no repeats | ||
| for _, include := range indexFile.Includes { | ||
| iURL, err := url.Parse(include) | ||
| if err != nil { | ||
| clog.Printf("Unable to parse include url for %s", include) | ||
| } | ||
| nextIndex, err := c.downloadIndexFile(indexFile, iURL) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if parent != nil { | ||
| c.Merge(parent, nextIndex) | ||
| } else { | ||
| c.Merge(indexFile, nextIndex) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this block works incorrectly for nested includes. Assuming we have three repos that have nested includes: AA includes BB, BB includes CC. The final index should contain BB.X, if I understand correctly. With this code, we would:
Either we:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IF AA -> BB and BB -> CC and BB and CC have X I would expect:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the case where in your example would be true if AA included BB and CC |
||
| } | ||
|
|
||
| return indexFile, err | ||
| } | ||
|
|
||
| // Merge combines the Entries of 2 index files. The first index file is the master | ||
| // the second is merged into the first. Any duplicates are ignored. | ||
| func (c *Client) Merge(index *IndexFile, mergeIndex *IndexFile) { | ||
| // index is the master, any dups in the merged in index will have what is local replace those entries | ||
| for _, pvs := range mergeIndex.Entries { | ||
| for _, pv := range pvs { | ||
| err := index.AddPackageVersion(pv) | ||
| // this is most likely to be a duplicate pv, which we ignore (but will log at the right v) | ||
| if err != nil { | ||
| // todo: add verbose logging here | ||
| continue | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| apiVersion: v1 | ||
| entries: | ||
| flink: | ||
| - appVersion: 0.7.0 | ||
| description: correct flink | ||
| digest: 0787a078e64c73064287751b833d63ca3d1d284b4f494ebf670443683d5b96dd | ||
| maintainers: | ||
| - email: <runyontr@gmail.com> | ||
| name: Tom Runyon | ||
| - email: <kensipe@gmail.com> | ||
| name: Ken Sipe | ||
| name: flink | ||
| operatorVersion: 0.3.0 | ||
| urls: | ||
| - http://kudo.dev/flink | ||
| includes: | ||
| - ../included-repo | ||
| generated: "2020-04-19T15:04:00Z" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| apiVersion: v1 | ||
| entries: | ||
| mysql: | ||
| - appVersion: "5.7" | ||
| digest: ad2451eaf68896490a2864afbb3fcd81e6fe3368e4bf001f8a23dc9cbcddf49a | ||
| maintainers: | ||
| - email: nick@dischord.org | ||
| name: Nick Jones | ||
| name: mysql | ||
| operatorVersion: 0.2.0 | ||
| urls: | ||
| - https://kudo-repository.storage.googleapis.com/0.10.0/mysql-5.7_0.2.0.tgz | ||
| flink: | ||
| - appVersion: 0.7.0 | ||
| description: wrong flink (should NOT be included) | ||
| digest: 0787a078e64c73064287751b833d63ca3d1d284b4f494ebf670443683d5b96dd | ||
| maintainers: | ||
| - email: <runyontr@gmail.com> | ||
| name: Tom Runyon | ||
| - email: <kensipe@gmail.com> | ||
| name: Ken Sipe | ||
| name: flink | ||
| operatorVersion: 0.3.0 | ||
| - appVersion: 0.8.0 | ||
| description: this merges because the version doesn't exist in parent | ||
| digest: 0787a078e64c73064287751b833d63ca3d1d284b4f494ebf670443683d5b96dd | ||
| maintainers: | ||
| - email: <runyontr@gmail.com> | ||
| name: Tom Runyon | ||
| - email: <kensipe@gmail.com> | ||
| name: Ken Sipe | ||
| name: flink | ||
| operatorVersion: 0.4.0 | ||
| urls: | ||
| - http://kudo.dev/flink | ||
|
|
||
| generated: "2020-04-19T15:04:00Z" | ||
|
|
||
|
|
Uh oh!
There was an error while loading. Please reload this page.