Skip to content

Commit

Permalink
changes filename, minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtuna committed Feb 7, 2018
1 parent 8fa04c2 commit 9232522
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 25 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 5 additions & 11 deletions cmd/chart-repo-sync/addRepo.go → cmd/chart-repo/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import (
"github.com/kubeapps/common/datastore"
)

var addRepoCmd = &cobra.Command{
Use: "add SUBCOMMAND",
Short: "add a new chart repository",
var syncCmd = &cobra.Command{
Use: "add [REPO NAME] [REPO URL]",
Short: "add a new chart repository, and resync the whole data",
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 2 {
logrus.Info("Need exactly two arguments: [REPO NAME] [REPO URL]")
cmd.Usage()
cmd.Help()
return
}

mongoURL, err := cmd.Flags().GetString("mongo-url")
Expand Down Expand Up @@ -66,10 +67,3 @@ var addRepoCmd = &cobra.Command{
logrus.Infof("Successfully added the chart repository %s to database", args[0])
},
}

func init() {
addRepoCmd.Flags().String("mongo-url", "localhost", "MongoDB URL (see https://godoc.org/labix.org/v2/mgo#Dial for format)")
addRepoCmd.Flags().String("mongo-database", "charts", "MongoDB database")
addRepoCmd.Flags().String("mongo-user", "", "MongoDB user")
addRepoCmd.Flags().Bool("debug", false, "verbose logging")
}
30 changes: 20 additions & 10 deletions cmd/chart-repo-sync/sync.go → cmd/chart-repo/chart_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,29 @@ import (
"github.com/spf13/cobra"
)

func newRootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "chartsvc",
Short: "Kubeapps Chart Repository utility",
}

cmd.AddCommand(addRepoCmd, deleteRepoCmd)
return cmd
var RootCmd = &cobra.Command{
Use: "chart-repo",
Short: "Kubeapps Chart Repository utility",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

func main() {
cmd := newRootCmd()
cmd := RootCmd
if err := cmd.Execute(); err != nil {
os.Exit(1)
}
}
}

func init() {
cmds := []*cobra.Command{syncCmd, deleteCmd}

for _, cmd := range cmds {
RootCmd.AddCommand(cmd)
cmd.Flags().String("mongo-url", "localhost", "MongoDB URL (see https://godoc.org/labix.org/v2/mgo#Dial for format)")
cmd.Flags().String("mongo-database", "charts", "MongoDB database")
cmd.Flags().String("mongo-user", "", "MongoDB user")
cmd.Flags().Bool("debug", false, "verbose logging")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
"github.com/spf13/cobra"
)

var deleteRepoCmd = &cobra.Command{
Use: "delete SUBCOMMAND",
Short: "delete a new chart repository",
var deleteCmd = &cobra.Command{
Use: "delete [REPO NAME]",
Short: "delete a chart repository",
Run: func(cmd *cobra.Command, args []string) {
cmd.Usage()
cmd.Help()
return
},
}
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions cmd/chart-repo-sync/utils.go → cmd/chart-repo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ func syncRepo(dbSession datastore.Session, repoName, repoURL string) error {
return nil
}

func deleteRepo(dbSession datastore.Session, repoName string) error {
err := removeCharts(dbSession, repoName)
if err != nil {
return err
}

return nil
}

func fetchRepoIndex(repoURL *url.URL) (*helmrepo.IndexFile, error) {
// use a copy of the URL struct so we don't modify the original
indexURL := *repoURL
Expand Down Expand Up @@ -221,6 +230,19 @@ func importCharts(dbSession datastore.Session, charts []chart) error {
return err
}

func removeCharts(dbSession datastore.Session, repoName string) error {
db, closer := dbSession.DB()
defer closer()
bulk := db.C(chartCollection).Bulk()

bulk.RemoveAll(bson.M{
"repo.name": repoName,
})

_, err := bulk.Run()
return err
}

func importWorker(dbSession datastore.Session, wg *sync.WaitGroup, icons <-chan chart, chartFiles <-chan importChartFilesJob) {
defer wg.Done()
for c := range icons {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 9232522

Please sign in to comment.