ec2config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: Apache-2.0 Imports: 13 Imported by: 4

Documentation

Overview

Package ec2config defines EC2 configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockDeviceMapping

type BlockDeviceMapping struct {
	DeviceName string `json:"device-name"`
	EBS        EBS    `json:"ebs"`
}

BlockDeviceMapping defines a block device mapping.

type Config

type Config struct {
	// EnvPrefix is used to update configuration via environmental variables.
	// The default is "AWS_K8S_TESTER_EC2_".
	EnvPrefix string `json:"env-prefix"`

	// AWSAccountID is the AWS account ID.
	AWSAccountID string `json:"aws-account-id"`
	// AWSRegion is the AWS region.
	AWSRegion string `json:"aws-region"`

	// LogLevel configures log level. Only supports debug, info, warn, error, panic, or fatal. Default 'info'.
	LogLevel string `json:"log-level"`
	// LogOutputs is a list of log outputs. Valid values are 'default', 'stderr', 'stdout', or file names.
	// Logs are appended to the existing file, if any.
	// Multiple values are accepted. If empty, it sets to 'default', which outputs to stderr.
	// See https://godoc.org/go.uber.org/zap#Open and https://godoc.org/go.uber.org/zap#Config for more details.
	LogOutputs []string `json:"log-outputs"`
	// LogOutputToUploadPath is the aws-k8s-tester log file path to upload to cloud storage.
	// Must be left empty.
	// This will be overwritten by cluster name.
	LogOutputToUploadPath       string `json:"log-output-to-upload-path"`
	LogOutputToUploadPathBucket string `json:"log-output-to-upload-path-bucket"`
	LogOutputToUploadPathURL    string `json:"log-output-to-upload-path-url"`
	// UploadTesterLogs is true to auto-upload log files.
	UploadTesterLogs bool `json:"upload-tester-logs"`

	// UploadBucketExpireDays is the number of days for objects in S3 bucket to expire.
	// Set 0 to not expire.
	UploadBucketExpireDays int `json:"upload-bucket-expire-days"`

	// Tag is the tag used for all cloudformation stacks.
	Tag string `json:"tag"`
	// Tags to add additional tags to the EC2 instances.
	Tags map[string]string `json:"tags"`
	// ClusterName is an unique ID for cluster.
	ClusterName string `json:"cluster-name"`

	// DestroyAfterCreate is true to automatically tear down EC2 instances.
	DestroyAfterCreate bool `json:"destroy-after-create"`
	// DestroyWaitTime is the duration to sleep before EC2 tear down.
	// Be ignored if "DestroyAfterCreate" is false.
	DestroyWaitTime time.Duration `json:"destroy-wait-time,omitempty"`

	// ConfigPath is the configuration file path.
	// If empty, it is autopopulated.
	// Deployer is expected to update this file with latest status,
	// and to make a backup of original configuration
	// with the filename suffix ".backup.yaml" in the same directory.
	ConfigPath       string    `json:"config-path"`
	ConfigPathBucket string    `json:"config-path-bucket"` // read-only to user
	ConfigPathURL    string    `json:"config-path-url"`    // read-only to user
	UpdatedAt        time.Time `json:"updated-at"`         // read-only to user

	// ImageID is the Amazon Machine Image (AMI).
	ImageID string `json:"image-id"`
	// UserName is the user name used for running init scripts or SSH access.
	UserName string `json:"user-name"`
	// Plugins is the list of plugins.
	Plugins []string `json:"plugins"`

	// InitScript contains init scripts (run-instance UserData field).
	// Script must be started with "#!/usr/bin/env bash" IF "Plugins" field is not defined.
	// And will be base64-encoded. Do not base64-encode. Just configure as plain-text.
	// Let this "ec2" package base64-encode.
	// Outputs are saved in "/var/log/cloud-init-output.log" in EC2 instance.
	// "tail -f /var/log/cloud-init-output.log" to check the progress.
	// Reference: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html.
	// Note that if both "Plugins" and "InitScript" are not empty,
	// "InitScript" field is always appended to the scripts generated by "Plugins" field.
	InitScript string `json:"init-script"`
	// InitScriptCreated is true once the init script has been created.
	// This is to prevent redundant init script updates from plugins.
	InitScriptCreated bool `json:"init-script-created"`

	// InstanceType is the instance type.
	InstanceType string `json:"instance-type"`
	// ClusterSize is the number of EC2 instances to create.
	ClusterSize int `json:"cluster-size"`

	// KeyName is the name of the key pair used for SSH access.
	// Leave empty to create a temporary one.
	KeyName string `json:"key-name"`
	// KeyPath is the file path to the private key.
	KeyPath       string `json:"key-path"`
	KeyPathBucket string `json:"key-path-bucket"`
	KeyPathURL    string `json:"key-path-url"`
	// KeyCreateSkip is true to indicate that EC2 key pair has been created, so needs no creation.
	KeyCreateSkip bool `json:"key-create-skip"`
	// KeyCreated is true to indicate that EC2 key pair has been created, so needs be cleaned later.
	KeyCreated bool `json:"key-created"`

	// VPCCIDR is the VPC CIDR.
	VPCCIDR string `json:"vpc-cidr"`
	// VPCID is the VPC ID to use.
	// Leave empty to create a temporary one.
	VPCID string `json:"vpc-id"`
	// VPCCreated is true to indicate that EC2 VPC has been created, so needs be cleaned later.
	// Set this to false, if the VPC is reused from somewhere else, so the original VPC creator deletes the VPC.
	VPCCreated bool `json:"vpc-created"`
	// InternetGatewayID is the internet gateway ID.
	InternetGatewayID string `json:"internet-gateway-id"`
	// RouteTableIDs is the list of route table IDs.
	RouteTableIDs []string `json:"route-table-ids"`

	// SubnetIDs is a list of subnet IDs to use.
	// If empty, it will fetch subnets from a given or created VPC.
	// And randomly assign them to instances.
	SubnetIDs                  []string          `json:"subnet-ids"`
	SubnetIDToAvailabilityZone map[string]string `json:"subnet-id-to-availability-zone"` // read-only to user

	// IngressRulesTCP is a map from TCP port range to CIDR to allow via security groups.
	IngressRulesTCP map[string]string `json:"ingress-rules-tcp"`

	// SecurityGroupIDs is the list of security group IDs.
	// Leave empty to create a temporary one.
	SecurityGroupIDs []string `json:"security-group-ids"`

	// AssociatePublicIPAddress is true to associate a public IP address.
	AssociatePublicIPAddress bool `json:"associate-public-ip-address"`

	// VolumeSize is the size of the default volume, in GiB.
	//
	// Constraints: 1-16384 for General Purpose SSD (gp2), 4-16384 for Provisioned
	// IOPS SSD (io1), 500-16384 for Throughput Optimized HDD (st1), 500-16384 for
	// Cold HDD (sc1), and 1-1024 for Magnetic (standard) volumes. If you specify
	// a snapshot, the volume size must be equal to or larger than the snapshot
	// size.
	//
	// Default: If you're creating the volume from a snapshot and don't specify
	// a volume size, the default is the snapshot size.
	VolumeSize int64 `json:"volume-size"`

	// Instances is a set of EC2 instances created from this configuration.
	Instances map[string]Instance `json:"instances"`

	// Wait is true to wait until all EC2 instances are ready.
	Wait bool `json:"wait"`

	// InstanceProfileFilePath is the JSON file path that defines the instance profile.
	InstanceProfileFilePath string `json:"instance-profile-file-path"`
	// InstanceProfileName is the name of an instance profile with permissions to manage EC2 instances.
	// NOTE THAT this always gets overwritten by 'ClusterName' and 'InstanceProfileFilePath'.
	InstanceProfileName string `json:"instance-profile-name"`
	// InstanceProfileCreated is true to indicate that instance profile has been created, so needs be cleaned later.
	InstanceProfileCreated bool `json:"instance-profile-created"`
	// InstanceProfilePolicyName is the name of instance profile.
	InstanceProfilePolicyName string `json:"instance-profile-policy-name"`
	// InstanceProfilePolicyARN is the ARN of instance profile.
	InstanceProfilePolicyARN string `json:"instance-profile-policy-arn"`
	// InstanceProfilePolicy is the instance profile policy.
	InstanceProfilePolicy string `json:"instance-profile-policy"`
	// InstanceProfilePolicyCreated is true to indicate that instance profile policy has been created, so needs be cleaned later.
	InstanceProfilePolicyCreated bool `json:"instance-profile-policy-created"`
	// InstanceProfileRoleName is the instance profile role name.
	InstanceProfileRoleName string `json:"instance-profile-role-name"`
	// InstanceProfileRoleCreated is true to indicate that instance profile role has been created, so needs be cleaned later.
	InstanceProfileRoleCreated bool `json:"instance-profile-role-created"`

	// CustomScript is executed at the end of EC2 init script.
	CustomScript string `json:"custom-script"`
}

