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

Improve kops subnet importer #302

Merged
merged 1 commit into from
Nov 5, 2018
Merged
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
10 changes: 10 additions & 0 deletions pkg/eks/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ func NewClusterConfig() *ClusterConfig {
return cfg
}

// AppendAvailabilityZone appends a new AZ to the set
func (c *ClusterConfig) AppendAvailabilityZone(newAZ string) {
for _, az := range c.AvailabilityZones {
if az == newAZ {
return
}
}
c.AvailabilityZones = append(c.AvailabilityZones, newAZ)
}

// IsSupportedRegion check if given region is supported
func (c *ClusterConfig) IsSupportedRegion() bool {
for _, supportedRegion := range SupportedRegions() {
Expand Down
15 changes: 12 additions & 3 deletions pkg/kops/kops.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ func (k *Wrapper) isOwned(t *ec2.Tag) bool {
return *t.Key == "kubernetes.io/cluster/"+k.clusterName && *t.Value == "owned"
}

func (k *Wrapper) topologyOf(s *ec2.Subnet) api.SubnetTopology {
for _, t := range s.Tags {
if *t.Key == "SubnetType" && *t.Value == "Private" {
return api.SubnetTopologyPrivate
}
}
return api.SubnetTopologyPublic // "Utility", "Public" or unspecified
}

// UseVPC finds VPC and subnets that give kops cluster uses and add those to EKS cluster config
func (k *Wrapper) UseVPC(spec *api.ClusterConfig) error {
allVPCs, err := aws.ListVPCs(k.cloud, k.clusterName)
Expand Down Expand Up @@ -60,9 +69,9 @@ func (k *Wrapper) UseVPC(spec *api.ClusterConfig) error {
for _, subnet := range allSubnets {
subnet := subnet.Obj.(*ec2.Subnet)
for _, tag := range subnet.Tags {
if k.isOwned(tag) && *subnet.VpcId == vpcs[0] {
spec.ImportSubnet(api.SubnetTopologyPublic, *subnet.AvailabilityZone, *subnet.SubnetId)
spec.AvailabilityZones = append(spec.AvailabilityZones, *subnet.AvailabilityZone)
if k.isOwned(tag) && *subnet.VpcId == spec.VPC.ID {
spec.ImportSubnet(k.topologyOf(subnet), *subnet.AvailabilityZone, *subnet.SubnetId)
spec.AppendAvailabilityZone(*subnet.AvailabilityZone)
}
}
}
Expand Down