Skip to content

Commit

Permalink
eks*: remove CFN dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
  • Loading branch information
gyuho committed Jul 16, 2021
1 parent 7500861 commit a4a3e36
Show file tree
Hide file tree
Showing 94 changed files with 6,595 additions and 5,749 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG/CHANGELOG-1.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@

See [code changes](https://github.com/aws/aws-k8s-tester/compare/v1.6.0...v1.6.1).

### `eksconfig`

- Rename all fields [`AWS_K8S_TESTER_EKS_PARAMETERS_*` to `AWS_K8S_TESTER_EKS_`](https://github.com/aws/aws-k8s-tester/commit/TODO).
- Rename fields [`AWS_K8S_TESTER_EKS_PARAMETERS_VPC_CIDR_BLOCK*` to `AWS_K8S_TESTER_EKS_VPC_CIDRS`](https://github.com/aws/aws-k8s-tester/commit/TODO).
- Rename fields [`AWS_K8S_TESTER_EKS_PARAMETERS_PUBLIC_SUBNET_CIDR_*` to `AWS_K8S_TESTER_EKS_VPC_PUBLIC_SUBNET_CIDRS`](https://github.com/aws/aws-k8s-tester/commit/TODO).
- Rename fields [`AWS_K8S_TESTER_EKS_PARAMETERS_PRIVATE_SUBNET_CIDR_*` to `AWS_K8S_TESTER_EKS_VPC_PRIVATE_SUBNET_CIDRS`](https://github.com/aws/aws-k8s-tester/commit/TODO).
- Rename fields [`AWS_K8S_TESTER_EKS_PARAMETERS_DHCP_OPTIONS_DOMAIN_NAME*` to `AWS_K8S_TESTER_EKS_VPC_DHCP_OPTIONS_*`](https://github.com/aws/aws-k8s-tester/commit/TODO).
- Change [`ssm*` fields in `AddOnNodeGroups` as nested](https://github.com/aws/aws-k8s-tester/commit/TODO).
- before, `AWS_K8S_TESTER_EKS_ADD_ON_NODE_GROUPS_ASGS='{"GetRef.Name-ng-for-cni":{"name":"GetRef.Name-ng-for-cni","remote-access-user-name":"ec2-user","ami-type":"AL2_x86_64","asg-min-size":30,"asg-max-size":35,"asg-desired-capacity":34,"image-id":"my-ami", "ssm-document-create":true, "instance-type":"type-2", "ssm-document-cfn-stack-name":"GetRef.Name-ssm", "ssm-document-name":"GetRef.Name-document", "kubelet-extra-args":"aaa aa", "cluster-autoscaler": {"enable" : true}, "volume-size":500}}'`
- after, `AWS_K8S_TESTER_EKS_ADD_ON_NODE_GROUPS_ASGS='{"GetRef.Name-ng-for-cni":{"name":"GetRef.Name-ng-for-cni","remote-access-user-name":"ec2-user","ami-type":"AL2_x86_64","asg-min-size":30,"asg-max-size":35,"asg-desired-capacity":34, "instance-type":"type-2", "image-id":"my-ami", "ssm":{"document-create":true, "document-name":"GetRef.Name-document"}, "kubelet-extra-args":"aaa aa", "cluster-autoscaler": {"enable" : true}, "volume-size":500}}'`
- Rename [`AddOnNodeGroups.ASG.InstanceTypes` to `InstanceType`](https://github.com/aws/aws-k8s-tester/commit/TODO).
- Rename `"instance-types"` to `"instance-type"`.

### `k8s-tester`

- Add [`k8s-tester/csrs`](https://github.com/aws/aws-k8s-tester/commit/90ef22a2e6505189f998d1f6ed738fe05f73d56d).
Expand Down
2 changes: 1 addition & 1 deletion ec2/asgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ const userDataAL2InstallSSM = ` UserData:
type templateASG struct {
Metadata string
UserData string
ASGDesiredCapacity int64
ASGDesiredCapacity int32
}

func (ts *Tester) createASGs() (err error) {
Expand Down
132 changes: 66 additions & 66 deletions ec2config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"time"

"github.com/aws/aws-k8s-tester/pkg/timeutil"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
aws_v2 "github.com/aws/aws-sdk-go-v2/aws"
aws_ec2_v2_types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/mitchellh/colorstring"
"sigs.k8s.io/yaml" // must use "sigs.k8s.io/yaml"
)
Expand Down Expand Up @@ -198,7 +198,7 @@ type Config struct {
ASGs map[string]ASG `json:"asgs"`

// TotalNodes is the total number of nodes from all ASGs.
TotalNodes int64 `json:"total-nodes" read-only:"true"`
TotalNodes int32 `json:"total-nodes" read-only:"true"`
}

func (c Config) Colorize(input string) string {
Expand Down Expand Up @@ -252,31 +252,14 @@ type ASG struct {
// Name is the ASG name.
Name string `json:"name"`

ASGCFNStackID string `json:"asg-cfn-stack-id" read-only:"true"`
ASGCFNStackYAMLPath string `json:"asg-cfn-stack-yaml-path" read-only:"true"`
ASGCFNStackYAMLS3Key string `json:"asg-cfn-stack-yaml-s3-key" read-only:"true"`

TimeFrameCreate timeutil.TimeFrame `json:"time-frame-create" read-only:"true"`
TimeFrameDelete timeutil.TimeFrame `json:"time-frame-delete" read-only:"true"`

// RemoteAccessUserName is the user name used for running init scripts or SSH access.
RemoteAccessUserName string `json:"remote-access-user-name"`

// SSMDocumentCreate is true to auto-create and delete SSM document.
SSMDocumentCreate bool `json:"ssm-document-create"`
// SSMDocumentName is the name of SSM document.
SSMDocumentName string `json:"ssm-document-name"`
// SSMDocumentCFNStackName is the name of SSM document CFN stack.
SSMDocumentCFNStackName string `json:"ssm-document-cfn-stack-name"`
// SSMDocumentCommands is the commands for SSM document.
// Only used if SSM doc is created.
SSMDocumentCommands string `json:"ssm-document-commands"`
// SSMDocumentExecutionTimeoutSeconds is the SSM document execution timeout in seconds.
SSMDocumentExecutionTimeoutSeconds int `json:"ssm-document-execution-timeout-in-seconds"`
SSMDocumentCFNStackID string `json:"ssm-document-cfn-stack-id" read-only:"true"`
SSMDocumentCFNStackYAMLPath string `json:"ssm-document-cfn-stack-yaml-path" read-only:"true"`
SSMDocumentCFNStackYAMLS3Key string `json:"ssm-document-cfn-stack-yaml-s3-key" read-only:"true"`
SSMDocumentCommandIDs []string `json:"ssm-document-command-ids" read-only:"true"`
// SSM defines SSM command parameters.
SSM *SSM `json:"ssm"`

// TODO: support bootstrap arguments
// ref. https://github.com/awslabs/amazon-eks-ami/blob/master/amazon-eks-nodegroup.yaml
Expand All @@ -294,8 +277,9 @@ type ASG struct {
// parameter of the AMI ID.
ImageIDSSMParameter string `json:"image-id-ssm-parameter"`

// InstanceTypes is the list of EC2 instance types.
InstanceTypes []string `json:"instance-types"`
// InstanceType is the EC2 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
Expand All @@ -306,19 +290,35 @@ type ASG struct {
//
// 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"`
VolumeSize int32 `json:"volume-size"`

// ASGMinSize is the minimum size of ASG.
ASGMinSize int64 `json:"asg-min-size,omitempty"`
ASGMinSize int32 `json:"asg-min-size,omitempty"`
// ASGMaxSize is the maximum size of ASG.
ASGMaxSize int64 `json:"asg-max-size,omitempty"`
ASGMaxSize int32 `json:"asg-max-size,omitempty"`
// ASGDesiredCapacity is the desired capacity of ASG.
ASGDesiredCapacity int64 `json:"asg-desired-capacity,omitempty"`
ASGDesiredCapacity int32 `json:"asg-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"`

// LaunchTemplateName is the name of the launch template.
LaunchTemplateName string `json:"launch-template-name" read-only:"true"`
}

type SSM struct {
// DocumentCreate is true to auto-create and delete SSM document.
DocumentCreate bool `json:"document-create"`
// DocumentName is the name of SSM document.
DocumentName string `json:"document-name"`
// DocumentCommands is the commands for SSM document.
// Only used if SSM doc is created.
DocumentCommands string `json:"document-commands"`
// DocumentExecutionTimeoutSeconds is the SSM document execution timeout in seconds.
DocumentExecutionTimeoutSeconds int `json:"document-execution-timeout-in-seconds"`
DocumentCommandIDs []string `json:"document-command-ids" read-only:"true"`
}

// Instance represents an EC2 instance.
Expand Down Expand Up @@ -362,9 +362,9 @@ type IAMInstanceProfile struct {
// CPUOptions represents the CPU of an EC2 instance.
type CPUOptions struct {
// CoreCount is the number of CPU cores for the instance.
CoreCount int64 `json:"core-count"`
CoreCount int32 `json:"core-count"`
// ThreadsPerCore is the number of threads per CPU core.
ThreadsPerCore int64 `json:"threads-per-core"`
ThreadsPerCore int32 `json:"threads-per-core"`
}

// Placement defines EC2 placement.
Expand All @@ -375,7 +375,7 @@ type Placement struct {

// State defines an EC2 state.
type State struct {
Code int64 `json:"code"`
Code int32 `json:"code"`
Name string `json:"name"`
}

Expand Down Expand Up @@ -542,73 +542,73 @@ aws ssm --region %s start-session --target %s
}

// ConvertInstance converts "aws ec2 describe-instances" to "config.Instance".
func ConvertInstance(iv *ec2.Instance) (instance Instance) {
func ConvertInstance(iv aws_ec2_v2_types.Instance) (instance Instance) {
instance = Instance{
Architecture: aws.StringValue(iv.Architecture),
ImageID: aws.StringValue(iv.ImageId),
InstanceID: aws.StringValue(iv.InstanceId),
InstanceType: aws.StringValue(iv.InstanceType),
KeyName: aws.StringValue(iv.KeyName),
PrivateDNSName: aws.StringValue(iv.PrivateDnsName),
PrivateIP: aws.StringValue(iv.PrivateIpAddress),
PublicDNSName: aws.StringValue(iv.PublicDnsName),
PublicIP: aws.StringValue(iv.PublicIpAddress),
StateTransitionReason: aws.StringValue(iv.StateTransitionReason),
SubnetID: aws.StringValue(iv.SubnetId),
VPCID: aws.StringValue(iv.VpcId),
Architecture: fmt.Sprint(iv.Architecture),
ImageID: aws_v2.ToString(iv.ImageId),
InstanceID: aws_v2.ToString(iv.InstanceId),
InstanceType: fmt.Sprint(iv.InstanceType),
KeyName: aws_v2.ToString(iv.KeyName),
PrivateDNSName: aws_v2.ToString(iv.PrivateDnsName),
PrivateIP: aws_v2.ToString(iv.PrivateIpAddress),
PublicDNSName: aws_v2.ToString(iv.PublicDnsName),
PublicIP: aws_v2.ToString(iv.PublicIpAddress),
StateTransitionReason: aws_v2.ToString(iv.StateTransitionReason),
SubnetID: aws_v2.ToString(iv.SubnetId),
VPCID: aws_v2.ToString(iv.VpcId),
BlockDeviceMappings: make([]BlockDeviceMapping, len(iv.BlockDeviceMappings)),
EBSOptimized: aws.BoolValue(iv.EbsOptimized),
RootDeviceName: aws.StringValue(iv.RootDeviceName),
RootDeviceType: aws.StringValue(iv.RootDeviceType),
EBSOptimized: aws_v2.ToBool(iv.EbsOptimized),
RootDeviceName: aws_v2.ToString(iv.RootDeviceName),
RootDeviceType: fmt.Sprint(iv.RootDeviceType),
SecurityGroups: make([]SecurityGroup, len(iv.SecurityGroups)),
LaunchTime: aws.TimeValue(iv.LaunchTime),
Hypervisor: aws.StringValue(iv.Hypervisor),
VirtualizationType: aws.StringValue(iv.VirtualizationType),
LaunchTime: aws_v2.ToTime(iv.LaunchTime),
Hypervisor: fmt.Sprint(iv.Hypervisor),
VirtualizationType: fmt.Sprint(iv.VirtualizationType),
}
for j := range iv.BlockDeviceMappings {
instance.BlockDeviceMappings[j] = BlockDeviceMapping{
DeviceName: aws.StringValue(iv.BlockDeviceMappings[j].DeviceName),
DeviceName: aws_v2.ToString(iv.BlockDeviceMappings[j].DeviceName),
EBS: EBS{
DeleteOnTermination: aws.BoolValue(iv.BlockDeviceMappings[j].Ebs.DeleteOnTermination),
Status: aws.StringValue(iv.BlockDeviceMappings[j].Ebs.Status),
VolumeID: aws.StringValue(iv.BlockDeviceMappings[j].Ebs.VolumeId),
DeleteOnTermination: aws_v2.ToBool(iv.BlockDeviceMappings[j].Ebs.DeleteOnTermination),
Status: fmt.Sprint(iv.BlockDeviceMappings[j].Ebs.Status),
VolumeID: aws_v2.ToString(iv.BlockDeviceMappings[j].Ebs.VolumeId),
},
}
}
for j := range iv.SecurityGroups {
instance.SecurityGroups[j] = SecurityGroup{
GroupName: aws.StringValue(iv.SecurityGroups[j].GroupName),
GroupID: aws.StringValue(iv.SecurityGroups[j].GroupId),
GroupName: aws_v2.ToString(iv.SecurityGroups[j].GroupName),
GroupID: aws_v2.ToString(iv.SecurityGroups[j].GroupId),
}
}
if iv.IamInstanceProfile != nil {
instance.IAMInstanceProfile = IAMInstanceProfile{
ARN: aws.StringValue(iv.IamInstanceProfile.Arn),
ID: aws.StringValue(iv.IamInstanceProfile.Id),
ARN: aws_v2.ToString(iv.IamInstanceProfile.Arn),
ID: aws_v2.ToString(iv.IamInstanceProfile.Id),
}
}
if iv.Placement != nil {
instance.Placement = Placement{
AvailabilityZone: aws.StringValue(iv.Placement.AvailabilityZone),
Tenancy: aws.StringValue(iv.Placement.Tenancy),
AvailabilityZone: aws_v2.ToString(iv.Placement.AvailabilityZone),
Tenancy: fmt.Sprint(iv.Placement.Tenancy),
}
}
if iv.State != nil {
instance.State = State{
Code: aws.Int64Value(iv.State.Code),
Name: aws.StringValue(iv.State.Name),
Code: aws_v2.ToInt32(iv.State.Code),
Name: fmt.Sprint(iv.State.Name),
}
}
if iv.StateReason != nil {
instance.StateReason = StateReason{
Code: aws.StringValue(iv.StateReason.Code),
Message: aws.StringValue(iv.StateReason.Message),
Code: aws_v2.ToString(iv.StateReason.Code),
Message: aws_v2.ToString(iv.StateReason.Message),
}
}
if iv.CpuOptions != nil {
instance.CPUOptions = CPUOptions{
CoreCount: aws.Int64Value(iv.CpuOptions.CoreCount),
ThreadsPerCore: aws.Int64Value(iv.CpuOptions.ThreadsPerCore),
CoreCount: aws_v2.ToInt32(iv.CpuOptions.CoreCount),
ThreadsPerCore: aws_v2.ToInt32(iv.CpuOptions.ThreadsPerCore),
}
}
return instance
Expand Down
33 changes: 17 additions & 16 deletions ec2config/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestEnv(t *testing.T) {
defer os.Unsetenv("AWS_K8S_TESTER_EC2_ASGS_FETCH_LOGS")
os.Setenv("AWS_K8S_TESTER_EC2_ASGS_LOGS_DIR", "hello")
defer os.Unsetenv("AWS_K8S_TESTER_EC2_ASGS_LOGS_DIR")
os.Setenv("AWS_K8S_TESTER_EC2_ASGS", `{"test-asg":{"name":"test-asg","ssm-document-create":true,"ssm-document-cfn-stack-name":"my-doc-cfn-stack","ssm-document-name":"my-doc","ssm-document-command-id":"no","ssm-document-cfn-stack-id":"invalid","ssm-document-commands":"echo 123; echo 456;","ssm-document-execution-timeout-in-seconds":10,"remote-access-user-name":"my-user","image-id":"123","image-id-ssm-parameter":"777","asg-launch-configuration-cfn-stack-id":"none","asg-cfn-stack-id":"bbb","ami-type":"BOTTLEROCKET_x86_64","asg-min-size":30,"asg-max-size":30,"asg-desired-capacity":30,"volume-size":120,"instance-types":["c5.xlarge"]}}`)
os.Setenv("AWS_K8S_TESTER_EC2_ASGS", `{"test-asg":{"name":"test-asg","ssm-document-create":true,"ssm-document-cfn-stack-name":"my-doc-cfn-stack","ssm-document-name":"my-doc","ssm-document-command-id":"no","ssm-document-cfn-stack-id":"invalid","ssm-document-commands":"echo 123; echo 456;","ssm-document-execution-timeout-in-seconds":10,"remote-access-user-name":"my-user","image-id":"123","image-id-ssm-parameter":"777","asg-launch-configuration-cfn-stack-id":"none","asg-cfn-stack-id":"bbb","ami-type":"BOTTLEROCKET_x86_64","asg-min-size":30,"asg-max-size":30,"asg-desired-capacity":30,"volume-size":120,"instance-type":"c5.xlarge"}}`)
defer os.Unsetenv("AWS_K8S_TESTER_EC2_ASGS")

if err := cfg.UpdateFromEnvs(); err != nil {
Expand Down Expand Up @@ -111,21 +111,22 @@ func TestEnv(t *testing.T) {
}
expectedASGs := map[string]ASG{
"test-asg": {
Name: "test-asg",
RemoteAccessUserName: "my-user",
SSMDocumentCreate: true,
SSMDocumentCFNStackName: "my-doc-cfn-stack",
SSMDocumentName: "my-doc",
SSMDocumentCommands: "echo 123; echo 456;",
SSMDocumentExecutionTimeoutSeconds: 10,
AMIType: "BOTTLEROCKET_x86_64",
ImageID: "123",
ImageIDSSMParameter: "777",
ASGMinSize: 30,
ASGMaxSize: 30,
ASGDesiredCapacity: 30,
InstanceTypes: []string{"c5.xlarge"},
VolumeSize: 120,
Name: "test-asg",
RemoteAccessUserName: "my-user",
SSM: &SSM{
DocumentCreate: true,
DocumentName: "my-doc",
DocumentCommands: "echo 123; echo 456;",
DocumentExecutionTimeoutSeconds: 10,
},
AMIType: "BOTTLEROCKET_x86_64",
ImageID: "123",
ImageIDSSMParameter: "777",
ASGMinSize: 30,
ASGMaxSize: 30,
ASGDesiredCapacity: 30,
InstanceType: "c5.xlarge",
VolumeSize: 120,
},
}
if !reflect.DeepEqual(cfg.ASGs, expectedASGs) {
Expand Down
Loading

0 comments on commit a4a3e36

Please sign in to comment.