adapter

package
v5.6.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package adapter contains the required logic for creating data structures used for feeding CloudFormation templates.

It follows the adapter pattern https://en.wikipedia.org/wiki/Adapter_pattern in the sense that it has the knowledge to transform a aws custom object into a data structure easily interpolable into the templates without any additional view logic.

There's a base template in `service/templates/cloudformation/guest/main.yaml` which defines the basic structure and includes the rest of templates that form the stack as nested templates. Those subtemplates should use a `define` action with the name that will be used to refer to them from the main template, as explained here https://golang.org/pkg/text/template/#hdr-Nested_template_definitions

Each adapter is related to one of these nested templates. It includes the data structure with all the values needed to interpolate in the related template and the logic required to obtain them, this logic is packed into functions called `hydraters`.

When extending the stack we will just need to: * Add the template file in `service/template/cloudformation/guest` and modify `service/template/cloudformation/main.yaml` to include the new template. * Add the adapter logic file in `service/resource/cloudformation/adapter` with the type definition and the Hydrater function to fill the fields (like asg.go or launch_configuration.go). * Add the new type to the Adapter type in `service/resource/cloudformation/adapter/adapter.go` and include the Hydrater function in the `hydraters` slice.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEmptyAmazonAccountID

func IsEmptyAmazonAccountID(err error) bool

IsEmptyAmazonAccountID asserts emptyAmazonAccountIDError.

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

func IsMalformedAmazonAccountID

func IsMalformedAmazonAccountID(err error) bool

IsMalformedAmazonAccountID asserts malformedAmazonAccountIDError.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound asserts notFoundError

func IsTooFewResults

func IsTooFewResults(err error) bool

IsTooFewResults asserts tooFewResultsError.

func IsTooManyResults

func IsTooManyResults(err error) bool

IsTooManyResults asserts tooManyResultsError.

func IsWrongAmazonAccountIDLength

func IsWrongAmazonAccountIDLength(err error) bool

IsWrongAmazonAccountIDLength asserts wrongAmazonAccountIDLengthError.

func IsWrongType

func IsWrongType(err error) bool

IsWrongType asserts wrongTypeError.

Types

type APIWhitelist

type APIWhitelist struct {
	Private Whitelist
	Public  Whitelist
}

APIWhitelist defines guest cluster k8s public/private api whitelisting.

type Adapter

type Adapter struct {
	Guest GuestAdapter
}

func NewGuest

func NewGuest(cfg Config) (Adapter, error)

type BlockDeviceMapping

type BlockDeviceMapping struct {
	DeleteOnTermination bool
	DeviceName          string
	VolumeSize          string
	VolumeType          string
}

type Config

type Config struct {
	APIWhitelist                    APIWhitelist
	ControlPlaneAccountID           string
	ControlPlaneNATGatewayAddresses []*ec2.Address
	ControlPlanePeerRoleARN         string
	ControlPlaneVPCID               string
	ControlPlaneVPCCidr             string
	CustomObject                    v1alpha1.AWSConfig
	EncrypterBackend                string
	GuestAccountID                  string
	InstallationName                string
	PublicRouteTables               string
	Route53Enabled                  bool
	StackState                      StackState
	TenantClusterAccountID          string
	TenantClusterKMSKeyARN          string
}

type Gateway

type Gateway struct {
	ClusterID             string
	NATGWName             string
	NATEIPName            string
	NATRouteName          string
	PrivateRouteTableName string
	PublicSubnetName      string
}

type GuestAdapter

type GuestAdapter struct {
	AutoScalingGroup    GuestAutoScalingGroupAdapter
	IAMPolicies         GuestIAMPoliciesAdapter
	InternetGateway     GuestInternetGatewayAdapter
	Instance            GuestInstanceAdapter
	LaunchConfiguration GuestLaunchConfigAdapter
	LifecycleHooks      GuestLifecycleHooksAdapter
	LoadBalancers       GuestLoadBalancersAdapter
	NATGateway          GuestNATGatewayAdapter
	Outputs             GuestOutputsAdapter
	RecordSets          GuestRecordSetsAdapter
	RouteTables         GuestRouteTablesAdapter
	SecurityGroups      GuestSecurityGroupsAdapter
	Subnets             GuestSubnetsAdapter
	VPC                 GuestVPCAdapter
}

