github.com/argoproj/argo-cd@v1.8.7/util/app/discovery/discovery.go (about)

     1  package discovery
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"strings"
     7  
     8  	"github.com/argoproj/argo-cd/util/kustomize"
     9  )
    10  
    11  func Discover(root string) (map[string]string, error) {
    12  	apps := make(map[string]string)
    13  	err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
    14  		if err != nil {
    15  			return err
    16  		}
    17  		if info.IsDir() {
    18  			return nil
    19  		}
    20  		dir, err := filepath.Rel(root, filepath.Dir(path))
    21  		if err != nil {
    22  			return err
    23  		}
    24  		base := filepath.Base(path)
    25  		if base == "params.libsonnet" && strings.HasSuffix(dir, "components") {
    26  			apps[filepath.Dir(dir)] = "Ksonnet"
    27  		}
    28  		if strings.HasSuffix(base, "Chart.yaml") {
    29  			apps[dir] = "Helm"
    30  		}
    31  		if kustomize.IsKustomization(base) {
    32  			apps[dir] = "Kustomize"
    33  		}
    34  		return nil
    35  	})
    36  	return apps, err
    37  }
    38  
    39  func AppType(path string) (string, error) {
    40  	apps, err := Discover(path)
    41  	if err != nil {
    42  		return "", err
    43  	}
    44  	appType, ok := apps["."]
    45  	if ok {
    46  		return appType, nil
    47  	}
    48  	return "Directory", nil
    49  }