argo-cd

Форк
0
/
gen_options_parser.go 
67 строк · 1.4 Кб
1
package util
2

3
import (
4
	"gopkg.in/yaml.v2"
5
	"os"
6
)
7

8
type SourceOpts struct {
9
	Strategy string `yaml:"strategy"`
10
}
11

12
type DestinationOpts struct {
13
	Strategy string `yaml:"strategy"`
14
}
15

16
type ApplicationOpts struct {
17
	Samples         int             `yaml:"samples"`
18
	SourceOpts      SourceOpts      `yaml:"source"`
19
	DestinationOpts DestinationOpts `yaml:"destination"`
20
}
21

22
type RepositoryOpts struct {
23
	Samples int `yaml:"samples"`
24
}
25

26
type ProjectOpts struct {
27
	Samples int `yaml:"samples"`
28
}
29

30
type ClusterOpts struct {
31
	Samples              int    `yaml:"samples"`
32
	NamespacePrefix      string `yaml:"namespacePrefix"`
33
	ValuesFilePath       string `yaml:"valuesFilePath"`
34
	DestinationNamespace string `yaml:"destinationNamespace"`
35
	ClusterNamePrefix    string `yaml:"clusterNamePrefix"`
36
	Concurrency          int    `yaml:"parallel"`
37
}
38

39
type GenerateOpts struct {
40
	ApplicationOpts ApplicationOpts `yaml:"application"`
41
	ClusterOpts     ClusterOpts     `yaml:"cluster"`
42
	RepositoryOpts  RepositoryOpts  `yaml:"repository"`
43
	ProjectOpts     ProjectOpts     `yaml:"project"`
44
	GithubToken     string
45
	Namespace       string `yaml:"namespace"`
46
}
47

48
func setDefaults(opts *GenerateOpts) {
49
	if opts.ClusterOpts.Concurrency == 0 {
50
		opts.ClusterOpts.Concurrency = 2
51
	}
52
}
53

54
func Parse(opts *GenerateOpts, file string) error {
55
	fp, err := os.ReadFile(file)
56
	if err != nil {
57
		return err
58
	}
59

60
	if e := yaml.Unmarshal(fp, &opts); e != nil {
61
		return e
62
	}
63

64
	setDefaults(opts)
65

66
	return nil
67
}
68

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.