type GuestAutoScalingGroupAdapter

type GuestAutoScalingGroupAdapter struct {
	ASGDesiredCapacity     int
	ASGMaxSize             int
	ASGMinSize             int
	ASGType                string
	ClusterID              string
	HealthCheckGracePeriod int
	MaxBatchSize           string
	MinInstancesInService  string
	PrivateSubnets         []string
	RollingUpdatePauseTime string
	WorkerAZs              []string
}

func (*GuestAutoScalingGroupAdapter) Adapt

type GuestIAMPoliciesAdapter

type GuestIAMPoliciesAdapter struct {
	ClusterID         string
	EC2ServiceDomain  string
	KMSKeyARN         string
	MasterRoleName    string
	MasterPolicyName  string
	MasterProfileName string
	RegionARN         string
	S3Bucket          string
	WorkerRoleName    string
	WorkerPolicyName  string
	WorkerProfileName string
}

func (*GuestIAMPoliciesAdapter) Adapt

func (i *GuestIAMPoliciesAdapter) Adapt(cfg Config) error

type GuestInstanceAdapter

type GuestInstanceAdapter struct {
	Cluster GuestInstanceAdapterCluster
	Image   GuestInstanceAdapterImage
	Master  GuestInstanceAdapterMaster
}

func (*GuestInstanceAdapter) Adapt

func (i *GuestInstanceAdapter) Adapt(config Config) error

type GuestInstanceAdapterCluster

type GuestInstanceAdapterCluster struct {
	ID string
}

type GuestInstanceAdapterImage

type GuestInstanceAdapterImage struct {
	ID string
}

type GuestInstanceAdapterMaster

type GuestInstanceAdapterMaster struct {
	AZ               string
	CloudConfig      string
	EncrypterBackend string
	DockerVolume     GuestInstanceAdapterMasterDockerVolume
	EtcdVolume       GuestInstanceAdapterMasterEtcdVolume
	LogVolume        GuestInstanceAdapterMasterLogVolume
	Instance         GuestInstanceAdapterMasterInstance
	PrivateSubnet    string
}

type GuestInstanceAdapterMasterDockerVolume

type GuestInstanceAdapterMasterDockerVolume struct {
	Name         string
	ResourceName string
}

type GuestInstanceAdapterMasterEtcdVolume

type GuestInstanceAdapterMasterEtcdVolume struct {
	Name string
}

type GuestInstanceAdapterMasterInstance

type GuestInstanceAdapterMasterInstance struct {
	ResourceName string
	Type         string
	Monitoring   bool
}

type GuestInstanceAdapterMasterLogVolume

type GuestInstanceAdapterMasterLogVolume struct {
	Name string
}

type GuestInternetGatewayAdapter

type GuestInternetGatewayAdapter struct {
	ClusterID          string
	PrivateRouteTables []string
}

func (*GuestInternetGatewayAdapter) Adapt

type GuestLaunchConfigAdapter

type GuestLaunchConfigAdapter struct {
	ASGType                        string
	WorkerAssociatePublicIPAddress bool
	WorkerBlockDeviceMappings      []BlockDeviceMapping
	WorkerInstanceMonitoring       bool
	WorkerInstanceType             string
	WorkerImageID                  string
	WorkerSecurityGroupID          string
	WorkerSmallCloudConfig         string
}

func (*GuestLaunchConfigAdapter) Adapt

func (l *GuestLaunchConfigAdapter) Adapt(config Config) error

type GuestLifecycleHooksAdapter

type GuestLifecycleHooksAdapter struct {
	Worker GuestLifecycleHooksAdapterWorker
}

func (*GuestLifecycleHooksAdapter) Adapt

func (a *GuestLifecycleHooksAdapter) Adapt(config Config) error

type GuestLifecycleHooksAdapterASG

type GuestLifecycleHooksAdapterASG struct {
	Ref string
}

type GuestLifecycleHooksAdapterLifecycleHook

type GuestLifecycleHooksAdapterLifecycleHook struct {
	Name string
}

