mirror of https://github.com/kubernetes/kops.git
AWS: Move some subnet functions into AWS model
We want to move all these eventually, and this is preparing for better GCE subnet support.
This commit is contained in:
parent
9eb28b93fe
commit
99764fb168
|
|
@ -17,10 +17,66 @@ limitations under the License.
|
|||
package awsmodel
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/kops/pkg/apis/kops"
|
||||
"k8s.io/kops/pkg/model"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/awstasks"
|
||||
)
|
||||
|
||||
// AWSModelContext provides the context for the aws model
|
||||
type AWSModelContext struct {
|
||||
*model.KopsModelContext
|
||||
}
|
||||
|
||||
func (b *AWSModelContext) LinkToSubnet(z *kops.ClusterSubnetSpec) *awstasks.Subnet {
|
||||
name := z.Name + "." + b.ClusterName()
|
||||
|
||||
return &awstasks.Subnet{Name: &name}
|
||||
}
|
||||
|
||||
func (b *AWSModelContext) LinkToPublicSubnetInZone(zoneName string) (*awstasks.Subnet, error) {
|
||||
var matches []*kops.ClusterSubnetSpec
|
||||
for i := range b.Cluster.Spec.Subnets {
|
||||
z := &b.Cluster.Spec.Subnets[i]
|
||||
if z.Zone != zoneName {
|
||||
continue
|
||||
}
|
||||
if z.Type != kops.SubnetTypePublic {
|
||||
continue
|
||||
}
|
||||
matches = append(matches, z)
|
||||
}
|
||||
if len(matches) == 0 {
|
||||
return nil, fmt.Errorf("could not find public subnet in zone: %q", zoneName)
|
||||
}
|
||||
if len(matches) > 1 {
|
||||
// TODO: Support this (arbitrary choice I think, for ELBs)
|
||||
return nil, fmt.Errorf("found multiple public subnets in zone: %q", zoneName)
|
||||
}
|
||||
|
||||
return b.LinkToSubnet(matches[0]), nil
|
||||
}
|
||||
|
||||
func (b *AWSModelContext) LinkToUtilitySubnetInZone(zoneName string) (*awstasks.Subnet, error) {
|
||||
var matches []*kops.ClusterSubnetSpec
|
||||
for i := range b.Cluster.Spec.Subnets {
|
||||
s := &b.Cluster.Spec.Subnets[i]
|
||||
if s.Zone != zoneName {
|
||||
continue
|
||||
}
|
||||
if s.Type != kops.SubnetTypeUtility {
|
||||
continue
|
||||
}
|
||||
matches = append(matches, s)
|
||||
}
|
||||
if len(matches) == 0 {
|
||||
return nil, fmt.Errorf("could not find utility subnet in zone: %q", zoneName)
|
||||
}
|
||||
if len(matches) > 1 {
|
||||
// TODO: Support this
|
||||
return nil, fmt.Errorf("found multiple utility subnets in zone: %q", zoneName)
|
||||
}
|
||||
|
||||
return b.LinkToSubnet(matches[0]), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,58 +206,6 @@ func (b *KopsModelContext) LinkToSSHKey() (*awstasks.SSHKey, error) {
|
|||
return &awstasks.SSHKey{Name: &sshKeyName}, nil
|
||||
}
|
||||
|
||||
func (b *KopsModelContext) LinkToSubnet(z *kops.ClusterSubnetSpec) *awstasks.Subnet {
|
||||
name := z.Name + "." + b.ClusterName()
|
||||
|
||||
return &awstasks.Subnet{Name: &name}
|
||||
}
|
||||
|
||||
func (b *KopsModelContext) LinkToPublicSubnetInZone(zoneName string) (*awstasks.Subnet, error) {
|
||||
var matches []*kops.ClusterSubnetSpec
|
||||
for i := range b.Cluster.Spec.Subnets {
|
||||
z := &b.Cluster.Spec.Subnets[i]
|
||||
if z.Zone != zoneName {
|
||||
continue
|
||||
}
|
||||
if z.Type != kops.SubnetTypePublic {
|
||||
continue
|
||||
}
|
||||
matches = append(matches, z)
|
||||
}
|
||||
if len(matches) == 0 {
|
||||
return nil, fmt.Errorf("could not find public subnet in zone: %q", zoneName)
|
||||
}
|
||||
if len(matches) > 1 {
|
||||
// TODO: Support this (arbitrary choice I think, for ELBs)
|
||||
return nil, fmt.Errorf("found multiple public subnets in zone: %q", zoneName)
|
||||
}
|
||||
|
||||
return b.LinkToSubnet(matches[0]), nil
|
||||
}
|
||||
|
||||
func (b *KopsModelContext) LinkToUtilitySubnetInZone(zoneName string) (*awstasks.Subnet, error) {
|
||||
var matches []*kops.ClusterSubnetSpec
|
||||
for i := range b.Cluster.Spec.Subnets {
|
||||
s := &b.Cluster.Spec.Subnets[i]
|
||||
if s.Zone != zoneName {
|
||||
continue
|
||||
}
|
||||
if s.Type != kops.SubnetTypeUtility {
|
||||
continue
|
||||
}
|
||||
matches = append(matches, s)
|
||||
}
|
||||
if len(matches) == 0 {
|
||||
return nil, fmt.Errorf("could not find utility subnet in zone: %q", zoneName)
|
||||
}
|
||||
if len(matches) > 1 {
|
||||
// TODO: Support this
|
||||
return nil, fmt.Errorf("found multiple utility subnets in zone: %q", zoneName)
|
||||
}
|
||||
|
||||
return b.LinkToSubnet(matches[0]), nil
|
||||
}
|
||||
|
||||
func (b *KopsModelContext) NamePrivateRouteTableInZone(zoneName string) string {
|
||||
return "private-" + zoneName + "." + b.ClusterName()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue