mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Avoid to index a document if FetchDcoument or SetCreated fails
This commit is contained in:
@@ -72,17 +72,17 @@ func addBranches(cdoc CrawledDocument, match Crawler, indx IndexFunc,
|
|||||||
seen[cdoc.ID()] = struct{}{}
|
seen[cdoc.ID()] = struct{}{}
|
||||||
|
|
||||||
// Insert into index
|
// Insert into index
|
||||||
err := indx(cdoc, match)
|
if err := indx(cdoc, match); err != nil {
|
||||||
logIfErr(err)
|
logger.Println("Failed to index: ", err)
|
||||||
if err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
deps, err := cdoc.GetResources()
|
deps, err := cdoc.GetResources()
|
||||||
logIfErr(err)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dep := range deps {
|
for _, dep := range deps {
|
||||||
if _, ok := seen[dep.ID()]; ok {
|
if _, ok := seen[dep.ID()]; ok {
|
||||||
continue
|
continue
|
||||||
@@ -107,29 +107,33 @@ func doCrawl(ctx context.Context, docsPtr *CrawlSeed, crawlers []Crawler, conv C
|
|||||||
}
|
}
|
||||||
docCount++
|
docCount++
|
||||||
|
|
||||||
|
if tail.WasCached() {
|
||||||
|
logger.Printf("%s %s is cached already", tail.RepositoryURL, tail.FilePath)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
match := findMatch(tail, crawlers)
|
match := findMatch(tail, crawlers)
|
||||||
if match == nil {
|
if match == nil {
|
||||||
logIfErr(fmt.Errorf(
|
logIfErr(fmt.Errorf("%v could not match any crawler", tail))
|
||||||
"%v could not match any crawler", tail))
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Println("Crawling ", tail.RepositoryURL, tail.FilePath)
|
logger.Println("Crawling ", tail.RepositoryURL, tail.FilePath)
|
||||||
err := match.FetchDocument(ctx, tail)
|
if err := match.FetchDocument(ctx, tail); err != nil {
|
||||||
logIfErr(err)
|
logger.Printf("FetchDocument failed on %s %s: %v",
|
||||||
// If there was no change or there is an error, we don't have
|
tail.RepositoryURL, tail.FilePath, err)
|
||||||
// to branch out, since the dependencies are already in the
|
|
||||||
// index, or we cannot find the document.
|
|
||||||
if err != nil || tail.WasCached() {
|
|
||||||
if tail.WasCached() {
|
|
||||||
logger.Println(tail.RepositoryURL, tail.FilePath, "is cached already")
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
logIfErr(match.SetCreated(ctx, tail))
|
if err := match.SetCreated(ctx, tail); err != nil {
|
||||||
|
logger.Printf("SetCreated failed on %s %s: %v",
|
||||||
|
tail.RepositoryURL, tail.FilePath, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
cdoc, err := conv(tail)
|
cdoc, err := conv(tail)
|
||||||
|
// If conv returns an error, cdoc can still be added into the index so that
|
||||||
|
// cdoc.Document can be searched.
|
||||||
logIfErr(err)
|
logIfErr(err)
|
||||||
|
|
||||||
addBranches(cdoc, match, indx, seen, stack)
|
addBranches(cdoc, match, indx, seen, stack)
|
||||||
|
|||||||
@@ -93,6 +93,9 @@ func (gc githubCrawler) Crawl(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FetchDocument first tries to fetch the document with d.FilePath. If it fails,
|
||||||
|
// it will try to add each string in konfig.RecognizedKustomizationFileNames() to
|
||||||
|
// d.FilePath, and try to fetch the document again.
|
||||||
func (gc githubCrawler) FetchDocument(_ context.Context, d *doc.Document) error {
|
func (gc githubCrawler) FetchDocument(_ context.Context, d *doc.Document) error {
|
||||||
repoURL := d.RepositoryURL + "/" + d.FilePath + "?ref=" + d.DefaultBranch
|
repoURL := d.RepositoryURL + "/" + d.FilePath + "?ref=" + d.DefaultBranch
|
||||||
repoSpec, err := git.NewRepoSpecFromUrl(repoURL)
|
repoSpec, err := git.NewRepoSpecFromUrl(repoURL)
|
||||||
|
|||||||
@@ -116,6 +116,8 @@ func (doc *KustomizationDocument) readBytes() ([]map[string]interface{}, error)
|
|||||||
return configs, nil
|
return configs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ParseYAML parses doc.Document and sets the following fields of doc:
|
||||||
|
// Kinds, Values, Identifiers.
|
||||||
func (doc *KustomizationDocument) ParseYAML() error {
|
func (doc *KustomizationDocument) ParseYAML() error {
|
||||||
doc.Identifiers = make([]string, 0)
|
doc.Identifiers = make([]string, 0)
|
||||||
doc.Values = make([]string, 0)
|
doc.Values = make([]string, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user