type GuestLifecycleHooksAdapterWorker

type GuestLifecycleHooksAdapterWorker struct {
	ASG           GuestLifecycleHooksAdapterASG
	LifecycleHook GuestLifecycleHooksAdapterLifecycleHook
}

type GuestLoadBalancersAdapter

type GuestLoadBalancersAdapter struct {
	APIElbHealthCheckTarget          string
	APIElbName                       string
	APIInternalElbName               string
	APIElbPortsToOpen                []GuestLoadBalancersAdapterPortPair
	APIElbScheme                     string
	APIInternalElbScheme             string
	APIElbSecurityGroupID            string
	EtcdElbHealthCheckTarget         string
	EtcdElbName                      string
	EtcdElbPortsToOpen               []GuestLoadBalancersAdapterPortPair
	EtcdElbScheme                    string
	EtcdElbSecurityGroupID           string
	ELBHealthCheckHealthyThreshold   int
	ELBHealthCheckInterval           int
	ELBHealthCheckTimeout            int
	ELBHealthCheckUnhealthyThreshold int
	IngressElbHealthCheckTarget      string
	IngressElbName                   string
	IngressInternalElbName           string
	IngressElbPortsToOpen            []GuestLoadBalancersAdapterPortPair
	IngressElbScheme                 string
	IngressInternalElbScheme         string
	MasterInstanceResourceName       string
	PublicSubnets                    []string
	PrivateSubnets                   []string
}

func (*GuestLoadBalancersAdapter) Adapt

func (a *GuestLoadBalancersAdapter) Adapt(cfg Config) error

type GuestLoadBalancersAdapterPortPair

type GuestLoadBalancersAdapterPortPair struct {
	// PortELB is the port the ELB should listen on.
	PortELB int
	// PortInstance is the port on the instance the ELB forwards traffic to.
	PortInstance int
}

type GuestNATGatewayAdapter

type GuestNATGatewayAdapter struct {
	Gateways []Gateway
}

func (*GuestNATGatewayAdapter) Adapt

func (a *GuestNATGatewayAdapter) Adapt(cfg Config) error

type GuestOutputsAdapter

type GuestOutputsAdapter struct {
	Master         GuestOutputsAdapterMaster
	Worker         GuestOutputsAdapterWorker
	Route53Enabled bool
	VersionBundle  GuestOutputsAdapterVersionBundle
}

func (*GuestOutputsAdapter) Adapt

func (a *GuestOutputsAdapter) Adapt(config Config) error

type GuestOutputsAdapterMaster

type GuestOutputsAdapterMaster struct {
	ImageID      string
	Instance     GuestOutputsAdapterMasterInstance
	CloudConfig  GuestOutputsAdapterMasterCloudConfig
	DockerVolume GuestOutputsAdapterMasterDockerVolume
}

type GuestOutputsAdapterMasterCloudConfig

type GuestOutputsAdapterMasterCloudConfig struct {
	Version string
}

type GuestOutputsAdapterMasterDockerVolume

type GuestOutputsAdapterMasterDockerVolume struct {
	ResourceName string
}

type GuestOutputsAdapterMasterInstance

type GuestOutputsAdapterMasterInstance struct {
	ResourceName string
	Type         string
}

type GuestOutputsAdapterVersionBundle

type GuestOutputsAdapterVersionBundle struct {
	Version string
}

type GuestOutputsAdapterWorker

type GuestOutputsAdapterWorker struct {
	ASG                GuestOutputsAdapterWorkerASG
	CloudConfig        GuestOutputsAdapterWorkerCloudConfig
	DockerVolumeSizeGB string
	ImageID            string
	InstanceType       string
}

type GuestOutputsAdapterWorkerASG

type GuestOutputsAdapterWorkerASG struct {
	Ref string
}

type GuestOutputsAdapterWorkerCloudConfig

type GuestOutputsAdapterWorkerCloudConfig struct {
	Version string
}

type GuestRecordSetsAdapter

type GuestRecordSetsAdapter struct {
	BaseDomain                 string
	EtcdDomain                 string
	ClusterID                  string
	MasterInstanceResourceName string
	Route53Enabled             bool
	VPCRegion                  string
}

