From fa9b4ac217d139ac846cde6e04372ff65ad13abb Mon Sep 17 00:00:00 2001 From: Ciprian Hacman Date: Fri, 19 Jun 2020 21:54:54 +0300 Subject: [PATCH 1/2] Add master and node image options when creating a cluster --- cmd/kops/create_cluster.go | 24 +++++++++++++++++++----- docs/cli/kops_create_cluster.md | 8 +++++--- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cmd/kops/create_cluster.go b/cmd/kops/create_cluster.go index 99c06072e37a3..f556038036d15 100644 --- a/cmd/kops/create_cluster.go +++ b/cmd/kops/create_cluster.go @@ -84,6 +84,8 @@ type CreateClusterOptions struct { ContainerRuntime string OutDir string Image string + NodeImage string + MasterImage string VPCID string SubnetIDs []string UtilitySubnetIDs []string @@ -299,8 +301,14 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command { cmd.Flags().StringVar(&sshPublicKey, "ssh-public-key", sshPublicKey, "SSH public key to use (defaults to ~/.ssh/id_rsa.pub on AWS)") - cmd.Flags().StringVar(&options.NodeSize, "node-size", options.NodeSize, "Set instance size for nodes") + cmd.Flags().Int32Var(&options.MasterCount, "master-count", options.MasterCount, "Set number of masters. Defaults to one master per master-zone") + cmd.Flags().Int32Var(&options.NodeCount, "node-count", options.NodeCount, "Set number of nodes") + + cmd.Flags().StringVar(&options.Image, "image", options.Image, "Set image for all instances.") + cmd.Flags().StringVar(&options.NodeImage, "node-image", options.NodeImage, "Set image for nodes") + cmd.Flags().StringVar(&options.MasterImage, "master-image", options.MasterImage, "Set image for masters") + cmd.Flags().StringVar(&options.NodeSize, "node-size", options.NodeSize, "Set instance size for nodes") cmd.Flags().StringVar(&options.MasterSize, "master-size", options.MasterSize, "Set instance size for masters") cmd.Flags().Int32Var(&options.MasterVolumeSize, "master-volume-size", options.MasterVolumeSize, "Set instance volume size (in GB) for masters") @@ -312,13 +320,9 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command { cmd.Flags().StringVar(&options.NetworkCIDR, "network-cidr", options.NetworkCIDR, "Set to override the default network CIDR") cmd.Flags().BoolVar(&options.DisableSubnetTags, "disable-subnet-tags", options.DisableSubnetTags, "Set to disable automatic subnet tagging") - cmd.Flags().Int32Var(&options.MasterCount, "master-count", options.MasterCount, "Set the number of masters. Defaults to one master per master-zone") - cmd.Flags().Int32Var(&options.NodeCount, "node-count", options.NodeCount, "Set the number of nodes") cmd.Flags().BoolVar(&options.EncryptEtcdStorage, "encrypt-etcd-storage", options.EncryptEtcdStorage, "Generate key in aws kms and use it for encrypt etcd volumes") cmd.Flags().StringVar(&options.EtcdStorageType, "etcd-storage-type", options.EtcdStorageType, "The default storage type for etc members") - cmd.Flags().StringVar(&options.Image, "image", options.Image, "Image to use for all instances.") - cmd.Flags().StringVar(&options.Networking, "networking", options.Networking, "Networking mode to use. kubenet, external, weave, flannel-vxlan (or flannel), flannel-udp, calico, canal, kube-router, amazon-vpc-routed-eni, cilium, cni, lyftvpc.") cmd.Flags().StringVar(&options.DNSZone, "dns-zone", options.DNSZone, "DNS hosted zone to use (defaults to longest matching zone)") @@ -852,6 +856,16 @@ func RunCreateCluster(ctx context.Context, f *util.Factory, out io.Writer, c *Cr group.Spec.Image = c.Image } } + if c.MasterImage != "" { + for _, group := range masters { + group.Spec.Image = c.MasterImage + } + } + if c.NodeImage != "" { + for _, group := range nodes { + group.Spec.Image = c.NodeImage + } + } if c.AssociatePublicIP != nil { for _, group := range instanceGroups { diff --git a/docs/cli/kops_create_cluster.md b/docs/cli/kops_create_cluster.md index d5c2e39511b95..cc4899dd6c6cc 100644 --- a/docs/cli/kops_create_cluster.md +++ b/docs/cli/kops_create_cluster.md @@ -83,9 +83,10 @@ kops create cluster [flags] --etcd-storage-type string The default storage type for etc members --gce-service-account string Service account with which the GCE VM runs. Warning: if not set, VMs will run as default compute service account. -h, --help help for cluster - --image string Image to use for all instances. + --image string Set image for all instances. --kubernetes-version string Version of kubernetes to run (defaults to version in channel) - --master-count int32 Set the number of masters. Defaults to one master per master-zone + --master-count int32 Set number of masters. Defaults to one master per master-zone + --master-image string Set image for masters --master-public-name string Sets the public master public name --master-security-groups strings Add precreated additional security groups to masters. --master-size string Set instance size for masters @@ -95,7 +96,8 @@ kops create cluster [flags] --model string Models to apply (separate multiple models with commas) (default "proto,cloudup") --network-cidr string Set to override the default network CIDR --networking string Networking mode to use. kubenet, external, weave, flannel-vxlan (or flannel), flannel-udp, calico, canal, kube-router, amazon-vpc-routed-eni, cilium, cni, lyftvpc. (default "kubenet") - --node-count int32 Set the number of nodes + --node-count int32 Set number of nodes + --node-image string Set image for nodes --node-security-groups strings Add precreated additional security groups to nodes. --node-size string Set instance size for nodes --node-tenancy string The tenancy of the node group on AWS. Can be either default or dedicated. From 279fd313ec4e77db01fbe9a6286ea84b2111280b Mon Sep 17 00:00:00 2001 From: Ciprian Hacman Date: Sat, 20 Jun 2020 19:17:19 +0300 Subject: [PATCH 2/2] Address review comments Co-authored-by: Peter Rifel --- cmd/kops/create_cluster.go | 4 ++-- docs/cli/kops_create_cluster.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/kops/create_cluster.go b/cmd/kops/create_cluster.go index f556038036d15..7ec597966d80d 100644 --- a/cmd/kops/create_cluster.go +++ b/cmd/kops/create_cluster.go @@ -305,8 +305,8 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command { cmd.Flags().Int32Var(&options.NodeCount, "node-count", options.NodeCount, "Set number of nodes") cmd.Flags().StringVar(&options.Image, "image", options.Image, "Set image for all instances.") - cmd.Flags().StringVar(&options.NodeImage, "node-image", options.NodeImage, "Set image for nodes") - cmd.Flags().StringVar(&options.MasterImage, "master-image", options.MasterImage, "Set image for masters") + cmd.Flags().StringVar(&options.NodeImage, "node-image", options.NodeImage, "Set image for nodes. Takes precedence over --image") + cmd.Flags().StringVar(&options.MasterImage, "master-image", options.MasterImage, "Set image for masters. Takes precedence over --image") cmd.Flags().StringVar(&options.NodeSize, "node-size", options.NodeSize, "Set instance size for nodes") cmd.Flags().StringVar(&options.MasterSize, "master-size", options.MasterSize, "Set instance size for masters") diff --git a/docs/cli/kops_create_cluster.md b/docs/cli/kops_create_cluster.md index cc4899dd6c6cc..db8335bfa8098 100644 --- a/docs/cli/kops_create_cluster.md +++ b/docs/cli/kops_create_cluster.md @@ -86,7 +86,7 @@ kops create cluster [flags] --image string Set image for all instances. --kubernetes-version string Version of kubernetes to run (defaults to version in channel) --master-count int32 Set number of masters. Defaults to one master per master-zone - --master-image string Set image for masters + --master-image string Set image for masters. Takes precedence over --image --master-public-name string Sets the public master public name --master-security-groups strings Add precreated additional security groups to masters. --master-size string Set instance size for masters @@ -97,7 +97,7 @@ kops create cluster [flags] --network-cidr string Set to override the default network CIDR --networking string Networking mode to use. kubenet, external, weave, flannel-vxlan (or flannel), flannel-udp, calico, canal, kube-router, amazon-vpc-routed-eni, cilium, cni, lyftvpc. (default "kubenet") --node-count int32 Set number of nodes - --node-image string Set image for nodes + --node-image string Set image for nodes. Takes precedence over --image --node-security-groups strings Add precreated additional security groups to nodes. --node-size string Set instance size for nodes --node-tenancy string The tenancy of the node group on AWS. Can be either default or dedicated.