forked from coreos/coreos-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_validate.go
67 lines (56 loc) · 1.44 KB
/
command_validate.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
package main
import (
"fmt"
"os"
"github.com/coreos/coreos-kubernetes/multi-node/aws/pkg/cluster"
"github.com/coreos/coreos-kubernetes/multi-node/aws/pkg/config"
"github.com/spf13/cobra"
)
var (
cmdValidate = &cobra.Command{
Use: "validate",
Short: "Validate cluster assets",
Long: ``,
RunE: runCmdValidate,
SilenceUsage: true,
}
validateOpts = struct {
awsDebug bool
}{}
)
func init() {
cmdRoot.AddCommand(cmdValidate)
cmdValidate.Flags().BoolVar(
&validateOpts.awsDebug,
"aws-debug",
false,
"Log debug information from aws-sdk-go library",
)
}
func runCmdValidate(cmd *cobra.Command, args []string) error {
cfg, err := config.ClusterFromFile(configPath)
if err != nil {
return fmt.Errorf("Unable to load cluster config: %v", err)
}
fmt.Printf("Validating UserData...\n")
if err := cfg.ValidateUserData(stackTemplateOptions); err != nil {
return err
}
fmt.Printf("UserData is valid.\n\n")
fmt.Printf("Validating stack template...\n")
data, err := cfg.RenderStackTemplate(stackTemplateOptions)
if err != nil {
return fmt.Errorf("Failed to render stack template: %v", err)
}
cluster := cluster.New(cfg, validateOpts.awsDebug)
report, err := cluster.ValidateStack(string(data))
if report != "" {
fmt.Fprintf(os.Stderr, "Validation Report: %s\n", report)
}
if err != nil {
return err
}
fmt.Printf("stack template is valid.\n\n")
fmt.Printf("Validation OK!\n")
return nil
}