From ba7c822046627760b6dbacb715921197c68ef38e Mon Sep 17 00:00:00 2001 From: Karinna Iniguez Date: Fri, 21 Sep 2018 11:48:02 -0700 Subject: [PATCH] parent 29864922783a158e85686c364081090346f33a2a author Karinna Iniguez 1537555682 -0700 committer Karinna Iniguez 1537817451 -0700 Add Storage to cluster Addons and describe bool flag define StorageClass object Call CreateDefaultStorageClass from create cluster function Refactor error handling and update Readme with new flag Move storage class creation after nodes join Set storageclass flag to true by default Call CreateDefaultStorageClass from create cluster function Move storage class creation after nodes join Set storageclass flag to true by default --- README.md | 6 ++++++ cmd/eksctl/create.go | 8 ++++++++ pkg/eks/api/api.go | 1 + pkg/eks/storageclass.go | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 pkg/eks/storageclass.go diff --git a/README.md b/README.md index 39986f8be5..48c238be00 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,12 @@ To create the same kind of basic cluster, but with a different name, run: eksctl create cluster --name=cluster-1 --nodes=4 ``` +To prevent a default StorageClass of gp2 provisioned by EBS: + +``` +eksctl create cluster --storage-class=false +``` + To write cluster credentials to a file other than default, run: ``` diff --git a/cmd/eksctl/create.go b/cmd/eksctl/create.go index 855acf459b..0e3f50f037 100644 --- a/cmd/eksctl/create.go +++ b/cmd/eksctl/create.go @@ -91,6 +91,7 @@ func createClusterCmd() *cobra.Command { fs.DurationVar(&cfg.WaitTimeout, "timeout", api.DefaultWaitTimeout, "max wait time in any polling operations") fs.BoolVar(&cfg.Addons.WithIAM.PolicyAmazonEC2ContainerRegistryPowerUser, "full-ecr-access", false, "enable full access to ECR") + fs.BoolVar(&cfg.Addons.Storage, "storage-class", true, "if true then a default StorageClass of type gp2 provisioned by EBS will be created") fs.StringVar(&cfg.NodeAMI, "node-ami", ami.ResolverStatic, "Advanced use cases only. If 'static' is supplied (default) then eksctl will use static AMIs; if 'auto' is supplied then eksctl will automatically set the AMI based on region/instance type; if any other value is supplied it will override the AMI to use for the nodes. Use with extreme care.") @@ -198,6 +199,13 @@ func doCreateCluster(cfg *api.ClusterConfig, name string) error { return err } + // add default storage class + if cfg.Addons.Storage == true { + if err := ctl.AddDefaultStorageClass(clientSet); err != nil { + return err + } + } + // check kubectl version, and offer install instructions if missing or old // also check heptio-authenticator // TODO: https://github.com/weaveworks/eksctl/issues/30 diff --git a/pkg/eks/api/api.go b/pkg/eks/api/api.go index 844292998f..5871825306 100644 --- a/pkg/eks/api/api.go +++ b/pkg/eks/api/api.go @@ -70,6 +70,7 @@ type ClusterConfig struct { type ClusterAddons struct { WithIAM AddonIAM + Storage bool } type AddonIAM struct { diff --git a/pkg/eks/storageclass.go b/pkg/eks/storageclass.go new file mode 100644 index 0000000000..4811f7ad9f --- /dev/null +++ b/pkg/eks/storageclass.go @@ -0,0 +1,39 @@ +package eks + +import ( + "github.com/pkg/errors" + corev1 "k8s.io/api/core/v1" + storage "k8s.io/api/storage/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + clientset "k8s.io/client-go/kubernetes" +) + +func (c *ClusterProvider) AddDefaultStorageClass(clientSet *clientset.Clientset) error { + + rp := corev1.PersistentVolumeReclaimRetain + + scb := &storage.StorageClass{ + TypeMeta: metav1.TypeMeta{ + Kind: "StorageClass", + APIVersion: "storage.k8s.io/v1", + }, + Provisioner: "kubernetes.io/aws-ebs", + ObjectMeta: metav1.ObjectMeta{ + Name: "gp2", + Annotations: map[string]string{ + "storageclass.kubernetes.io/is-default-class": "true", + }, + }, + Parameters: map[string]string{ + "type": "gp2", + }, + ReclaimPolicy: &rp, + MountOptions: []string{"debug"}, + } + + if _, err := clientSet.StorageV1().StorageClasses().Create(scb); err != nil { + return errors.Wrap(err, "adding default StorageClass of gp2") + } + + return nil +}