package subnet

import "github.com/oslokommune/okctl/pkg/cfn/components/subnet"

Package subnet provides functionality for slicing and dicing subnets for use with EKS

Index

Constants

const (
	// TypePublic represents a public subnet
	TypePublic = "public"
	// TypePrivate represents a private subnet
	TypePrivate = "private"
	// TypeDatabase represents a database subnet
	TypeDatabase = "database"
)
const (
	// DefaultSubnets defines how many subnets we will be needing by default in total
	DefaultSubnets = 9
	// DefaultPrefixLen defines the size of the subnets, e.g., how many IPs they contain
	DefaultPrefixLen = 24

	// DefaultPrivateSubnetsLogicalID defines the logical id for the stack outputs
	DefaultPrivateSubnetsLogicalID = "PrivateSubnetIds"
	// DefaultPublicSubnetsLogicalID defines the logical id for the stack outputs
	DefaultPublicSubnetsLogicalID = "PublicSubnetIds"
	// DefaultDatabaseSubnetsLogicalID defines the logical id for the stack outputs
	DefaultDatabaseSubnetsLogicalID = "DatabaseSubnetIds"
)

Functions

func Types

func Types() []string

Types returns all available subnet types

Types

type CreatorFn

type CreatorFn func(network *net.IPNet) *Subnet

CreatorFn defines a function that is invoked when creating a subnet

func DefaultCreator

func DefaultCreator(vpc cfn.Referencer, cluster cfn.Namer, dist Distribution) CreatorFn

DefaultCreator provides a simplified way of creating a new subnet

func NoopCreator

func NoopCreator() CreatorFn

NoopCreator simply returns the subnet with the given CIDR

type Distribution

type Distribution interface {
	Next() (subnetType string, availabilityZone string, number int)
	DistinctSubnetTypes() int
	DistinctAzs() int
}

Distribution defines the interface required for something to be able to distribute subnets across various parameters

type Distributor

type Distributor struct {
	SubnetTypes []string
	SubnetIndex int
	Azs         []string
	AzsIndex    map[string]int
}

Distributor stores state required for creating an even distribution of subnets

func NewDistributor

func NewDistributor(subnetTypes, azs []string) (*Distributor, error)

NewDistributor returns a Distributor that can be used to delegate a set of subnets evenly across the provided types and availability zones

func (*Distributor) DistinctAzs

func (d *Distributor) DistinctAzs() int

DistinctAzs returns the number of distinct azs

func (*Distributor) DistinctSubnetTypes

func (d *Distributor) DistinctSubnetTypes() int

DistinctSubnetTypes returns the number of distinct subnet types

func (*Distributor) Next

func (d *Distributor) Next() (string, string, int)

Next returns the next entry in the distribution

type Subnet

type Subnet struct {
	// contains filtered or unexported fields
}

Subnet stores state required for creating a cloud formation subnet

func (*Subnet) Name

func (s *Subnet) Name() string

Name returns the name of the resource

func (*Subnet) Ref

func (s *Subnet) Ref() string

Ref returns a cloud formation intrinsic ref to the resource

func (*Subnet) Resource

func (s *Subnet) Resource() cloudformation.Resource

Resource returns a cloud formation resource for a subnet

type Subnets

type Subnets struct {
	Public   []*Subnet
	Private  []*Subnet
	Database []*Subnet
}

Subnets stores the state of the created subnets

func New

func New(n int, prefixLen int, block *net.IPNet, createFn CreatorFn) (*Subnets, error)

New creates n new subnets from the provided cidr block with the given network prefix size and distributes them evenly across the Subnet types and availability zones as given by the Distribution.

func NewDefault

func NewDefault(network *net.IPNet, region string, vpc cfn.Referencer, cluster cfn.Namer) (*Subnets, error)

NewDefault creates a default Subnet distribution for the given network and region

func (*Subnets) NamedOutputs

func (s *Subnets) NamedOutputs() map[string]cloudformation.Output

NamedOutputs returns the cloud formation outputs commonly required for the given subnets

Source Files

subnet.go

Version
v0.0.106 (latest)
Published
Oct 21, 2022
Platform
linux/amd64
Imports
9 packages
Last checked
5 days ago

Tools for package owners.