adapter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: Apache-2.0 Imports: 27 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 AccountID

func AccountID(clients Clients) (string, error)

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.

func ValidateAccountID

func ValidateAccountID(accountID string) error

func VpcCIDR

func VpcCIDR(clients Clients, vpcID string) (string, error)

Types

type APIWhitelist

type APIWhitelist struct {
	Enabled    bool
	SubnetList string
}

APIWhitelist defines guest cluster k8s api whitelisting.

type Adapter

type Adapter struct {
	Guest    GuestAdapter
	HostPost HostPostAdapter
	HostPre  HostPreAdapter
}

func NewGuest

func NewGuest(cfg Config) (Adapter, error)

func NewHostPost

func NewHostPost(cfg Config) (Adapter, error)

func NewHostPre

func NewHostPre(cfg Config) (Adapter, error)

type BlockDeviceMapping

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

type CFClient

CFClient describes the methods required to be implemented by a CloudFormation AWS client.

type Clients

type Clients struct {
	CloudFormation CFClient
	EC2            EC2Client
	IAM            IAMClient
	KMS            KMSClient
	ELB            ELBClient
	STS            STSClient
}

type CloudFormationMock

type CloudFormationMock struct{}

func (*CloudFormationMock) WaitUntilStackCreateComplete

func (c *CloudFormationMock) WaitUntilStackCreateComplete(*awscloudformation.DescribeStacksInput) error

func (*CloudFormationMock) WaitUntilStackCreateCompleteWithContext

func (c *CloudFormationMock) WaitUntilStackCreateCompleteWithContext(ctx aws.Context, input *awscloudformation.DescribeStacksInput, opts ...request.WaiterOption) error

type Config

type Config struct {
	APIWhitelist      APIWhitelist
	CustomObject      v1alpha1.AWSConfig
	Clients           Clients
	EncrypterBackend  string
	GuestAccountID    string
	HostAccountID     string
	HostClients       Clients
	InstallationName  string
	PublicRouteTables string
	Route53Enabled    bool
	StackState        StackState
}

type EC2Client

EC2Client describes the methods required to be implemented by a EC2 AWS client.

type EC2ClientMock

type EC2ClientMock struct {
	ec2iface.EC2API
	// contains filtered or unexported fields
}

func (*EC2ClientMock) DescribeAddresses

func (e *EC2ClientMock) DescribeAddresses(input *ec2.DescribeAddressesInput) (*ec2.DescribeAddressesOutput, error)

func (*EC2ClientMock) DescribeRouteTables

func (e *EC2ClientMock) DescribeRouteTables(input *ec2.DescribeRouteTablesInput) (*ec2.DescribeRouteTablesOutput, error)

func (*EC2ClientMock) DescribeSecurityGroups

func (*EC2ClientMock) DescribeSubnets

func (e *EC2ClientMock) DescribeSubnets(input *ec2.DescribeSubnetsInput) (*ec2.DescribeSubnetsOutput, error)

func (*EC2ClientMock) DescribeVpcs

func (e *EC2ClientMock) DescribeVpcs(input *ec2.DescribeVpcsInput) (*ec2.DescribeVpcsOutput, error)

func (*EC2ClientMock) SetMatchingRouteTables

func (e *EC2ClientMock) SetMatchingRouteTables(value int)

type ELBClient

type ELBClient interface {
	DescribeLoadBalancers(*elb.DescribeLoadBalancersInput) (*elb.DescribeLoadBalancersOutput, error)
}

ELBClient describes the methods required to be implemented by a ELB AWS client.

type ELBClientMock

type ELBClientMock struct {
	elbiface.ELBAPI
	// contains filtered or unexported fields
}

func (*ELBClientMock) DescribeLoadBalancers

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
	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 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
	APIElbPortsToOpen                []GuestLoadBalancersAdapterPortPair
	APIElbScheme                     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
	IngressElbPortsToOpen            []GuestLoadBalancersAdapterPortPair
	IngressElbScheme                 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 {
	Key string
	Ref string
}

