Skip to content

Commit

Permalink
Merge pull request #302 from weaveworks/improve-kops-subnet-importer
Browse files Browse the repository at this point in the history
Improve kops subnet importer
  • Loading branch information
errordeveloper authored Nov 5, 2018
2 parents 9714630 + 728f070 commit faa7fa2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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

0 comments on commit faa7fa2

Please sign in to comment.