ec2config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: Apache-2.0 Imports: 19 Imported by: 4

Documentation

Overview

Package ec2config defines EC2 configuration.

Index

Constants

View Source
const (
	// ASGsMaxLimit is the maximum number of "Managed Node Group"s per a EKS cluster.
	ASGsMaxLimit = 10
	// ASGMaxLimit is the maximum number of nodes per a "Managed Node Group".
	ASGMaxLimit = 100
)
View Source
const EnvironmentVariablePrefix = "AWS_K8S_TESTER_EC2_"

EnvironmentVariablePrefix is the environment variable prefix used for "ec2config".

View Source
const StatusDELETEDORNOTEXIST = "DELETED/NOT-EXIST"

TODO: asg status

Variables

View Source
var DefaultConfig = Config{

	ConfigPath:                     "",
	RemoteAccessCommandsOutputPath: "",
	Name:                           "",

	Region: "us-west-2",

	LogLevel: logutil.DefaultLogLevel,

	LogOutputs: []string{"stderr"},

	OnFailureDelete:            true,
	OnFailureDeleteWaitSeconds: 120,

	RoleCreate:                 true,
	VPCCreate:                  true,
	RemoteAccessKeyCreate:      true,
	RemoteAccessPrivateKeyPath: filepath.Join(homedir.HomeDir(), ".ssh", "ec2_aws_rsa"),
	RemoteAccessUserName:       "ec2-user",
}

DefaultConfig is the default configuration.

  • empty string creates a non-nil object for pointer-type field
  • omitting an entire field returns nil value
  • make sure to check both

Functions

This section is empty.

Types

type ASG added in v0.6.9

type ASG struct {
	// Name is the ASG name.
	Name string `json:"name"`

	CFNStackID string `json:"cfn-stack-id" read-only:"true"`

	// ImageID is the Amazon Machine Image (AMI).
	// If empty, auto-populated with SSM parameter.
	ImageID string `json:"image-id"`
	// InstanceType is the instance type.
	InstanceType string `json:"instance-type"`
	// 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"`

	// MinSize is the minimum size of ASG.
	MinSize int64 `json:"min-size,omitempty"`
	// MaxSize is the maximum size of ASG.
	MaxSize int64 `json:"max-size,omitempty"`
	// DesiredCapacity is the desired capacity of ASG.
	DesiredCapacity int64 `json:"desired-capacity,omitempty"`

	// Instances is a map from instance ID to instance.
	Instances map[string]Instance `json:"instanaces" read-only:"true"`
	// Logs maps each instance ID to a list of log file paths fetched via SSH access.
	Logs map[string][]string `json:"logs" read-only:"true"`
}

ASG represents one ASG.

func (*ASG) SSHCommands added in v0.6.9

func (asg *ASG) SSHCommands(region string, keyPath string, userName string) (s string)