Config defines EC2 configuration.

func Load

func Load(p string) (cfg *Config, err error)

Load loads configuration from YAML.

Example usage:

import "github.com/aws/aws-k8s-tester/internal/ec2/config"
cfg := config.Load("test.yaml")
err := cfg.ValidateAndSetDefaults()

Do not set default values in this function. "ValidateAndSetDefaults" must be called separately, to prevent overwriting previous data when loaded from disks.

func NewDefault

func NewDefault() *Config

NewDefault returns a copy of the default configuration.

func (*Config) SSHCommands

func (cfg *Config) SSHCommands() (s string)

SSHCommands returns the SSH commands.

func (*Config) Sync

func (cfg *Config) Sync() (err error)

Sync persists current configuration and states to disk.

func (*Config) UpdateFromEnvs

func (cfg *Config) UpdateFromEnvs() error

UpdateFromEnvs updates fields from environmental variables.

func (*Config) ValidateAndSetDefaults

func (cfg *Config) ValidateAndSetDefaults() (err error)

ValidateAndSetDefaults returns an error for invalid configurations. And updates empty fields with default values. At the end, it writes populated YAML to aws-k8s-tester config path.

type EBS

type EBS struct {
	DeleteOnTermination bool   `json:"delete-on-termination"`
	Status              string `json:"status"`
	VolumeID            string `json:"volume-id"`
}

