First pass at create_cluster_integration_test for specifying NGWs.

This commit is contained in:
Eric Hole 2017-01-09 17:28:10 -05:00
parent bcaf929256
commit f5b3425d3d
8 changed files with 234 additions and 2 deletions

View File

@ -67,6 +67,9 @@ type CreateClusterOptions struct {
// Enable/Disable Bastion Host complete setup
Bastion bool
NgwIds string
NgwEips string
}
func (o *CreateClusterOptions) InitDefaults() {
@ -503,6 +506,32 @@ func RunCreateCluster(f *util.Factory, out io.Writer, c *CreateClusterOptions) e
return fmt.Errorf("Invalid topology %s.", c.Topology)
}
// NAT Gateway/ElasticIP
if c.NgwIds != "" {
ngwEipList := make([]string, 0)
// Perhaps abstract parseZoneList into something more general
// But it works for processing comma-delimited strings for now
for _, ngwEip := range parseZoneList(c.NgwEips) {
ngwEipList = append(ngwEipList, ngwEip)
}
ngwIdList := make([]string, 0)
for _, ngwId := range parseZoneList(c.NgwIds) {
ngwIdList = append(ngwIdList, ngwId)
}
gatewayIndex := 0
for i := range cluster.Spec.Subnets {
subnet := &cluster.Spec.Subnets[i]
if subnet.Type == api.SubnetTypePrivate {
subnet.NgwId = ngwIdList[gatewayIndex]
subnet.NgwEip = ngwEipList[gatewayIndex]
gatewayIndex++
}
// fmt.Printf("This is cluster.Spec.Subnets %+v\n", subnet)
}
}
sshPublicKeys := make(map[string][]byte)
if c.SSHPublicKey != "" {
c.SSHPublicKey = utils.ExpandPath(c.SSHPublicKey)

View File

@ -18,6 +18,7 @@ package main
import (
"bytes"
"fmt"
"github.com/golang/glog"
"io/ioutil"
"k8s.io/kops/cmd/kops/util"
@ -51,6 +52,12 @@ func TestCreateClusterPrivate(t *testing.T) {
runCreateClusterIntegrationTest(t, "../../tests/integration/create_cluster/private", "v1alpha2")
}
// TestCreateClusterPrivate runs kops create cluster private.example.com --zones us-test-1a --master-zones us-test-1a
func TestCreateClusterWithNGWSpecified(t *testing.T) {
runCreateClusterIntegrationTest(t, "../../tests/integration/create_cluster/ngwspecified", "v1alpha1")
runCreateClusterIntegrationTest(t, "../../tests/integration/create_cluster/ngwspecified", "v1alpha2")
}
func runCreateClusterIntegrationTest(t *testing.T, srcDir string, version string) {
var stdout bytes.Buffer

View File

@ -318,9 +318,11 @@ type ClusterSubnetSpec struct {
// ProviderID is the cloud provider id for the objects associated with the zone (the subnet on AWS)
ProviderID string `json:"subnetId,omitempty"`
NgwId string `json:"ngwId,omitempty"`
NgwEip string `json:"ngwEip,omitempty"`
EgressIP string `json:"egressIP,omitempty"`
// TODO: ACTIVATE EGRESSIP AND WRITE THE LOGIC TO ALLOW SMARTER AND BROADER SPECING OF EXISTING COMPONENTS
// EgressIP string `json:"egressIP,omitempty"`
Type SubnetType `json:"type,omitempty"`
}

View File

@ -46,6 +46,7 @@ func ParseInstanceGroupRole(input string, lenient bool) (InstanceGroupRole, bool
// ParseRawYaml parses an object just using yaml, without the full api machinery
// Deprecated: prefer using the API machinery
func ParseRawYaml(data []byte, dest interface{}) error {
// Yaml can't parse empty strings
configString := string(data)
configString = strings.TrimSpace(configString)

View File

@ -227,8 +227,11 @@ type ClusterSubnetSpec struct {
// TODO Change ProviderID -> SubnetId
ProviderID string `json:"subnetId,omitempty"`
NgwId string `json:"ngwId,omitempty"`
NgwEip string `json:"ngwEip,omitempty"`
EgressIP string `json:"egressIP,omitempty"`
// TODO: ACTIVATE EGRESSIP AND WRITE THE LOGIC TO ALLOW SMARTER AND BROADER SPECING OF EXISTING COMPONENTS
// EgressIP string `json:"egressIP,omitempty"`
Type SubnetType `json:"type,omitempty"`
}

View File

@ -0,0 +1,88 @@
apiVersion: kops/v1alpha1
kind: Cluster
metadata:
creationTimestamp: "2017-01-01T00:00:00Z"
name: private.example.com
spec:
api:
loadBalancer:
type: Public
channel: stable
cloudProvider: aws
configBase: memfs://tests/private.example.com
etcdClusters:
- etcdMembers:
- name: us-test-1a
zone: us-test-1a
name: main
- etcdMembers:
- name: us-test-1a
zone: us-test-1a
name: events
kubernetesVersion: v1.4.7
masterPublicName: api.private.example.com
networkCIDR: 172.20.0.0/16
networking:
kopeio: {}
nonMasqueradeCIDR: 100.64.0.0/10
topology:
bastion:
enable: true
name: bastion-private.example.com
masters: private
nodes: private
zones:
- cidr: 172.20.0.0/22
name: us-test-1a
privateCIDR: 172.20.32.0/19
---
apiVersion: kops/v1alpha1
kind: InstanceGroup
metadata:
creationTimestamp: "2017-01-01T00:00:00Z"
name: bastions
spec:
associatePublicIp: true
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
machineType: t2.micro
maxSize: 1
minSize: 1
role: Bastion
zones:
- utility-us-test-1a
---
apiVersion: kops/v1alpha1
kind: InstanceGroup
metadata:
creationTimestamp: "2017-01-01T00:00:00Z"
name: master-us-test-1a
spec:
associatePublicIp: true
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
machineType: m3.medium
maxSize: 1
minSize: 1
role: Master
zones:
- us-test-1a
---
apiVersion: kops/v1alpha1
kind: InstanceGroup
metadata:
creationTimestamp: "2017-01-01T00:00:00Z"
name: nodes
spec:
associatePublicIp: true
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
machineType: t2.medium
maxSize: 2
minSize: 2
role: Node
zones:
- us-test-1a

View File

@ -0,0 +1,94 @@
apiVersion: kops/v1alpha2
kind: Cluster
metadata:
creationTimestamp: "2017-01-01T00:00:00Z"
name: private.example.com
spec:
api:
loadBalancer:
type: Public
channel: stable
cloudProvider: aws
configBase: memfs://tests/private.example.com
etcdClusters:
- etcdMembers:
- instanceGroup: master-us-test-1a
name: us-test-1a
name: main
- etcdMembers:
- instanceGroup: master-us-test-1a
name: us-test-1a
name: events
kubernetesVersion: v1.4.7
masterPublicName: api.private.example.com
networkCIDR: 172.20.0.0/16
networking:
kopeio: {}
nonMasqueradeCIDR: 100.64.0.0/10
subnets:
- cidr: 172.20.32.0/19
name: us-test-1a
ngwEip: eipalloc-e12345
ngwId: nat-09123456
type: Private
zone: us-test-1a
- cidr: 172.20.0.0/22
name: utility-us-test-1a
type: Utility
zone: us-test-1a
topology:
bastion:
bastionPublicName: bastion-private.example.com
masters: private
nodes: private
---
apiVersion: kops/v1alpha2
kind: InstanceGroup
metadata:
creationTimestamp: "2017-01-01T00:00:00Z"
name: bastions
spec:
associatePublicIp: true
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
machineType: t2.micro
maxSize: 1
minSize: 1
role: Bastion
subnets:
- utility-us-test-1a
---
apiVersion: kops/v1alpha2
kind: InstanceGroup
metadata:
creationTimestamp: "2017-01-01T00:00:00Z"
name: master-us-test-1a
spec:
associatePublicIp: true
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
machineType: m3.medium
maxSize: 1
minSize: 1
role: Master
subnets:
- us-test-1a
---
apiVersion: kops/v1alpha2
kind: InstanceGroup
metadata:
creationTimestamp: "2017-01-01T00:00:00Z"
name: nodes
spec:
associatePublicIp: true
image: kope.io/k8s-1.4-debian-jessie-amd64-hvm-ebs-2016-10-21
machineType: t2.medium
maxSize: 2
minSize: 2
role: Node
subnets:
- us-test-1a

View File

@ -0,0 +1,8 @@
ClusterName: private.example.com
Zones: us-test-1a
Cloud: aws
Topology: private
Networking: kopeio-vxlan
Bastion: true
NgwEips: eipalloc-e12345
NgwIds: nat-09123456