type GuestOutputsAdapterWorkerCloudConfig

type GuestOutputsAdapterWorkerCloudConfig struct {
	Version string
}

type GuestRecordSetsAdapter

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

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 {
	APIWhitelistEnabled       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 HostPostAdapter

type HostPostAdapter struct {
	RouteTables HostPostRouteTablesAdapter
	RecordSets  HostPostRecordSetsAdapter
}

type HostPostRecordSetsAdapter

type HostPostRecordSetsAdapter struct {
	BaseDomain                 string
	ClusterID                  string
	GuestHostedZoneNameServers string
	Route53Enabled             bool
}

func (*HostPostRecordSetsAdapter) Adapt

func (r *HostPostRecordSetsAdapter) Adapt(config Config) error

type HostPostRouteTablesAdapter

type HostPostRouteTablesAdapter struct {
	PrivateRoutes []HostPostRouteTablesAdapterRoute
	PublicRoutes  []HostPostRouteTablesAdapterRoute
}

func (*HostPostRouteTablesAdapter) Adapt

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

type HostPostRouteTablesAdapterRoute

type HostPostRouteTablesAdapterRoute struct {
	RouteTableName   string
	RouteTableID     string
	CidrBlock        string
	PeerConnectionID string
}

type HostPreAdapter

type HostPreAdapter struct {
	IAMRoles HostPreIAMRolesAdapter
}

type HostPreIAMRolesAdapter

type HostPreIAMRolesAdapter struct {
	PeerAccessRoleName string
	GuestAccountID     string
}

func (*HostPreIAMRolesAdapter) Adapt

func (h *HostPreIAMRolesAdapter) Adapt(cfg Config) error

type IAMClient

type IAMClient interface {
	GetUser(*iam.GetUserInput) (*iam.GetUserOutput, error)
	GetRole(*iam.GetRoleInput) (*iam.GetRoleOutput, error)
}

IAMClient describes the methods required to be implemented by a IAM AWS client.

type IAMClientMock

type IAMClientMock struct {
	iamiface.IAMAPI
	// contains filtered or unexported fields
}

func (*IAMClientMock) GetRole

func (i *IAMClientMock) GetRole(input *iam.GetRoleInput) (*iam.GetRoleOutput, error)

type KMSClient

type KMSClient interface {
	DescribeKey(*kms.DescribeKeyInput) (*kms.DescribeKeyOutput, error)
}

KMSClient describes the methods required to be implemented by a KMS AWS client.

type KMSClientMock

type KMSClientMock struct {
	kmsiface.KMSAPI
	// contains filtered or unexported fields
}

func (*KMSClientMock) DescribeKey

func (k *KMSClientMock) DescribeKey(input *kms.DescribeKeyInput) (*kms.DescribeKeyOutput, error)

type RouteTableAssociation

type RouteTableAssociation struct {
	Name           string
	RouteTableName string
	SubnetName     string
}

type RouteTableName

type RouteTableName struct {
	ResourceName        string
	TagName             string
	VPCPeeringRouteName string
}

type STSClient

type STSClient interface {
	GetCallerIdentity(*sts.GetCallerIdentityInput) (*sts.GetCallerIdentityOutput, error)
}

STSClient describes the methods required to be implemented by a STS AWS client.

type STSClientMock

type STSClientMock struct {
	stsiface.STSAPI
	// contains filtered or unexported fields
}

func (*STSClientMock) GetCallerIdentity

func (i *STSClientMock) GetCallerIdentity(input *sts.GetCallerIdentityInput) (*sts.GetCallerIdentityOutput, error)

type SmallCloudconfigConfig

type SmallCloudconfigConfig struct {
	S3URL string
}

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

type StackState

type StackState struct {
	Name string

	HostedZoneNameServers 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 int
	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
}

Jump to

Keyboard shortcuts

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