mirror of https://github.com/kubernetes/kops.git
Reorg rolling-update cluster command
This commit is contained in:
parent
17afbd6292
commit
08b7420fda
|
|
@ -18,21 +18,19 @@ package main
|
|||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"k8s.io/kops/cmd/kops/util"
|
||||
)
|
||||
|
||||
// rollingupdateCmd represents the rollingupdate command
|
||||
type RollingUpdateCmd struct {
|
||||
cobraCommand *cobra.Command
|
||||
}
|
||||
|
||||
var rollingUpdateCommand = RollingUpdateCmd{
|
||||
cobraCommand: &cobra.Command{
|
||||
func NewCmdRollingUpdate(f *util.Factory, out io.Writer) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "rolling-update",
|
||||
Short: "rolling update clusters",
|
||||
Long: `rolling update clusters`,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCommand.AddCommand(rollingUpdateCommand.cobraCommand)
|
||||
// create subcommands
|
||||
cmd.AddCommand(NewCmdRollingUpdateCluster(f, out))
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ package main
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
"k8s.io/kops/cmd/kops/util"
|
||||
api "k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup"
|
||||
"k8s.io/kops/upup/pkg/kutil"
|
||||
|
|
@ -32,7 +34,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type RollingUpdateClusterCmd struct {
|
||||
type RollingUpdateOptions struct {
|
||||
Yes bool
|
||||
Force bool
|
||||
CloudOnly bool
|
||||
|
|
@ -41,49 +43,66 @@ type RollingUpdateClusterCmd struct {
|
|||
NodeInterval time.Duration
|
||||
BastionInterval time.Duration
|
||||
|
||||
cobraCommand *cobra.Command
|
||||
ClusterName string
|
||||
}
|
||||
|
||||
var rollingupdateCluster = RollingUpdateClusterCmd{
|
||||
cobraCommand: &cobra.Command{
|
||||
func (o *RollingUpdateOptions) InitDefaults() {
|
||||
o.Yes = false
|
||||
o.Force = false
|
||||
o.CloudOnly = false
|
||||
|
||||
o.MasterInterval = 5 * time.Minute
|
||||
o.NodeInterval = 2 * time.Minute
|
||||
o.BastionInterval = 5 * time.Minute
|
||||
}
|
||||
|
||||
func NewCmdRollingUpdateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
||||
var options RollingUpdateOptions
|
||||
options.InitDefaults()
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "cluster",
|
||||
Short: "rolling-update cluster",
|
||||
Long: `rolling-updates a k8s cluster.`,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
cmd := rollingupdateCluster.cobraCommand
|
||||
rollingUpdateCommand.cobraCommand.AddCommand(cmd)
|
||||
cmd.Flags().BoolVar(&options.Yes, "yes", options.Yes, "perform rolling update without confirmation")
|
||||
cmd.Flags().BoolVar(&options.Force, "force", options.Force, "Force rolling update, even if no changes")
|
||||
cmd.Flags().BoolVar(&options.CloudOnly, "cloudonly", options.CloudOnly, "Perform rolling update without confirming progress with k8s")
|
||||
|
||||
cmd.Flags().BoolVar(&rollingupdateCluster.Yes, "yes", false, "perform rolling update without confirmation")
|
||||
cmd.Flags().BoolVar(&rollingupdateCluster.Force, "force", false, "Force rolling update, even if no changes")
|
||||
cmd.Flags().BoolVar(&rollingupdateCluster.CloudOnly, "cloudonly", false, "Perform rolling update without confirming progress with k8s")
|
||||
|
||||
cmd.Flags().DurationVar(&rollingupdateCluster.MasterInterval, "master-interval", 5*time.Minute, "Time to wait between restarting masters")
|
||||
cmd.Flags().DurationVar(&rollingupdateCluster.NodeInterval, "node-interval", 2*time.Minute, "Time to wait between restarting nodes")
|
||||
cmd.Flags().DurationVar(&rollingupdateCluster.BastionInterval, "bastion-interval", 5*time.Minute, "Time to wait between restarting bastions")
|
||||
cmd.Flags().DurationVar(&options.MasterInterval, "master-interval", options.MasterInterval, "Time to wait between restarting masters")
|
||||
cmd.Flags().DurationVar(&options.NodeInterval, "node-interval", options.NodeInterval, "Time to wait between restarting nodes")
|
||||
cmd.Flags().DurationVar(&options.BastionInterval, "bastion-interval", options.BastionInterval, "Time to wait between restarting bastions")
|
||||
|
||||
cmd.Run = func(cmd *cobra.Command, args []string) {
|
||||
err := rollingupdateCluster.Run(args)
|
||||
err := rootCommand.ProcessArgs(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clusterName := rootCommand.ClusterName()
|
||||
if clusterName == "" {
|
||||
return nil, fmt.Errorf("--name is required")
|
||||
}
|
||||
|
||||
options.ClusterName = clusterName
|
||||
|
||||
err = RunRollingUpdateCluster(&rootCommand, os.Stdout, options)
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *RollingUpdateClusterCmd) Run(args []string) error {
|
||||
err := rootCommand.ProcessArgs(args)
|
||||
func RunRollingUpdateCluster(f *util.Factory, out io.Writer, options *RollingUpdateOptions) error {
|
||||
clientset, err := f.Clientset()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cluster, err := rootCommand.Cluster()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientset, err := rootCommand.Clientset()
|
||||
cluster, err := GetCluster(f, options.ClusterName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -98,7 +117,7 @@ func (c *RollingUpdateClusterCmd) Run(args []string) error {
|
|||
|
||||
var nodes []v1.Node
|
||||
var k8sClient *k8s_clientset.Clientset
|
||||
if !c.CloudOnly {
|
||||
if !options.CloudOnly {
|
||||
k8sClient, err = k8s_clientset.NewForConfig(config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot build kube client for %q: %v", contextName, err)
|
||||
|
|
@ -131,9 +150,9 @@ func (c *RollingUpdateClusterCmd) Run(args []string) error {
|
|||
}
|
||||
|
||||
d := &kutil.RollingUpdateCluster{
|
||||
MasterInterval: c.MasterInterval,
|
||||
NodeInterval: c.NodeInterval,
|
||||
Force: c.Force,
|
||||
MasterInterval: options.MasterInterval,
|
||||
NodeInterval: options.NodeInterval,
|
||||
Force: options.Force,
|
||||
}
|
||||
d.Cloud = cloud
|
||||
|
||||
|
|
@ -183,10 +202,10 @@ func (c *RollingUpdateClusterCmd) Run(args []string) error {
|
|||
}
|
||||
|
||||
columns := []string{"NAME", "STATUS", "NEEDUPDATE", "READY", "MIN", "MAX"}
|
||||
if !c.CloudOnly {
|
||||
if !options.CloudOnly {
|
||||
columns = append(columns, "NODES")
|
||||
}
|
||||
err := t.Render(l, os.Stdout, columns...)
|
||||
err := t.Render(l, out, columns...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -199,12 +218,12 @@ func (c *RollingUpdateClusterCmd) Run(args []string) error {
|
|||
}
|
||||
}
|
||||
|
||||
if !needUpdate && !c.Force {
|
||||
if !needUpdate && !options.Force {
|
||||
fmt.Printf("\nNo rolling-update required\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
if !c.Yes {
|
||||
if !options.Yes {
|
||||
fmt.Printf("\nMust specify --yes to rolling-update\n")
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ func NewCmdRoot(f *util.Factory, out io.Writer) *cobra.Command {
|
|||
cmd.AddCommand(NewCmdEdit(f, out))
|
||||
cmd.AddCommand(NewCmdUpdate(f, out))
|
||||
cmd.AddCommand(NewCmdReplace(f, out))
|
||||
cmd.AddCommand(NewCmdRollingUpdate(f, out))
|
||||
cmd.AddCommand(NewCmdToolbox(f, out))
|
||||
cmd.AddCommand(NewCmdValidate(f, out))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue