Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Support for deploying to existing VPC #346

Merged
merged 3 commits into from
Apr 4, 2016
Merged

Conversation

colhom
Copy link
Contributor

@colhom colhom commented Mar 23, 2016

I've added some validation as well so folks don't waste time creating clusters and tracking down subnet conflicts in the cloudformation events logs when the create fails.

@pieterlange
Copy link

Nice work! Making a separate VPC for each k8s cluster would be a real pain :)

@four43
Copy link

four43 commented Mar 23, 2016

Hey thanks! This is great!

@colhom
Copy link
Contributor Author

colhom commented Mar 24, 2016

\cc @aaronlevy


//Find out if stack exists already. This determines whether we should do subnet conflict validatio
var stackExists bool
stackNotExistExpr := regexp.MustCompile(fmt.Sprintf("^ValidationError: Stack with id %s does not exist", c.ClusterName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to be really fragile. There has to be a better way to determine if a stack exist.

What about just len(describeStackOutput.Stacks) > 0 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DescribeStacks returns an Validation error if there are no stacks that have the given name. The regex is the only way I've found to differentiate that error from other stuff (can't contact API, invalid creds, etc)

The other option is to use ListStacks and loop through all the stacks checking for that stack name.

@colhom
Copy link
Contributor Author

colhom commented Mar 31, 2016

@aaronlevy review items addressed.


//Find out if stack exists already. This determines whether we should do subnet conflict validation
var stackExists bool
stackNotExistExpr := regexp.MustCompile(fmt.Sprintf("^ValidationError: Stack with id %s does not exist", c.ClusterName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we care at all if the stack exists? Couldn't a VPC exist outside of a cloud-formation stack (and this would skip validation code).

DescribeSubnets(*ec2.DescribeSubnetsInput) (*ec2.DescribeSubnetsOutput, error)
}

func (c *Cluster) validateExistingVPCState(ec2Svc ec2Service) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit test which utilizes this dummy interface is in the next commit

@@ -5,7 +5,7 @@ import (
"testing"
)

const MinimalConfigYaml = `externalDNSName: test-external-dns-name
const minimalConfigYaml = `externalDNSName: test-external-dns-name
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not useful to expose this, so took the liberty of cleaning it up

@colhom
Copy link
Contributor Author

colhom commented Apr 1, 2016

@aaronlevy ready for review

if err != nil {
return fmt.Errorf("invalid podCIDR: %v", err)
}
if vpcNet.Contains(podNetIP) {
if vpcNet.Contains(podNet.IP) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, will nix this block

@aaronlevy
Copy link
Contributor

Couple minor comments, but otherwise lgtm

In the case of an existing VPC, validates that the new subnet will not conflict with any existing subnets in that VPC
@colhom colhom merged commit 52c51de into coreos:master Apr 4, 2016
@colhom colhom deleted the existing-vpc branch April 4, 2016 17:57
return fmt.Errorf("could not find vpc %s in region %s", c.VPCID, c.Region)
}
if len(vpcOutput.Vpcs) > 1 {
//Theoretically this should never happen. If it does, we probably want to know.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this an invariant we can trust to amazon.

@rothgar
Copy link

rothgar commented Apr 7, 2016

How is this supposed to be used/configured in cluster.yaml? I'm assuming I'll need to build from git but don't see documentation in the repo.

@colhom colhom mentioned this pull request Apr 8, 2016
18 tasks
@pieterlange
Copy link

@rothgar
This should do it:

vpcId: vpc-xxx
routeTableId: rtb-xxxxxx

hjacobs added a commit to zalando-incubator/kubernetes-on-aws that referenced this pull request Oct 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants