/
create-config.go
73 lines (64 loc) · 1.98 KB
/
create-config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package eks
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"github.com/aws/aws-k8s-tester/eksconfig"
"github.com/aws/aws-k8s-tester/version"
"github.com/spf13/cobra"
)
func newCreateConfig() *cobra.Command {
return &cobra.Command{
Use: "config",
Short: "Writes an aws-k8s-tester eks configuration with default values",
Long: "Configuration values are overwritten by environment variables.",
Run: createConfigFunc,
}
}
func createConfigFunc(cmd *cobra.Command, args []string) {
if !autoPath && path == "" {
fmt.Fprintln(os.Stderr, "'--path' flag is not specified")
os.Exit(1)
}
cfg := eksconfig.NewDefault()
if autoPath {
path = filepath.Join(os.TempDir(), cfg.Name+".yaml")
}
cfg.ConfigPath = path
fmt.Printf("\n*********************************\n")
fmt.Printf("overwriting config file from environment variables with %s\n", version.Version())
err := cfg.UpdateFromEnvs()
if err != nil {
fmt.Fprintf(os.Stderr, "failed to load configuration from environment variables: %v", err)
os.Exit(1)
}
if err = cfg.ValidateAndSetDefaults(); err != nil {
fmt.Printf("\n*********************************\n")
fmt.Printf("'aws-k8s-tester eks create config --path %q' fail %v\n", path, err)
os.Exit(1)
}
txt, err := ioutil.ReadFile(path)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read configuration %q (%v)\n", path, err)
os.Exit(1)
}
fmt.Printf("\n\n%q:\n\n%s\n\n\n", path, string(txt))
if cfg.IsEnabledAddOnNodeGroups() {
body, err := json.MarshalIndent(cfg.AddOnNodeGroups, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("AddOnNodeGroups:\n\n%s\n\n\n", string(body))
}
if cfg.IsEnabledAddOnManagedNodeGroups() {
body, err := json.MarshalIndent(cfg.AddOnManagedNodeGroups, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("AddOnManagedNodeGroups:\n\n%s\n\n\n", string(body))
}
fmt.Printf("\n*********************************\n")
fmt.Printf("'aws-k8s-tester eks create config --path %q' success\n", path)
}