EBS defines an EBS volume.

type Instance

type Instance struct {
	ImageID             string               `json:"image-id"`
	InstanceID          string               `json:"instance-id"`
	InstanceType        string               `json:"instance-type"`
	KeyName             string               `json:"key-name"`
	Placement           Placement            `json:"placement"`
	PrivateDNSName      string               `json:"private-dns-name"`
	PrivateIP           string               `json:"private-ip"`
	PublicDNSName       string               `json:"public-dns-name"`
	PublicIP            string               `json:"public-ip"`
	State               State                `json:"state"`
	SubnetID            string               `json:"subnet-id"`
	VPCID               string               `json:"vpc-id"`
	BlockDeviceMappings []BlockDeviceMapping `json:"block-device-mappings"`
	EBSOptimized        bool                 `json:"ebs-optimized"`
	RootDeviceName      string               `json:"root-device-name"`
	RootDeviceType      string               `json:"root-device-type"`
	SecurityGroups      []SecurityGroup      `json:"security-groups"`
	LaunchTime          time.Time            `json:"launch-time"`
}

Instance represents an EC2 instance.

type Placement

type Placement struct {
	AvailabilityZone string `json:"availability-zone"`
	Tenancy          string `json:"tenancy"`
}

Placement defines EC2 placement.

type SecurityGroup

type SecurityGroup struct {
	GroupName string `json:"group-name"`
	GroupID   string `json:"group-id"`
}

SecurityGroup defines a security group.

type State

type State struct {
	Code int64  `json:"code"`
	Name string `json:"name"`
}

State defines an EC2 state.

Directories

Path Synopsis
Package plugins defines various plugins to install on EC2 creation, using init scripts or EC2 user data.
Package plugins defines various plugins to install on EC2 creation, using init scripts or EC2 user data.

Jump to

Keyboard shortcuts

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