Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: More VPC features #285

Closed
wants to merge 5 commits into from
Closed
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
7 changes: 4 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ required = [

[[constraint]]
name = "k8s.io/kops"
branch = "master"
source = "https://github.com/errordeveloper/kops"
revision = "b3ce6e69a332657fec9a31b3855c0f761f943803"

# copied from https://github.com/kubernetes/kops/blob/master/Gopkg.toml
[[override]]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ eksctl delete cluster --name=<name> [--region=<region>]

### Scaling nodegroup

The default nodegroup can be scaled by using the `eksctl scale nodegroup` command. For example, to scale to 5 nodes:
The initial nodegroup can be scaled by using the `eksctl scale nodegroup` command. For example, to scale to 5 nodes:

```
eksctl scale nodegroup --name=<name> --nodes=5
Expand Down
3 changes: 0 additions & 3 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import (

"github.com/weaveworks/eksctl/pkg/eks/api"
"github.com/weaveworks/eksctl/pkg/testutils"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

const (
Expand Down
7 changes: 7 additions & 0 deletions pkg/cfn/builder/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ const (
templateDescriptionSuffix = " [created and managed by eksctl]"
)

type awsCloudFormationResource struct {
Type string
Properties map[string]interface{}
UpdatePolicy map[string]map[string]string `json:",omitempty"`
DependsOn []string `json:",omitempty"`
}

// ResourceSet is an interface which cluster and nodegroup builders
// must implement
type ResourceSet interface {
Expand Down
157 changes: 117 additions & 40 deletions pkg/cfn/builder/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package builder_test
import (
"encoding/base64"
"encoding/json"
"net"
"path/filepath"
"strings"

Expand All @@ -12,6 +13,7 @@ import (
. "github.com/onsi/gomega"
. "github.com/weaveworks/eksctl/pkg/cfn/builder"
"github.com/weaveworks/eksctl/pkg/cloudconfig"
"github.com/weaveworks/eksctl/pkg/eks"
"github.com/weaveworks/eksctl/pkg/eks/api"
"github.com/weaveworks/eksctl/pkg/nodebootstrap"
)
Expand Down Expand Up @@ -90,33 +92,112 @@ var _ = Describe("CloudFormation template builder API", func() {

testAZs := []string{"us-west-2b", "us-west-2a", "us-west-2c"}

newClusterConfig := func() *api.ClusterConfig {
cfg := api.NewClusterConfig()
ng := cfg.NewNodeGroup()

cfg.Region = "us-west-2"
cfg.ClusterName = clusterName
cfg.AvailabilityZones = testAZs
ng.InstanceType = "t2.medium"

*cfg.VPC.CIDR = api.DefaultCIDR()

return cfg
}

Describe("GetAllOutputsFromClusterStack", func() {
caCertData, err := base64.StdEncoding.DecodeString(caCert)
It("should not error", func() { Expect(err).ShouldNot(HaveOccurred()) })

expected := &api.ClusterConfig{
Region: "us-west-2",
ClusterName: clusterName,
SecurityGroup: "sg-0b44c48bcba5b7362",
Subnets: []string{"subnet-0f98135715dfcf55f", "subnet-0ade11bad78dced9e", "subnet-0e2e63ff1712bf6ef"},
VPC: "vpc-0e265ad953062b94b",
Endpoint: endpoint,
CertificateAuthorityData: caCertData,
ARN: arn,
NodeInstanceRoleARN: "",
AvailabilityZones: testAZs,
}

initial := &api.ClusterConfig{
ClusterName: clusterName,
AvailabilityZones: testAZs,
VPC: api.ClusterVPC{
Network: api.Network{
ID: "vpc-0e265ad953062b94b",
CIDR: &net.IPNet{
IP: []byte{192, 168, 0, 0},
Mask: []byte{255, 255, 0, 0},
},
},
SecurityGroup: "sg-0b44c48bcba5b7362",
Subnets: map[api.SubnetTopology]map[string]api.Network{
"Public": map[string]api.Network{
"us-west-2b": {
//ID: "subnet-0f98135715dfcf55f",
CIDR: &net.IPNet{
IP: []byte{192, 168, 0, 0},
Mask: []byte{255, 255, 224, 0},
},
},
"us-west-2a": {
//ID: "subnet-0ade11bad78dced9e",
CIDR: &net.IPNet{
IP: []byte{192, 168, 32, 0},
Mask: []byte{255, 255, 224, 0},
},
},
"us-west-2c": {
//ID: "subnet-0e2e63ff1712bf6ef",
CIDR: &net.IPNet{
IP: []byte{192, 168, 64, 0},
Mask: []byte{255, 255, 224, 0},
},
},
},
"Private": map[string]api.Network{
"us-west-2b": {
//ID: "subnet-0f98135715dfcf55f",
CIDR: &net.IPNet{
IP: []byte{192, 168, 96, 0},
Mask: []byte{255, 255, 224, 0},
},
},
"us-west-2a": {
//ID: "subnet-0ade11bad78dced9e",
CIDR: &net.IPNet{
IP: []byte{192, 168, 128, 0},
Mask: []byte{255, 255, 224, 0},
},
},
"us-west-2c": {
//ID: "subnet-0e2e63ff1712bf6ef",
CIDR: &net.IPNet{
IP: []byte{192, 168, 160, 0},
Mask: []byte{255, 255, 224, 0},
},
},
},
},
},
NodeGroups: []*api.NodeGroup{
{
AMI: "",
InstanceType: "t2.medium",
SubnetTopology: "Public",
},
},
}

initial := newClusterConfig()
ctl := eks.New(initial)
It("should not error when calling SetSubnets", func() {
err := ctl.SetSubnets()
Expect(err).ShouldNot(HaveOccurred())
})

rs := NewClusterResourceSet(initial)
rs.AddAllResources()

sampleStack := newStackWithOutputs(map[string]string{
"SecurityGroup": "sg-0b44c48bcba5b7362",
"Subnets": "subnet-0f98135715dfcf55f,subnet-0ade11bad78dced9e,subnet-0e2e63ff1712bf6ef",
"SubnetsPublic": "subnet-0f98135715dfcf55f,subnet-0ade11bad78dced9e,subnet-0e2e63ff1712bf6ef",
"VPC": "vpc-0e265ad953062b94b",
"Endpoint": endpoint,
"CertificateAuthorityData": caCert,
Expand All @@ -130,17 +211,14 @@ var _ = Describe("CloudFormation template builder API", func() {
})

It("should be equal", func() {
Expect(initial).To(Equal(expected))
Expect(*initial).To(Equal(*expected))
})
})

Describe("AutoNameTag", func() {
rs := NewNodeGroupResourceSet(&api.ClusterConfig{
ClusterName: clusterName,
AvailabilityZones: testAZs,
NodeType: "t2.medium",
Region: "us-west-2",
}, "eksctl-test-123-cluster", 0)
cfg := newClusterConfig()

rs := NewNodeGroupResourceSet(cfg, "eksctl-test-123-cluster", 0)

err := rs.AddAllResources()
It("should add all resources without errors", func() {
Expand Down Expand Up @@ -179,12 +257,15 @@ var _ = Describe("CloudFormation template builder API", func() {
})

Describe("NodeGroupTags", func() {
rs := NewNodeGroupResourceSet(&api.ClusterConfig{
ClusterName: clusterName,
AvailabilityZones: testAZs,
NodeType: "t2.medium",
Region: "us-west-2",
}, "eksctl-test-123-cluster", 0)
cfg := api.NewClusterConfig()
ng := cfg.NewNodeGroup()

cfg.Region = "us-west-2"
cfg.ClusterName = clusterName
cfg.AvailabilityZones = testAZs
ng.InstanceType = "t2.medium"

rs := NewNodeGroupResourceSet(cfg, "eksctl-test-123-cluster", 0)
rs.AddAllResources()

template, err := rs.RenderJSON()
Expand All @@ -210,17 +291,15 @@ var _ = Describe("CloudFormation template builder API", func() {
})

Describe("NodeGroupAutoScaling", func() {
rs := NewNodeGroupResourceSet(&api.ClusterConfig{
ClusterName: clusterName,
AvailabilityZones: testAZs,
NodeType: "t2.medium",
Region: "us-west-2",
Addons: api.ClusterAddons{
WithIAM: api.AddonIAM{
PolicyAutoScaling: true,
},
cfg := newClusterConfig()

cfg.Addons = api.ClusterAddons{
WithIAM: api.AddonIAM{
PolicyAutoScaling: true,
},
}, "eksctl-test-123-cluster", 0)
}

rs := NewNodeGroupResourceSet(cfg, "eksctl-test-123-cluster", 0)
rs.AddAllResources()

template, err := rs.RenderJSON()
Expand Down Expand Up @@ -251,20 +330,18 @@ var _ = Describe("CloudFormation template builder API", func() {
})

Describe("UserData", func() {
cfg := newClusterConfig()

var c *cloudconfig.CloudConfig

caCertData, err := base64.StdEncoding.DecodeString(caCert)
It("should not error", func() { Expect(err).ShouldNot(HaveOccurred()) })

rs := NewNodeGroupResourceSet(&api.ClusterConfig{
ClusterName: clusterName,
AvailabilityZones: testAZs,
NodeType: "m5.large",
Region: "us-west-2",
Endpoint: endpoint,
CertificateAuthorityData: caCertData,
}, "eksctl-test-123-cluster", 0)
cfg.Endpoint = endpoint
cfg.CertificateAuthorityData = caCertData
cfg.NodeGroups[0].InstanceType = "m5.large"

rs := NewNodeGroupResourceSet(cfg, "eksctl-test-123-cluster", 0)
rs.AddAllResources()

template, err := rs.RenderJSON()
Expand Down
Loading