Skip to content

Commit

Permalink
check all existing index
Browse files Browse the repository at this point in the history
Signed-off-by: ye.sijun <junnplus@gmail.com>
  • Loading branch information
junnplus committed Dec 30, 2021
1 parent b015efb commit 7d34838
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/krew/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"sigs.k8s.io/krew/cmd/krew/cmd/internal"
"sigs.k8s.io/krew/internal/environment"
"sigs.k8s.io/krew/internal/gitutil"
"sigs.k8s.io/krew/internal/index/indexoperations"
"sigs.k8s.io/krew/internal/indexmigration"
"sigs.k8s.io/krew/internal/installation"
"sigs.k8s.io/krew/internal/installation/receipt"
Expand Down Expand Up @@ -209,10 +210,17 @@ func cleanupStaleKrewInstallations() error {
}

func checkIndex(_ *cobra.Command, _ []string) error {
if ok, err := gitutil.IsGitCloned(paths.IndexPath(constants.DefaultIndexName)); err != nil {
return errors.Wrap(err, "failed to check local index git repository")
} else if !ok {
return errors.New(`krew local plugin index is not initialized (run "kubectl krew update")`)
indexes, err := indexoperations.ListIndexes(paths)
if err != nil {
return errors.Wrap(err, "failed to list indexes")
}
for _, idx := range indexes {
indexPath := paths.IndexPath(idx.Name)
if ok, err := gitutil.IsGitCloned(indexPath); err != nil {
return errors.Wrap(err, "failed to check local index git repository")
} else if !ok {
return errors.New(`krew local plugin index is not initialized (run "kubectl krew update")`)
}
}
return nil
}
Expand Down

0 comments on commit 7d34838

Please sign in to comment.