Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #130 from mumoshu/kube-aws-node-pools-update
Browse files Browse the repository at this point in the history
Add `kube-aws node-pools update` command
  • Loading branch information
mumoshu authored Dec 7, 2016
2 parents ab6495a + 9476ee7 commit bd33d1f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
69 changes: 69 additions & 0 deletions cmd/nodepool/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package nodepool

import (
"fmt"

"github.com/coreos/kube-aws/nodepool/cluster"
"github.com/coreos/kube-aws/nodepool/config"
"github.com/spf13/cobra"
)

var (
cmdUpdate = &cobra.Command{
Use: "update",
Short: "Update an existing node pool",
Long: ``,
RunE: runCmdUpdate,
SilenceUsage: true,
}

updateOpts = struct {
awsDebug bool
s3URI string
}{}
)

func init() {
NodePoolCmd.AddCommand(cmdUpdate)
cmdUpdate.Flags().BoolVar(&updateOpts.awsDebug, "aws-debug", false, "Log debug information from aws-sdk-go library")
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")
}

func runCmdUpdate(cmd *cobra.Command, args []string) error {
conf, err := config.ClusterFromFile(nodePoolClusterConfigFilePath())
if err != nil {
return fmt.Errorf("Failed to read node pool config: %v", err)
}

if err := conf.ValidateUserData(stackTemplateOptions()); err != nil {
return fmt.Errorf("Failed to validate user data: %v", err)
}

data, err := conf.RenderStackTemplate(stackTemplateOptions())
if err != nil {
return fmt.Errorf("Failed to render stack template: %v", err)
}

cluster := cluster.New(conf, updateOpts.awsDebug)

report, err := cluster.Update(string(data), updateOpts.s3URI)
if err != nil {
return fmt.Errorf("Error updating node pool: %v", err)
}
if report != "" {
fmt.Printf("Update stack: %s\n", report)
}

info, err := cluster.Info()
if err != nil {
return fmt.Errorf("Failed fetching node pool info: %v", err)
}

successMsg :=
`Success! Your AWS resources are being updated:
%s
`
fmt.Printf(successMsg, info.String())

return nil
}
9 changes: 9 additions & 0 deletions nodepool/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ func (c *Cluster) Create(stackBody string, s3URI string) error {
return c.stackProvisioner().CreateStackAndWait(cfSvc, s3Svc, stackBody, s3URI)
}

func (c *Cluster) Update(stackBody string, s3URI string) (string, error) {
cfSvc := cloudformation.New(c.session)
s3Svc := s3.New(c.session)

updateOutput, err := c.stackProvisioner().UpdateStackAndWait(cfSvc, s3Svc, stackBody, s3URI)

return updateOutput, err
}

func (c *Cluster) ValidateStack(stackBody string, s3URI string) (string, error) {
return c.stackProvisioner().Validate(stackBody, s3URI)
}
Expand Down

0 comments on commit bd33d1f

Please sign in to comment.