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

Add kube-aws node-pools update command #130

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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