mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
SKip the empty resource/base item in a kustomization file and set the
defaultBranch if needed
This commit is contained in:
@@ -97,6 +97,17 @@ func (gc githubCrawler) Crawl(
|
|||||||
// it will try to add each string in konfig.RecognizedKustomizationFileNames() to
|
// it will try to add each string in konfig.RecognizedKustomizationFileNames() to
|
||||||
// d.FilePath, and try to fetch the document again.
|
// 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 {
|
||||||
|
// set the default branch if it is empty
|
||||||
|
if d.DefaultBranch == "" {
|
||||||
|
url := gc.client.ReposRequest(d.RepositoryFullName())
|
||||||
|
defaultBranch, err := gc.client.GetDefaultBranch(url)
|
||||||
|
if err != nil {
|
||||||
|
logger.Printf(
|
||||||
|
"(error: %v) setting default_branch to master\n", err)
|
||||||
|
defaultBranch = "master"
|
||||||
|
}
|
||||||
|
d.DefaultBranch = defaultBranch
|
||||||
|
}
|
||||||
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)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ func (doc *KustomizationDocument) GetResources() ([]*Document, error) {
|
|||||||
|
|
||||||
res := make([]*Document, 0, len(k.Resources))
|
res := make([]*Document, 0, len(k.Resources))
|
||||||
for _, r := range k.Resources {
|
for _, r := range k.Resources {
|
||||||
|
if strings.TrimSpace(r) == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
next, err := doc.Document.FromRelativePath(r)
|
next, err := doc.Document.FromRelativePath(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("GetResources error: %v\n", err)
|
fmt.Printf("GetResources error: %v\n", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user