argo-cd
67 строк · 1.4 Кб
1package util
2
3import (
4"gopkg.in/yaml.v2"
5"os"
6)
7
8type SourceOpts struct {
9Strategy string `yaml:"strategy"`
10}
11
12type DestinationOpts struct {
13Strategy string `yaml:"strategy"`
14}
15
16type ApplicationOpts struct {
17Samples int `yaml:"samples"`
18SourceOpts SourceOpts `yaml:"source"`
19DestinationOpts DestinationOpts `yaml:"destination"`
20}
21
22type RepositoryOpts struct {
23Samples int `yaml:"samples"`
24}
25
26type ProjectOpts struct {
27Samples int `yaml:"samples"`
28}
29
30type ClusterOpts struct {
31Samples int `yaml:"samples"`
32NamespacePrefix string `yaml:"namespacePrefix"`
33ValuesFilePath string `yaml:"valuesFilePath"`
34DestinationNamespace string `yaml:"destinationNamespace"`
35ClusterNamePrefix string `yaml:"clusterNamePrefix"`
36Concurrency int `yaml:"parallel"`
37}
38
39type GenerateOpts struct {
40ApplicationOpts ApplicationOpts `yaml:"application"`
41ClusterOpts ClusterOpts `yaml:"cluster"`
42RepositoryOpts RepositoryOpts `yaml:"repository"`
43ProjectOpts ProjectOpts `yaml:"project"`
44GithubToken string
45Namespace string `yaml:"namespace"`
46}
47
48func setDefaults(opts *GenerateOpts) {
49if opts.ClusterOpts.Concurrency == 0 {
50opts.ClusterOpts.Concurrency = 2
51}
52}
53
54func Parse(opts *GenerateOpts, file string) error {
55fp, err := os.ReadFile(file)
56if err != nil {
57return err
58}
59
60if e := yaml.Unmarshal(fp, &opts); e != nil {
61return e
62}
63
64setDefaults(opts)
65
66return nil
67}
68