-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from hypnoglow/reindex-command
Implement reindex command
- Loading branch information
Showing
11 changed files
with
445 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/hypnoglow/helm-s3/pkg/awss3" | ||
"github.com/hypnoglow/helm-s3/pkg/helmutil" | ||
"github.com/hypnoglow/helm-s3/pkg/index" | ||
) | ||
|
||
const ( | ||
reindexCommandDefaultTimeout = time.Second * 15 | ||
) | ||
|
||
func runReindex(repoName string) error { | ||
// Just one big timeout for the whole operation. | ||
ctx, cancel := context.WithTimeout(context.Background(), reindexCommandDefaultTimeout) | ||
defer cancel() | ||
|
||
repoEntry, err := helmutil.LookupRepoEntry(repoName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
storage := awss3.New() | ||
|
||
items, errs := storage.Traverse(ctx, repoEntry.URL) | ||
|
||
builtIndex := make(chan *index.Index, 1) | ||
go func() { | ||
idx := index.New() | ||
for item := range items { | ||
idx.Add(item.Meta, item.Filename, repoEntry.URL, item.Hash) | ||
} | ||
idx.SortEntries() | ||
|
||
builtIndex <- idx | ||
}() | ||
|
||
for err = range errs { | ||
return errors.Wrap(err, "traverse the chart repository") | ||
} | ||
|
||
idx := <-builtIndex | ||
|
||
r, err := idx.Reader() | ||
if err != nil { | ||
return errors.Wrap(err, "get index reader") | ||
} | ||
|
||
if err := storage.PutIndex(ctx, repoEntry.URL, r); err != nil { | ||
return errors.Wrap(err, "upload index to the repository") | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.