SSHCommands returns the SSH commands.

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 {

	// Name is the name of EC2 tester.
	Name string `json:"name"`
	// ConfigPath is the configuration file path.
	// Deployer is expected to update this file with latest status.
	ConfigPath string `json:"config-path,omitempty"`
	// Region is the AWS geographic area for EC2 deployment.
	// If empty, set default region.
	Region string `json:"region,omitempty"`

	// AWSAccountID is the account ID of the eks tester caller session.
	AWSAccountID string `json:"aws-account-id" read-only:"true"`
	// AWSUserID is the user ID of the eks tester caller session.
	AWSUserID string `json:"aws-user-id" read-only:"true"`
	// AWSIAMRoleARN is the user IAM Role ARN of the eks tester caller session.
	AWSIAMRoleARN string `json:"aws-iam-role-arn" read-only:"true"`
	// AWSCredentialPath is automatically set via AWS SDK Go.
	// And to be mounted as a volume as 'Secret' object.
	AWSCredentialPath string `json:"aws-credential-path" read-only:"true"`

	// CreateTook is the duration that took to create the resource.
	CreateTook time.Duration `json:"create-took,omitempty" read-only:"true"`
	// CreateTookString is the duration that took to create the resource.
	CreateTookString string `json:"create-took-string,omitempty" read-only:"true"`
	// DeleteTook is the duration that took to create the resource.
	DeleteTook time.Duration `json:"delete-took,omitempty" read-only:"true"`
	// DeleteTookString is the duration that took to create the resource.
	DeleteTookString string `json:"delete-took-string,omitempty" read-only:"true"`

	// 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://pkg.go.dev/go.uber.org/zap#Open and https://pkg.go.dev/go.uber.org/zap#Config for more details.
	LogOutputs []string `json:"log-outputs,omitempty"`
	// LogsDir is set to specify the target directory to store all remote log files.
	// If empty, it stores in the same directory as "ConfigPath".
	LogsDir string `json:"logs-dir,omitempty"`

	// Up is true if the cluster is up.
	Up bool `json:"up"`
	// StatusCurrent represents the current status of the cluster.
	StatusCurrent string `json:"status-current"`
	// Status represents the status of the cluster.
	Status []Status `json:"status"`

	// OnFailureDelete is true to delete all resources on creation fail.
	OnFailureDelete bool `json:"on-failure-delete"`
	// OnFailureDeleteWaitSeconds is the seconds to wait before deleting
	// all resources on creation fail.
	OnFailureDeleteWaitSeconds uint64 `json:"on-failure-delete-wait-seconds"`

	// RoleName is the name of cluster role.
	RoleName string `json:"role-name"`
	// RoleCreate is true to auto-create and delete cluster role.
	RoleCreate bool `json:"role-create"`
	// RoleARN is the role ARN that EC2 uses to create AWS resources for Kubernetes.
	// By default, it's empty which triggers tester to create one.
	RoleARN string `json:"role-arn"`
	// RoleServicePrincipals is the EC2 Role Service Principals
	RoleServicePrincipals []string `json:"role-service-principals"`
	// RoleManagedPolicyARNs is EC2 Role managed policy ARNs.
	RoleManagedPolicyARNs []string `json:"role-managed-policy-arns"`
	RoleCFNStackID        string   `json:"role-cfn-stack-id" read-only:"true"`

	// VPCCreate is true to auto-create and delete VPC.
	VPCCreate bool `json:"vpc-create"`
	// VPCID is the VPC ID for cluster creation.
	// If not empty, VPC is reused and not deleted.
	// If empty, VPC is created anew and deleted on cluster deletion.
	VPCID         string `json:"vpc-id"`
	VPCCFNStackID string `json:"vpc-cfn-stack-id" read-only:"true"`
	// SSHIngressIPv4Range is the IP range for SSH inbound traffic.
	SSHIngressIPv4Range string `json:"ssh-ingress-ipv4-range"`
	// VpcCIDR is the IP range (CIDR notation) for VPC, must be a valid private
	// (RFC 1918) CIDR range.
	VPCCIDR string `json:"vpc-cidr,omitempty"`
	// PublicSubnetCIDR1 is the CIDR Block for subnet 1 within the VPC.
	PublicSubnetCIDR1 string `json:"public-subnet-cidr-1,omitempty"`
	// PublicSubnetCIDR2 is the CIDR Block for subnet 2 within the VPC.
	PublicSubnetCIDR2 string `json:"public-subnet-cidr-2,omitempty"`
	// PublicSubnetCIDR3 is the CIDR Block for subnet 3 within the VPC.
	PublicSubnetCIDR3 string `json:"public-subnet-cidr-3,omitempty"`
	// PrivateSubnetCIDR1 is the CIDR Block for subnet 1 within the VPC.
	PrivateSubnetCIDR1 string `json:"private-subnet-cidr-1,omitempty"`
	// PrivateSubnetCIDR2 is the CIDR Block for subnet 2 within the VPC.
	PrivateSubnetCIDR2 string `json:"private-subnet-cidr-2,omitempty"`
	// PublicSubnetIDs is the list of all public subnets in the VPC.
	PublicSubnetIDs []string `json:"public-subnet-ids" read-only:"true"`
	// PrivateSubnetIDs is the list of all private subnets in the VPC.
	PrivateSubnetIDs []string `json:"private-subnet-ids" read-only:"true"`
	// SecurityGroupID is the security group ID for the VPC.
	SecurityGroupID string `json:"security-group-id" read-only:"true"`

	// RemoteAccessKeyCreate is true to create the remote SSH access private key.
	RemoteAccessKeyCreate bool `json:"remote-access-key-create"`
	// RemoteAccessKeyName is the remote SSH access private key name.
	RemoteAccessKeyName string `json:"remote-access-key-name"`
	// RemoteAccessPrivateKeyPath is the remote SSH access private key path.
	RemoteAccessPrivateKeyPath string `json:"remote-access-private-key-path"`
	// RemoteAccessUserName is the user name used for running init scripts or SSH access.
	RemoteAccessUserName string `json:"remote-access-user-name"`
	// RemoteAccessCommandsOutputPath is the output path for ssh commands.
	RemoteAccessCommandsOutputPath string `json:"remote-access-commands-output-path,omitempty"`

	// ASGs is a map from each ASG name to EC2 ASG.
	ASGs map[string]ASG `json:"asgs"`
	// contains filtered or unexported fields
}

Config defines EC2 configuration.

func Load

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

Load loads configuration from YAML. Useful when injecting shared configuration via ConfigMap.

Example usage:

import "github.com/aws/aws-k8s-tester/eksconfig"
cfg := eksconfig.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) RecordStatus added in v0.6.9

func (cfg *Config) RecordStatus(status string)

RecordStatus records cluster status.

func (*Config) SSHCommands

func (cfg *Config) SSHCommands() 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() (err error)

UpdateFromEnvs updates fields from environmental variables. Empty values are ignored and do not overwrite fields with empty values. WARNING: The environmetal variable value always overwrites current field values if there's a conflict.

func (*Config) ValidateAndSetDefaults

func (cfg *Config) ValidateAndSetDefaults() 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.

func ConvertInstance added in v0.6.9

func ConvertInstance(iv *ec2.Instance) (instance Instance)

ConvertInstance converts "aws ec2 describe-instances" to "config.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.

type Status added in v0.6.9

type Status struct {
	Time   time.Time `json:"time"`
	Status string    `json:"status"`
}

Status is the status.

Jump to

Keyboard shortcuts

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