Skip to content

Commit

Permalink
parent 2986492
Browse files Browse the repository at this point in the history
author Karinna Iniguez <kngz@amazon.com> 1537555682 -0700
committer Karinna Iniguez <kngz@amazon.com> 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
  • Loading branch information
karinnainiguez committed Sep 24, 2018
1 parent 2986492 commit ba7c822
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

```
Expand Down
8 changes: 8 additions & 0 deletions cmd/eksctl/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/eks/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type ClusterConfig struct {

type ClusterAddons struct {
WithIAM AddonIAM
Storage bool
}

type AddonIAM struct {
Expand Down
39 changes: 39 additions & 0 deletions pkg/eks/storageclass.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ba7c822

Please sign in to comment.