This repository has been archived by the owner on Sep 30, 2020. It is now read-only.
/
update.go
69 lines (56 loc) · 1.89 KB
/
update.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
package cmd
import (
"fmt"
"github.com/kubernetes-incubator/kube-aws/core/root"
"github.com/spf13/cobra"
)
var (
cmdUpdate = &cobra.Command{
Use: "update",
Short: "Update an existing Kubernetes cluster",
Long: ``,
RunE: runCmdUpdate,
SilenceUsage: true,
}
updateOpts = struct {
awsDebug, prettyPrint, skipWait bool
s3URI string
}{}
)
func init() {
RootCmd.AddCommand(cmdUpdate)
cmdUpdate.Flags().BoolVar(&updateOpts.awsDebug, "aws-debug", false, "Log debug information from aws-sdk-go library")
cmdUpdate.Flags().BoolVar(&updateOpts.prettyPrint, "pretty-print", false, "Pretty print the resulting CloudFormation")
cmdUpdate.Flags().StringVar(&updateOpts.s3URI, "s3-uri", "", "When your template is bigger than the cloudformation limit of 51200 bytes, upload the template to the specified location in S3. S3 location expressed as s3://<bucket>/path/to/dir")
cmdUpdate.Flags().BoolVar(&updateOpts.skipWait, "skip-wait", false, "Don't wait the resources finish")
}
func runCmdUpdate(cmd *cobra.Command, args []string) error {
if err := validateRequired(flag{"--s3-uri", updateOpts.s3URI}); err != nil {
return err
}
opts := root.NewOptions(updateOpts.s3URI, updateOpts.prettyPrint, updateOpts.skipWait)
cluster, err := root.ClusterFromFile(configPath, opts, updateOpts.awsDebug)
if err != nil {
return fmt.Errorf("Failed to read cluster config: %v", err)
}
if _, err := cluster.ValidateStack(); err != nil {
return err
}
report, err := cluster.Update()
if err != nil {
return fmt.Errorf("Error updating cluster: %v", err)
}
if report != "" {
fmt.Printf("Update stack: %s\n", report)
}
info, err := cluster.Info()
if err != nil {
return fmt.Errorf("Failed fetching cluster info: %v", err)
}
successMsg :=
`Success! Your AWS resources are being updated:
%s
`
fmt.Printf(successMsg, info.String())
return nil
}