func (*GuestRecordSetsAdapter) Adapt

func (a *GuestRecordSetsAdapter) Adapt(config Config) error

type GuestRouteTablesAdapter

type GuestRouteTablesAdapter struct {
	HostClusterCIDR        string
	PublicRouteTableName   RouteTableName
	PrivateRouteTableNames []RouteTableName
}

func (*GuestRouteTablesAdapter) Adapt

func (r *GuestRouteTablesAdapter) Adapt(cfg Config) error

type GuestSecurityGroupsAdapter

type GuestSecurityGroupsAdapter struct {
	APIInternalELBSecurityGroupName  string
	APIInternalELBSecurityGroupRules []securityGroupRule
	APIWhitelistEnabled              bool
	PrivateAPIWhitelistEnabled       bool
	MasterSecurityGroupName          string
	MasterSecurityGroupRules         []securityGroupRule
	WorkerSecurityGroupName          string
	WorkerSecurityGroupRules         []securityGroupRule
	IngressSecurityGroupName         string
	IngressSecurityGroupRules        []securityGroupRule
	EtcdELBSecurityGroupName         string
	EtcdELBSecurityGroupRules        []securityGroupRule
}

func (*GuestSecurityGroupsAdapter) Adapt

func (s *GuestSecurityGroupsAdapter) Adapt(cfg Config) error

type GuestSubnetsAdapter

type GuestSubnetsAdapter struct {
	PublicSubnets  []Subnet
	PrivateSubnets []Subnet
}

func (*GuestSubnetsAdapter) Adapt

func (s *GuestSubnetsAdapter) Adapt(cfg Config) error

type GuestVPCAdapter

type GuestVPCAdapter struct {
	CidrBlock        string
	ClusterID        string
	InstallationName string
	HostAccountID    string
	PeerVPCID        string
	PeerRoleArn      string
	Region           string
	RegionARN        string
	RouteTableNames  []RouteTableName
}

func (*GuestVPCAdapter) Adapt

func (v *GuestVPCAdapter) Adapt(cfg Config) error

type Hydrater

type Hydrater func(config Config) error

type RouteTableAssociation

type RouteTableAssociation struct {
	Name           string
	RouteTableName string
	SubnetName     string
}

type RouteTableName

type RouteTableName struct {
	ResourceName        string
	TagName             string
	VPCPeeringRouteName string
}

type SmallCloudconfigConfig

type SmallCloudconfigConfig struct {
	InstanceRole string
	S3URL        string
}

SmallCloudconfigConfig represents the data structure required for executing the small cloudconfig template.

type StackState

type StackState struct {
	Name string

	DockerVolumeResourceName   string
	MasterImageID              string
	MasterInstanceType         string
	MasterInstanceResourceName string
	// TODO the cloud config versions shouldn't be injected here. These should
	// actually always only be the ones the operator has hard coded. No other
	// version should be used here ever.
	MasterCloudConfigVersion string
	MasterInstanceMonitoring bool

	// TODO the cloud config versions shouldn't be injected here. These should
	// actually always only be the ones the operator has hard coded. No other
	// version should be used here ever.
	WorkerCloudConfigVersion  string
	WorkerDesired             int
	WorkerDockerVolumeSizeGB  string
	WorkerKubeletVolumeSizeGB string
	WorkerLogVolumeSizeGB     string
	WorkerImageID             string
	WorkerInstanceMonitoring  bool
	WorkerInstanceType        string
	WorkerMax                 int
	WorkerMin                 int

	VersionBundleVersion string
}

TODO we copy this because of a circular import issue with the cloudformation resource. The way how the resource works with the adapter and how infromation is passed has to be reworked at some point. Just hacking this now to keep going and to keep the changes as minimal as possible.

type Subnet

type Subnet struct {
	AvailabilityZone      string
	CIDR                  string
	Name                  string
	MapPublicIPOnLaunch   bool
	RouteTableAssociation RouteTableAssociation
}

type Whitelist

type Whitelist struct {
	Enabled    bool
	SubnetList string
}

Whitelist represents the structure required for defining whitelisting for resource security group

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL